[bug-fix] Fix preset-constitution-not-installed: use PresetResolver in constitution setup
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 thatinstall_from_directoryre-seeds memory from preset when[PROJECT_NAME]is presentTestConstitutionReseedOnPresetInstall::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 constitutionsTestConstitutionReseedOnPresetInstall::test_install_skips_reseed_when_no_constitution_template— pins no-op when preset has noconstitution-templateentryTestConstitutionReseedOnPresetInstall::test_install_skips_reseed_when_memory_absent— pins thatinstall_from_directorydoes not create the memory fileTestEnsureConstitutionFromTemplate::test_uses_preset_constitution_when_available— pins that the function picks the preset's template over the generic coreTestEnsureConstitutionFromTemplate::test_falls_back_to_core_template_without_preset— pins fallback to core template when no preset is installedTestEnsureConstitutionFromTemplate::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
PresetResolvercontract and the existingTestSelfTestPresetfixture patterns. - The logic mirrors the existing
_register_commands/PresetResolver.resolvecall patterns already exercised by the test suite.
Deviations from Assessment
None. The implementation follows the preferred three-part fix exactly:
ensure_constitution_from_templateusesPresetResolver.- Init flow reordered so constitution seeding runs after preset installation.
- 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.constitutionpreset-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_templateafter preset installation is a no-op for projects without--preset(the common case). _maybe_reseed_constitutionis best-effort: anOSErroron the finalshutil.copy2is 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 · ◷