|
25 | 25 | POWERSHELL = ( |
26 | 26 | shutil.which("pwsh") or shutil.which("powershell.exe") or shutil.which("powershell") |
27 | 27 | ) |
| 28 | +# On Windows, prefer the built-in Windows PowerShell 5.1 (.NET Framework) when a |
| 29 | +# test needs to exercise a 5.1-specific code path; fall back to whatever |
| 30 | +# POWERSHELL resolves to elsewhere. |
| 31 | +WINDOWS_POWERSHELL = ( |
| 32 | + (shutil.which("powershell.exe") or shutil.which("powershell") or POWERSHELL) |
| 33 | + if os.name == "nt" |
| 34 | + else POWERSHELL |
| 35 | +) |
28 | 36 |
|
29 | 37 |
|
30 | 38 | def _write_ext_config(project_root: Path, **overrides: object) -> None: |
@@ -279,12 +287,14 @@ def shlex_quote(value: str) -> str: |
279 | 287 | return "'" + value.replace("'", "'\"'\"'") + "'" |
280 | 288 |
|
281 | 289 |
|
282 | | -def _run_powershell_agent_context_script(project_root: Path) -> subprocess.CompletedProcess: |
| 290 | +def _run_powershell_agent_context_script( |
| 291 | + project_root: Path, powershell: str | None = None |
| 292 | +) -> subprocess.CompletedProcess: |
283 | 293 | script = EXT_DIR / "scripts" / "powershell" / "update-agent-context.ps1" |
284 | 294 | env = _bundled_script_env(project_root) |
285 | 295 | return subprocess.run( |
286 | 296 | [ |
287 | | - POWERSHELL, |
| 297 | + powershell or POWERSHELL, |
288 | 298 | "-NoProfile", |
289 | 299 | "-ExecutionPolicy", |
290 | 300 | "Bypass", |
@@ -412,6 +422,29 @@ def test_bash_script_deduplicates_context_files_in_order(self, tmp_path): |
412 | 422 | assert output.count("agent-context: updated CLAUDE.md") == 1 |
413 | 423 | assert "agent-context: updated agents.md" not in output |
414 | 424 |
|
| 425 | + @requires_bash |
| 426 | + def test_bash_script_discovers_nested_plan(self, tmp_path): |
| 427 | + """Plan discovery recurses into scoped layouts (#3024).""" |
| 428 | + project = tmp_path / "project" |
| 429 | + project.mkdir() |
| 430 | + _install_agent_context_config( |
| 431 | + project, |
| 432 | + context_file="AGENTS.md", |
| 433 | + context_files=[], |
| 434 | + ) |
| 435 | + plan = project / "specs" / "scope" / "001-feature" / "plan.md" |
| 436 | + plan.parent.mkdir(parents=True) |
| 437 | + plan.write_text("# Plan\n", encoding="utf-8") |
| 438 | + |
| 439 | + result = _run_bash_agent_context_script(project) |
| 440 | + |
| 441 | + assert result.returncode == 0, result.stderr + result.stdout |
| 442 | + text = (project / "AGENTS.md").read_text(encoding="utf-8") |
| 443 | + # The old one-level glob (specs/*/plan.md) would find nothing here, so no |
| 444 | + # "at" line would be emitted. Normalize separators before matching: on |
| 445 | + # MSYS bash the emitted path may be absolute with backslashes. |
| 446 | + assert "specs/scope/001-feature/plan.md" in text.replace("\\", "/") |
| 447 | + |
415 | 448 | @requires_bash |
416 | 449 | def test_bash_script_falls_back_from_invalid_speckit_python(self, tmp_path): |
417 | 450 | project = tmp_path / "project" |
@@ -484,6 +517,33 @@ def test_powershell_script_deduplicates_context_files_in_order(self, tmp_path): |
484 | 517 | assert output.count("agent-context: updated CLAUDE.md") == 1 |
485 | 518 | assert "agent-context: updated agents.md" not in output |
486 | 519 |
|
| 520 | + @pytest.mark.skipif(WINDOWS_POWERSHELL is None, reason="PowerShell not available") |
| 521 | + def test_powershell_script_discovers_nested_plan(self, tmp_path): |
| 522 | + """Plan discovery recurses into scoped layouts (#3024). |
| 523 | +
|
| 524 | + The relative-path fix this covers is specific to Windows PowerShell 5.1 |
| 525 | + (.NET Framework), so prefer ``powershell.exe`` over ``pwsh`` here to |
| 526 | + actually exercise that failure mode on Windows. |
| 527 | + """ |
| 528 | + project = tmp_path / "project" |
| 529 | + project.mkdir() |
| 530 | + _install_agent_context_config( |
| 531 | + project, |
| 532 | + context_file="AGENTS.md", |
| 533 | + context_files=[], |
| 534 | + ) |
| 535 | + plan = project / "specs" / "scope" / "001-feature" / "plan.md" |
| 536 | + plan.parent.mkdir(parents=True) |
| 537 | + plan.write_text("# Plan\n", encoding="utf-8") |
| 538 | + |
| 539 | + result = _run_powershell_agent_context_script( |
| 540 | + project, powershell=WINDOWS_POWERSHELL |
| 541 | + ) |
| 542 | + |
| 543 | + assert result.returncode == 0, result.stderr + result.stdout |
| 544 | + text = (project / "AGENTS.md").read_text(encoding="utf-8") |
| 545 | + assert "at specs/scope/001-feature/plan.md" in text |
| 546 | + |
487 | 547 | @pytest.mark.skipif(POWERSHELL is None, reason="PowerShell not available") |
488 | 548 | def test_powershell_script_falls_back_from_invalid_speckit_python(self, tmp_path): |
489 | 549 | project = tmp_path / "project" |
|
0 commit comments