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 <223556219+Copilot@users.noreply.github.com>

* 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 <223556219+Copilot@users.noreply.github.com>

* 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 <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manfred Riem
2026-06-22 11:33:44 -05:00
committed by GitHub
parent 5012ba4613
commit 79a34b892d
2 changed files with 30 additions and 4 deletions

View File

@@ -1033,6 +1033,32 @@ class TestPresetResolver:
result = resolver.resolve("hidden-template")
assert result is None
def test_collect_all_layers_finds_bundled_core_without_specify_commands(
self, project_dir
):
"""Tier-5 fallback locates the bundled core command when
.specify/templates/commands/ has no matching file.
Regression test for #3086: a stale ``.parent`` chain made the
source-checkout fallback resolve to ``src/templates/...`` (which does
not exist), so ``wrap`` presets found no base layer. The fallback must
resolve against the real repo-root ``templates/commands`` tree.
"""
# project_dir's commands dir is empty, so tier-4 cannot satisfy this.
resolver = PresetResolver(project_dir)
layers = resolver.collect_all_layers("speckit.implement", "command")
assert layers, "expected a bundled core base layer to be found"
assert layers[-1]["source"] == "core (bundled)"
assert layers[-1]["path"].parts[-2:] == ("commands", "implement.md")
def test_resolve_command_falls_back_to_bundled_core(self, project_dir):
"""resolve() tier-5 returns the bundled core command when
.specify/templates/commands/ lacks it (regression for #3086)."""
resolver = PresetResolver(project_dir)
result = resolver.resolve("speckit.implement", "command")
assert result is not None
assert result.parts[-2:] == ("commands", "implement.md")
class TestResolveCore:
"""Test PresetResolver.resolve_core() skips the installed-presets tier."""