Skip to content

Commit 79a34b8

Browse files
mnriemCopilot
andauthored
fix(presets): use _repo_root() for bundled-core source-checkout fallback (#3086) (#3091)
* fix(presets): use _repo_root() for bundled-core source-checkout fallback The tier-5 fallback in PresetResolver.resolve() and _find_bundled_core() computed the repo root as Path(__file__).parent.parent.parent. After presets.py was moved to presets/__init__.py (#2826) that chain is one level short, resolving to src/ and looking for src/templates/commands/<cmd>.md, which never exists. As a result, wrap-strategy presets found no core base layer in source/editable installs. Use the shared _repo_root() helper so both fallbacks resolve against the actual repo-root templates/ tree. Wheel installs were unaffected (core_pack path), so this only impacts source/editable checkouts. Refs #3086 Co-authored-by: Copilot <[email protected]> * test(presets): restore dropped def for oserror-manifest test A prior edit accidentally removed the def test_resolve_extension_command_via_manifest_skips_oserror_manifests line, orphaning its body inside the new bundled-core test. Restore the test definition so pytest collects it again. Co-authored-by: Copilot <[email protected]> * test(presets): move bundled-core tests into TestPresetResolver The two tier-5 fallback regression tests exercise collect_all_layers() and resolve(), not resolve_core(), so they belong in TestPresetResolver rather than TestResolveCore. Relocate them for clearer suite navigation. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 5012ba4 commit 79a34b8

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎src/specify_cli/presets/__init__.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ def resolve(
27072707
# (source-checkout / editable install). This is the canonical home for
27082708
# speckit's built-in command/template files and must always be checked
27092709
# so that strategy:wrap presets can locate {CORE_TEMPLATE}.
2710-
from specify_cli import _locate_core_pack # local import to avoid cycles
2710+
from specify_cli import _locate_core_pack, _repo_root # local import to avoid cycles
27112711
_core_pack = _locate_core_pack()
27122712
if _core_pack is not None:
27132713
# Wheel install path
@@ -2727,7 +2727,7 @@ def resolve(
27272727
return candidate
27282728
else:
27292729
# Source-checkout / editable install: templates live at repo root
2730-
repo_root = Path(__file__).parent.parent.parent
2730+
repo_root = _repo_root()
27312731
if template_type == "template":
27322732
candidate = repo_root / "templates" / f"{template_name}.md"
27332733
elif template_type == "command":
@@ -3079,7 +3079,7 @@ def _find_bundled_core(
30793079
``.specify/templates/`` doesn't contain the core file.
30803080
"""
30813081
try:
3082-
from specify_cli import _locate_core_pack
3082+
from specify_cli import _locate_core_pack, _repo_root
30833083
except ImportError:
30843084
return None
30853085

@@ -3102,7 +3102,7 @@ def _find_bundled_core(
31023102
if c.exists():
31033103
return c
31043104
else:
3105-
repo_root = Path(__file__).parent.parent.parent
3105+
repo_root = _repo_root()
31063106
for name in names:
31073107
if template_type == "template":
31083108
c = repo_root / "templates" / f"{name}.md"

‎tests/test_presets.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,32 @@ def test_resolve_skips_hidden_extension_dirs(self, project_dir):
10331033
result = resolver.resolve("hidden-template")
10341034
assert result is None
10351035

1036+
def test_collect_all_layers_finds_bundled_core_without_specify_commands(
1037+
self, project_dir
1038+
):
1039+
"""Tier-5 fallback locates the bundled core command when
1040+
.specify/templates/commands/ has no matching file.
1041+
1042+
Regression test for #3086: a stale ``.parent`` chain made the
1043+
source-checkout fallback resolve to ``src/templates/...`` (which does
1044+
not exist), so ``wrap`` presets found no base layer. The fallback must
1045+
resolve against the real repo-root ``templates/commands`` tree.
1046+
"""
1047+
# project_dir's commands dir is empty, so tier-4 cannot satisfy this.
1048+
resolver = PresetResolver(project_dir)
1049+
layers = resolver.collect_all_layers("speckit.implement", "command")
1050+
assert layers, "expected a bundled core base layer to be found"
1051+
assert layers[-1]["source"] == "core (bundled)"
1052+
assert layers[-1]["path"].parts[-2:] == ("commands", "implement.md")
1053+
1054+
def test_resolve_command_falls_back_to_bundled_core(self, project_dir):
1055+
"""resolve() tier-5 returns the bundled core command when
1056+
.specify/templates/commands/ lacks it (regression for #3086)."""
1057+
resolver = PresetResolver(project_dir)
1058+
result = resolver.resolve("speckit.implement", "command")
1059+
assert result is not None
1060+
assert result.parts[-2:] == ("commands", "implement.md")
1061+
10361062

10371063
class TestResolveCore:
10381064
"""Test PresetResolver.resolve_core() skips the installed-presets tier."""

0 commit comments

Comments
 (0)