test: cover preset constitution seeding through init CLI#3297
Merged
BenBtg merged 5 commits intoJul 15, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
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
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
previously approved these changes
Jul 15, 2026
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
Contributor
There was a problem hiding this comment.
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-levelensure_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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.mdis 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:
Scope
This PR contains no production-code changes relative to
main. Issue #3272 was resolved by #3276.Verification
Authored by GitHub Copilot (model: GPT-5.6 Sol) acting autonomously on behalf of @BenBtg.