Skip to content

Commit 403fcdc

Browse files
matecardosoclaude
andauthored
fix(agent-context): discover nested plans in Python port mtime fallback (#3734)
The Python port of update-agent-context reintroduced a one-level plan scan (specs/*/plan.md) in its mtime fallback, while the Bash and PowerShell ports search recursively (specs/**/plan.md) per the fix for issue #3024. The three ports were therefore not in parity: for nested scoped layouts such as specs/<scope>/<feature>/plan.md, the Python port found no plan and omitted the plan link from the managed context section. Switch the fallback to `(root / "specs").rglob("plan.md")` and update the module docstring to match the documented recursive-discovery contract. Add a parity regression test covering the nested layout (it fails on the one-level glob and passes with the recursive scan). Co-authored-by: Claude Opus 4.8 <[email protected]>
1 parent 2fb94e0 commit 403fcdc

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎extensions/agent-context/scripts/python/update_agent_context.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
1212
When ``plan_path`` is omitted, the script derives it from
1313
``.specify/feature.json`` (written by /speckit-specify). Falls back to the most
14-
recently modified ``specs/*/plan.md`` only when feature.json is absent or its
15-
plan does not exist yet.
14+
recently modified ``plan.md`` anywhere under ``specs/`` (including nested scoped
15+
layouts such as ``specs/<scope>/<feature>/plan.md``) only when feature.json is
16+
absent or its plan does not exist yet.
1617
"""
1718

1819
from __future__ import annotations
@@ -173,7 +174,7 @@ def _resolve_plan_path(project_root: str) -> str:
173174
if not plan_path:
174175
root = Path(project_root).resolve()
175176
plans = sorted(
176-
(root / "specs").glob("*/plan.md"),
177+
(root / "specs").rglob("plan.md"),
177178
key=lambda p: p.stat().st_mtime,
178179
reverse=True,
179180
)

‎tests/extensions/test_update_agent_context_python_parity.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ def test_python_mtime_fallback_matching_bash(tmp_path: Path) -> None:
317317
assert b"at specs/001-new/plan.md" in content
318318

319319

320+
@requires_posix_bash
321+
def test_python_mtime_fallback_finds_nested_plan_matching_bash(tmp_path: Path) -> None:
322+
# Regression: the mtime fallback must discover plan.md in nested scoped
323+
# layouts (specs/<scope>/<feature>/plan.md), matching the Bash/PowerShell
324+
# ports and the documented recursive-discovery contract (see #3024). A
325+
# one-level scan (specs/*/plan.md) would miss this and omit the plan link.
326+
repo_a, repo_b = twin_projects(tmp_path, context_file="AGENTS.md")
327+
for repo in (repo_a, repo_b):
328+
plan = repo / "specs" / "scope-a" / "002-nested" / "plan.md"
329+
plan.parent.mkdir(parents=True, exist_ok=True)
330+
plan.write_text("# plan\n", encoding="utf-8")
331+
332+
bash = run_bash(repo_a)
333+
py = run_python(repo_b)
334+
335+
assert_parity(bash, py, repo_a, repo_b)
336+
content = (repo_b / "AGENTS.md").read_bytes()
337+
assert content == (repo_a / "AGENTS.md").read_bytes()
338+
assert b"at specs/scope-a/002-nested/plan.md" in content
339+
340+
320341
@requires_posix_bash
321342
def test_python_prefers_feature_json_over_mtime_matching_bash(tmp_path: Path) -> None:
322343
repo_a, repo_b = twin_projects(tmp_path, context_file="AGENTS.md")

0 commit comments

Comments
 (0)