spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

[bug-fix] preset-constitution-not-installed: resolver-aware seeding + post-install reseed

Open github-actions[bot] opened this issue 5 months ago โ€ข 0 comments

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 โ€” verifies ensure_constitution_from_template picks up the preset's constitution-template via PresetResolver
  • TestConstitutionReseed::test_ensure_constitution_falls_back_to_core_without_preset โ€” verifies fallback to core template when no preset overrides it
  • TestConstitutionReseed::test_ensure_constitution_skips_existing_file โ€” verifies existing memory files are never overwritten
  • TestConstitutionReseed::test_install_from_directory_reseeds_generic_constitution โ€” verifies install_from_directory re-seeds a generic (placeholder-containing) memory constitution from the preset
  • TestConstitutionReseed::test_install_from_directory_does_not_overwrite_authored_constitution โ€” verifies authored constitutions (no placeholder tokens) are left untouched
  • TestConstitutionReseed::test_install_from_directory_skips_reseed_without_constitution_template โ€” verifies presets that don't provide constitution-template don't touch the memory file
  • TestConstitutionReseed::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/venv installed 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:

  1. PresetResolver used in ensure_constitution_from_template โœ…
  2. Init flow reordered (call moved after preset block) โœ…
  3. Guarded re-seed hook in install_from_directory via _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_template after the preset block does not affect init runs without a --preset argument (no-op change for the common case).
  • PresetResolver is now imported lazily inside ensure_constitution_from_template with a try/except Exception guard, 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 ยท โ—ท

github-actions[bot] avatar Jul 01 '26 18:07 github-actions[bot]