[bug-fix] preset-constitution-not-installed: resolver-aware seeding + post-install reseed
Bug fix โ preset-constitution-not-installed
Proposed fix for issue #3272, applying the remediation from the bug assessment.
Verdict: valid ยท Severity: high
Summary
ensure_constitution_from_template previously hardcoded a copy from the core template, bypassing PresetResolver entirely and always seeding .specify/memory/constitution.md with the generic upstream placeholder. This change makes constitution seeding preset-aware in two places (init flow and preset add), so a preset that provides a ratified constitution-template automatically lands in the project's memory file.
Changes
| File | Change | Notes |
|---|---|---|
src/specify_cli/commands/init.py |
modified | ensure_constitution_from_template now resolves via PresetResolver; call moved after preset installation block |
src/specify_cli/presets/__init__.py |
modified | Added _CONSTITUTION_PLACEHOLDER_TOKENS constant and _maybe_reseed_constitution method; called at end of install_from_directory |
tests/test_presets.py |
added tests | 7 regression tests in new TestConstitutionReseed class |
Tests Added or Updated
TestConstitutionReseed::test_ensure_constitution_uses_resolver_when_preset_installedโ verifiesensure_constitution_from_templatepicks up the preset's constitution-template viaPresetResolverTestConstitutionReseed::test_ensure_constitution_falls_back_to_core_without_presetโ verifies fallback to core template when no preset overrides itTestConstitutionReseed::test_ensure_constitution_skips_existing_fileโ verifies existing memory files are never overwrittenTestConstitutionReseed::test_install_from_directory_reseeds_generic_constitutionโ verifiesinstall_from_directoryre-seeds a generic (placeholder-containing) memory constitution from the presetTestConstitutionReseed::test_install_from_directory_does_not_overwrite_authored_constitutionโ verifies authored constitutions (no placeholder tokens) are left untouchedTestConstitutionReseed::test_install_from_directory_skips_reseed_without_constitution_templateโ verifies presets that don't provideconstitution-templatedon't touch the memory fileTestConstitutionReseed::test_self_test_preset_reseeds_generic_constitution_on_installโ end-to-end test using the self-test preset
Local Verification
- Syntax check:
python3 -c "import ast; ast.parse(open(f).read())"on all three files โ OK - No test runner available in the CI environment (no
uv/venvinstalled at workflow time); verified by code inspection and AST parsing.
Deviations from Assessment
None. The implementation follows all three parts of the preferred remediation exactly:
PresetResolverused inensure_constitution_from_templateโ- Init flow reordered (call moved after preset block) โ
- Guarded re-seed hook in
install_from_directoryvia_maybe_reseed_constitutionโ
The guard condition uses both [PROJECT_NAME] and [PRINCIPLE_1_NAME] as placeholder tokens, as recommended in the assessment's Risks & Considerations.
Risks & Review Notes
- The re-seed guard (placeholder token check) may produce false negatives for authored constitutions that happen to retain
[PROJECT_NAME]or[PRINCIPLE_1_NAME]as literal text. The conservative dual-token check (any(token in content for token in ...)) reduces but cannot eliminate this risk โ a single stray[PROJECT_NAME]in an otherwise complete constitution would still trigger a re-seed. - Moving
ensure_constitution_from_templateafter the preset block does not affect init runs without a--presetargument (no-op change for the common case). PresetResolveris now imported lazily insideensure_constitution_from_templatewith atry/except Exceptionguard, keeping the fallback to direct core-path lookup for environments where the preset system is unavailable.
Refs #3272 ยท cc @PechiSW
- Fixes #3272
Generated by ๐ ๏ธ Fix Bug from Labeled Issue for issue #3272 ยท 3.2K AIC ยท โ 29.5 AIC ยท โ 35.6K ยท โท