Skip to content

test: cover preset constitution seeding through init CLI#3297

Merged
BenBtg merged 5 commits into
mainfrom
fix/3272-preset-constitution-not-installed-e6ce3ab03838f7ba
Jul 15, 2026
Merged

test: cover preset constitution seeding through init CLI#3297
BenBtg merged 5 commits into
mainfrom
fix/3272-preset-constitution-not-installed-e6ce3ab03838f7ba

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds CLI-level regression coverage for the constitution preset behavior implemented by #3276.

The test runs specify init --preset <local-path> and verifies that .specify/memory/constitution.md is seeded from a preset whose manifest declares a non-conventional template path.

This complements the existing resolver-level tests by covering the complete init flow, including:

  • preset installation occurring before constitution materialization;
  • local preset path handling;
  • manifest-declared constitution template paths; and
  • the final memory constitution content.

Scope

This PR contains no production-code changes relative to main. Issue #3272 was resolved by #3276.

Verification

  • Targeted CLI and constitution resolver tests pass.
  • Ruff checks pass.

Authored by GitHub Copilot (model: GPT-5.6 Sol) acting autonomously on behalf of @BenBtg.

…tion setup

Apply the remediation from the bug assessment on issue #3272.

Changes:
1. Modify ensure_constitution_from_template (init.py) to resolve the
   constitution-template through the preset priority stack via
   PresetResolver, instead of hardcoding the core template path. This
   ensures a preset's replacement constitution-template is used when
   seeding .specify/memory/constitution.md.

2. Reorder init flow: move ensure_constitution_from_template to after
   the preset installation block so that 'specify init --preset' seeds
   the memory file from the already-resolved template stack, not from
   the generic template that existed before the preset arrived.

3. Add _maybe_reseed_constitution to PresetManager (presets/__init__.py):
   a post-install hook that re-seeds .specify/memory/constitution.md
   from the preset's constitution-template during 'specify preset add'
   on an existing project, but only when the memory file still contains
   generic placeholder tokens ([PROJECT_NAME] or [PRINCIPLE_1_NAME]).
   Legitimately authored constitutions (no placeholder tokens) are never
   overwritten.

4. Add regression tests covering both code paths (TestConstitutionReseedOnPresetInstall
   and TestEnsureConstitutionFromTemplate in tests/test_presets.py).

Refs #3272

Assisted-by: GitHub Copilot (model: claude-sonnet-4.6, autonomous)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automated bug-fix Trigger the bug-fix agentic workflow labels Jul 1, 2026
@BenBtg BenBtg self-assigned this Jul 6, 2026
@BenBtg BenBtg requested a review from Copilot July 13, 2026 15:07
@BenBtg BenBtg marked this pull request as ready for review July 13, 2026 15:10
@BenBtg BenBtg requested a review from mnriem as a code owner July 13, 2026 15:10
@BenBtg BenBtg marked this pull request as draft July 13, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes preset-aware constitution seeding during initialization and preset installation.

Changes:

  • Resolves constitution templates through PresetResolver.
  • Reorders initialization and adds guarded post-install reseeding.
  • Adds constitution seeding and preservation tests.
Show a summary per file
File Description
src/specify_cli/commands/init.py Adds preset-aware constitution resolution and reorders seeding.
src/specify_cli/presets/__init__.py Adds post-install constitution reseeding.
tests/test_presets.py Tests constitution resolution and overwrite guards.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 5
  • Review effort level: Medium

Comment thread src/specify_cli/commands/init.py Outdated
Comment thread src/specify_cli/presets/__init__.py Outdated
Comment thread src/specify_cli/presets/__init__.py Outdated
Comment thread src/specify_cli/presets/__init__.py Outdated
Comment thread src/specify_cli/commands/init.py
Use manifest-aware composed content, atomic safe writes, and conservative generic-template matching for constitution seeding and re-seeding.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49891a32-bec4-462c-a7f2-6d6ec4eefcdb
@BenBtg

BenBtg commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Consolidated the duplicate implementation from #3298 into this branch and hardened the resolution path in commit e601a6e. The final implementation uses manifest-aware composed content, exact generic-template matching, pre-read symlink validation, atomic writes, warned best-effort failure handling, and CLI-level regression coverage.\n\nPosted on behalf of @BenBtg by GitHub Copilot (model: GPT-5.6 Sol).

Resolve constitution implementation conflicts in favor of the provenance-based fix now on main while retaining CLI-level regression coverage for manifest-declared preset paths.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49891a32-bec4-462c-a7f2-6d6ec4eefcdb
@BenBtg BenBtg requested a review from Copilot July 15, 2026 15:21
@BenBtg BenBtg added bug-test and removed bug-fix Trigger the bug-fix agentic workflow labels Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

BenBtg
BenBtg previously approved these changes Jul 15, 2026
@BenBtg BenBtg changed the title [bug-fix] Fix preset-constitution-not-installed: use PresetResolver in constitution setup test: cover preset constitution seeding through init CLI Jul 15, 2026
@BenBtg BenBtg requested a review from Copilot July 15, 2026 16:20
@BenBtg BenBtg marked this pull request as ready for review July 15, 2026 16:21
@BenBtg BenBtg self-requested a review July 15, 2026 16:21
Remove accidental whole-file Ruff formatting introduced during conflict resolution so the PR contains only the intended end-to-end test.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49891a32-bec4-462c-a7f2-6d6ec4eefcdb

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

Comments suppressed due to low confidence (1)

tests/integrations/test_cli.py:313

  • PresetManager.install_from_directory() already calls _seed_constitution_from_preset() (src/specify_cli/presets/__init__.py:1742-1749), so this test's constitution is created during installation; the later init-level ensure_constitution_from_template() only preserves the existing file. Consequently, moving or removing the post-install materialization still passes, so the ordering claimed by this regression test is not covered. Disable the lifecycle seeding hook here (or instrument the init helper) so the final assertion depends on init materializing after the preset is registered.
        """Pre-existing shared files are not overwritten without --force."""
        from specify_cli import _install_shared_infra

        project = tmp_path / "skip-test"
        project.mkdir()
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

Disable preset-install lifecycle seeding in the regression test so it fails unless init materializes the constitution after registering the preset.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49891a32-bec4-462c-a7f2-6d6ec4eefcdb

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@BenBtg BenBtg merged commit f065e27 into main Jul 15, 2026
14 checks passed
@mnriem mnriem deleted the fix/3272-preset-constitution-not-installed-e6ce3ab03838f7ba branch July 15, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants