Skip to content

test(shell): run the platform-independent shell tests on Windows - #4136

Merged
kovtcharov-amd merged 1 commit into
mainfrom
kalin/4127-shell-tests-windows-signal
Sep 24, 2026
Merged

kovtcharov-amd merged 1 commit into
mainfrom
kalin/4127-shell-tests-windows-signal

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Why this matters

A Windows contributor running the four shell test suites sees 112 skipped, which is visually indistinguishable from green. CI on ubuntu and macOS sees 112 real results. So the loop is: verify locally, see no red, push, watch CI fail — which is exactly how the confirm-gate defect in #3808 reached CI undetected.

The skip reason is genuine for the tests that actually launch a process: Windows runs each pipeline through cmd.exe, and os.killpg / process groups are POSIX-only. It is not genuine for the refusal, parsing, grant and tool-description tests — those decide before anything reaches a shell, and a module-level skip was hiding them on the platform most GAIA contributors develop on. After this change Windows runs 70 passed / 42 skipped instead of 112 skipped, and every one of those 70 is a real assertion about the security-adjacent refusal path.

POSIX is untouched: the per-test mark carries the same sys.platform == "win32" condition the module-level one did, so off Windows it is a no-op and all 112 still run.

🔍 Technical details

Membership was measured, not guessed. A throwaway pytest plugin stripped the cmd.exe skipifs, wrapped shell_tools.subprocess.Popen / .run, and recorded which node IDs actually spawned a child. 42 did; 70 did not. The 70 were then run on Windows 11 and all passed; every one of the 10 failures fell inside the 42. So the split is empirical, not a reading of the test names.

That measurement mattered, because running the tests would have given the wrong answer. This dev box has MSYS coreutils on PATH, so ls, cat, sort and date resolve and most execution tests pass here — they would not on a clean Windows machine or a windows-latest runner. Classifying on "does it pass on my box" is the hidden-state trap CLAUDE.md warns about; classifying on "does it spawn a process" is not.

  • pytestmark = pytest.mark.skipif(...) → posix_only = pytest.mark.skipif(...), same reason string per module, applied as @posix_only to the 35 spawning tests across three files.
  • No assertion was weakened, relaxed, or deleted. The diff is 53 insertions / 3 deletions; the 3 deletions are the pytestmark name on each of the three lines.
  • Node IDs are unchanged (no reorganisation into classes), so other in-flight PRs that name these tests in their test plans still resolve.
  • test_shell_env_assignment.py's two existing shutil.which("pytest") skipifs stack above @posix_only; pytest ORs them, so behaviour off Windows is identical.
  • tests/unit/test_shell_pipelines.py keeps its module-level mark — all seven of its tests genuinely run a pipeline, so there is nothing to promote. test_shell_output_encoding.py already used per-test marks and is untouched.
  • One pleasing side effect: test_windows_never_hands_a_compound_line_to_cmd_exe_as_one_string — a fully-mocked test about the Windows path — was itself skipped on Windows. It now runs there.

Merge-conflict note for reviewers: #3721 and #3402 both touch test_shell_compound_commands.py, neither near the pytestmark line. Whichever lands second may need a trivial rebase.

Scope

This does not close #4127. That issue asks for windows-latest in the test_unit.yml matrix, gated on #4115 and #4119 landing first so the lane starts green. This is a prerequisite for that lane being worth anything — without it, 112 of the tests the new lane would run are skipped by construction.

Test plan

  • python -m pytest tests/unit/test_shell_compound_commands.py tests/unit/test_shell_env_assignment.py -q on Windows 11 — was 77 skipped, now 51 passed, 26 skipped
  • Same for all four modules — was 112 skipped, now 70 passed, 42 skipped
  • python -m pytest tests/unit/test_shell*.py tests/unit/test_powershell_command_injection.py -q — 266 passed, 42 skipped
  • python util/lint.py --all — output byte-identical to a clean origin/main worktree (both exit 1 on the same pre-existing mypy findings in src/gaia/, none in files this PR touches)
  • CI on ubuntu/macOS — expect the same counts as before this PR; the mark is a no-op off Windows

Towards #4127.

A module-level skipif on four shell suites meant a Windows contributor saw
"77 skipped" where CI saw 77 real results, and "77 skipped" reads as green.
That is how a confirm-gate defect in #3808 got verified locally and still
failed on ubuntu.

The skip is demoted to a per-test @posix_only mark on exactly the tests that
launch a process. The refusal, parsing, grant and tool-description tests never
reach a shell, so they now run everywhere. Across the four modules: 112 skipped
becomes 70 passed / 42 skipped on Windows, with POSIX unchanged — the mark's
condition is the same sys.platform check, so it is a no-op off Windows.

