Skip to content

Commit d912227

Browse files
committed
fix: align resolve() with manifest file paths and match extension context_note
- Update resolve() preset tier to consult manifest file paths before convention-based lookup, matching collect_all_layers behavior - Use exact extension context_note format matching extensions.CommandRegistrar - Update test to declare template in manifest (authoritative manifest)
1 parent f6a7cd8 commit d912227

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

src/specify_cli/presets.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,10 @@ def _reconcile_composed_commands(self, command_names: List[str]) -> None:
747747
if c.get("name") == cmd_name
748748
]
749749
if matching_cmds:
750-
ext_name = ext_manifest.data.get("extension", {}).get("name", ext_id)
751750
registrar.register_commands_for_non_skill_agents(
752751
matching_cmds, ext_id, ext_dir,
753752
self.project_root,
754-
context_note=f"Extension: {ext_name} ({ext_id})",
753+
context_note=f"\n<!-- Extension: {ext_id} -->\n<!-- Config: .specify/extensions/{ext_id}/ -->\n",
755754
)
756755
registered = True
757756
except Exception:
@@ -2432,13 +2431,27 @@ def resolve(
24322431
registry = PresetRegistry(self.presets_dir)
24332432
for pack_id, _metadata in registry.list_by_priority():
24342433
pack_dir = self.presets_dir / pack_id
2435-
for subdir in subdirs:
2436-
if subdir:
2437-
candidate = pack_dir / subdir / f"{template_name}{ext}"
2438-
else:
2439-
candidate = pack_dir / f"{template_name}{ext}"
2440-
if candidate.exists():
2441-
return candidate
2434+
# Check manifest file path first
2435+
manifest = self._get_manifest(pack_dir)
2436+
if manifest:
2437+
for tmpl in manifest.templates:
2438+
if (tmpl.get("name") == template_name
2439+
and tmpl.get("type") == template_type):
2440+
file_path = tmpl.get("file")
2441+
if file_path:
2442+
candidate = pack_dir / file_path
2443+
if candidate.exists():
2444+
return candidate
2445+
break
2446+
# Convention-based fallback (only when manifest doesn't list this template)
2447+
else:
2448+
for subdir in subdirs:
2449+
if subdir:
2450+
candidate = pack_dir / subdir / f"{template_name}{ext}"
2451+
else:
2452+
candidate = pack_dir / f"{template_name}{ext}"
2453+
if candidate.exists():
2454+
return candidate
24422455

24432456
# Priority 3: Extension-provided templates (sorted by priority — lower number wins)
24442457
for _priority, ext_id, _metadata in self._get_all_extensions_by_priority():

tests/test_presets.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,17 +2886,28 @@ def test_enable_not_installed(self, project_dir):
28862886
assert result.exit_code == 1, result.output
28872887
assert "not installed" in result.output.lower()
28882888

2889-
def test_disabled_preset_excluded_from_resolution(self, project_dir, pack_dir):
2889+
def test_disabled_preset_excluded_from_resolution(self, project_dir, temp_dir, valid_pack_data):
28902890
"""Test that disabled presets are excluded from template resolution."""
2891-
# Install preset with a template
2891+
# Install preset with a template declared in the manifest
2892+
pack_data = {**valid_pack_data}
2893+
pack_data["preset"] = {**valid_pack_data["preset"], "id": "test-pack", "name": "Test"}
2894+
pack_data["provides"] = {
2895+
"templates": [{
2896+
"type": "template",
2897+
"name": "test-template",
2898+
"file": "templates/test-template.md",
2899+
}]
2900+
}
2901+
pack_dir = temp_dir / "test-pack"
2902+
pack_dir.mkdir(exist_ok=True)
2903+
with open(pack_dir / "preset.yml", "w") as f:
2904+
yaml.dump(pack_data, f)
2905+
(pack_dir / "templates").mkdir(exist_ok=True)
2906+
(pack_dir / "templates" / "test-template.md").write_text("# Template from test-pack")
2907+
28922908
manager = PresetManager(project_dir)
28932909
manager.install_from_directory(pack_dir, "0.1.5")
28942910

2895-
# Create a template in the preset directory
2896-
preset_template = project_dir / ".specify" / "presets" / "test-pack" / "templates" / "test-template.md"
2897-
preset_template.parent.mkdir(parents=True, exist_ok=True)
2898-
preset_template.write_text("# Template from test-pack")
2899-
29002911
resolver = PresetResolver(project_dir)
29012912

29022913
# Template should be found when enabled

0 commit comments

Comments
 (0)