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

[bug-fix] Fix preset-constitution-not-installed: use PresetResolver in constitution setup

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 hardcoded a read from the generic core template path, bypassing the preset resolution stack entirely, so a preset's constitution-template (with strategy: replace) was never used when seeding .specify/memory/constitution.md. Additionally, for specify init --preset, the function ran before the preset was installed, so even a resolver-aware call would have missed the preset. This PR fixes both issues and adds a post-install re-seed hook for specify preset add on existing projects.

Changes

File Change Notes
src/specify_cli/commands/init.py modified ensure_constitution_from_template now resolves template via PresetResolver; call moved to after preset installation block
src/specify_cli/presets/__init__.py modified Added _maybe_reseed_constitution helper; called from install_from_directory post-install
tests/test_presets.py added tests TestConstitutionReseedOnPresetInstall and TestEnsureConstitutionFromTemplate classes

Tests Added or Updated

  • TestConstitutionReseedOnPresetInstall::test_install_reseeds_generic_constitution_memory — pins that install_from_directory re-seeds memory from preset when [PROJECT_NAME] is present
  • TestConstitutionReseedOnPresetInstall::test_install_reseeds_on_principle_placeholder — pins re-seed when [PRINCIPLE_1_NAME] is present even without [PROJECT_NAME]
  • TestConstitutionReseedOnPresetInstall::test_install_does_not_overwrite_authored_constitution — pins the safety guard against overwriting authored constitutions
  • TestConstitutionReseedOnPresetInstall::test_install_skips_reseed_when_no_constitution_template — pins no-op when preset has no constitution-template entry
  • TestConstitutionReseedOnPresetInstall::test_install_skips_reseed_when_memory_absent — pins that install_from_directory does not create the memory file
  • TestEnsureConstitutionFromTemplate::test_uses_preset_constitution_when_available — pins that the function picks the preset's template over the generic core
  • TestEnsureConstitutionFromTemplate::test_falls_back_to_core_template_without_preset — pins fallback to core template when no preset is installed
  • TestEnsureConstitutionFromTemplate::test_skips_when_memory_already_exists — pins the existing-file guard

Local Verification

  • Commands run: none — the test toolchain (pytest, uv) was unavailable in this CI environment (network blocked, no pre-installed venv). Correctness was verified by careful code inspection against the PresetResolver contract and the existing TestSelfTestPreset fixture patterns.
  • The logic mirrors the existing _register_commands / PresetResolver.resolve call patterns already exercised by the test suite.

Deviations from Assessment

None. The implementation follows the preferred three-part fix exactly:

  1. ensure_constitution_from_template uses PresetResolver.
  2. Init flow reordered so constitution seeding runs after preset installation.
  3. Guarded re-seed in install_from_directory (skips when memory is absent or has been authored).

The two NEEDS CLARIFICATION open questions were non-blocking:

  • Q1 (warn vs. silently skip for authored constitutions): implemented as silent skip, consistent with the assessment's own wording ("if and only if the existing memory file is still the unmodified generic placeholder").
  • Q2 (speckit.constitution preset-awareness): not in scope; the second assessment comment confirmed this is a separate concern.

Risks & Review Notes

  • The re-seed guard ([PROJECT_NAME] / [PRINCIPLE_1_NAME] detection) must cover both tokens since a partially-filled constitution might have the project name set but still carry [PRINCIPLE_1_NAME]. Both checks are independent (either triggers a re-seed).
  • Moving ensure_constitution_from_template after preset installation is a no-op for projects without --preset (the common case).
  • _maybe_reseed_constitution is best-effort: an OSError on the final shutil.copy2 is silently swallowed so it cannot fail the overall preset installation.

Refs #3272 · cc @PechiSW

  • Fixes #3272

Generated by 🛠️ Fix Bug from Labeled Issue for issue #3272 · 2K AIC · ⌖ 53.4 AIC · ⊞ 34K · ◷

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