Membership was measured, not guessed: a probe wrapped subprocess.Popen/run and
recorded which tests actually spawned. Every assertion is byte-identical.
test_shell_pipelines.py keeps its module-level mark because all seven of its
tests really do run a pipeline.
@github-actions github-actions Bot added the tests Test changes label Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

Windows contributors were seeing 112 skipped on the shell test suites — indistinguishable from green — because a module-level skip hid every test in three files, including the ones that never touch a shell. This swaps that for a per-test mark so the 70 refusal, parsing, grant and tool-description tests now actually run on Windows, while the 42 that spawn real processes stay skipped for the same genuine reason as before.

The split holds up under review: every test left unmarked asserts a refusal or a parse result, and every test asserting successful execution or real output carries the mark. Off Windows the mark is a no-op, so nothing changes for the existing CI lanes. No assertions were weakened or removed — the only deletions are the three old mark names.

One thing to keep in mind rather than fix: nothing enforces the split going forward. A future test in these files that launches a process but forgets the mark will only surface once the Windows lane from #4127 exists. That lane is the right guard, so this is a note, not a request.

Real-world evidence

N/A — tests-only change; no runnable product surface, so no evidence bundle was produced and the verdict rests on static review plus the counts in the PR description. The description does carry the relevant proof: real Windows 11 runs before and after (112 skipped → 70 passed, 42 skipped), plus the POSIX-side run confirming the mark is inert there. The remaining unchecked box (ubuntu/macOS CI) is the one thing still to confirm, and it should be a formality.

🔍 Technical details

Verification performed

Parsed all three modules and cross-checked mark membership against what each test asserts. Every one of the 29 unmarked tests asserts status == "error" / executed is False, a parse result from _parse_line, a grant decision via _tool_requires_confirmation / skill_grant_covers_call, or a tool-description string — none reach subprocess. The mocked test_windows_never_hands_a_compound_line_to_cmd_exe_as_one_string (test_shell_compound_commands.py:474) is the notable recovery: a test about the Windows path that the module-level skip disabled on Windows.

Could not run the suites here — pytest is not installed in this environment — so the POSIX no-op claim rests on the mark's condition being byte-identical to the one it replaced, which it is in all three files.

Points checked and cleared

  • test_shell_env_assignment.py:78-80 and :130-131 stack @pytest.mark.skipif(shutil.which("pytest") is None, ...) above @posix_only. pytest evaluates every skipif mark and skips if any condition is true, so this is an OR — behaviour off Windows is unchanged. Only the reported skip reason could differ, which is cosmetic.
  • test_shell_pipelines.py:20 correctly keeps its module-level pytestmark; all seven of its tests spawn a pipeline, so there is nothing to promote. test_shell_output_encoding.py already uses per-test marks (sys.platform != "win32", the inverse condition) and is consistently untouched.
  • Path-based unmarked tests (test_cd_outside_the_allowed_paths_is_refused, test_cd_to_a_missing_directory_says_so_instead_of_running_the_line, test_a_value_outside_the_allowed_paths_is_refused) build paths from tmp_path rather than POSIX literals, so they are portable.
  • Node IDs unchanged — no reorganisation into classes — so in-flight PRs naming these tests in their test plans still resolve.

🟢 Nit — the split has no automated guard (tests/unit/test_shell_compound_commands.py:22)

Membership is a judgement recorded as 35 decorators. The PR's own measurement method (wrapping shell_tools.subprocess.Popen / .run and recording which node IDs spawn a child) is exactly what a guard would do, and it was thrown away after use. Not worth building now — the windows-latest lane in #4127 catches a mis-marked test the first time it runs — but if that lane slips, this classification silently rots.

Strengths

  • Classifying on "does it spawn a process" rather than "does it pass on my box" is the right call, and the PR says why: MSYS coreutils on the dev box's PATH make execution tests pass locally that would fail on a clean windows-latest runner. That is precisely the hidden-state trap CLAUDE.md warns about, correctly avoided.
  • The per-module docstring additions explain why only some tests carry the mark, so the next person adding a test to these files knows which side they are on — the right place for that rule, given there is no lint check for it.
  • Scope is honest: the description states plainly that this does not close ci(tests): unit suite has no Windows lane on a Windows-first product #4127 and is a prerequisite for that lane being meaningful.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit 0e5e463 Sep 24, 2026
37 of 38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/4127-shell-tests-windows-signal branch September 24, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci(tests): unit suite has no Windows lane on a Windows-first product

2 participants