test(disk-hygiene): mock sys.argv in run_guard* helpers to seal the kill-switch argv seam - #971
Conversation
…ill-switch argv seam `resolve_disk_hygiene_enabled()` reads `--disk-hygiene-enabled` from `sys.argv[1:]` before the environment fallback (#382). The `run_guard`, `run_guard_disabled`, and `run_guard_powershell_disabled` helpers in `test_hygiene.py` patched `os.environ` to drive the kill switch but left `sys.argv` unpatched, so a test runner whose real invocation argv carried that flag could override the env-var mock and flip an expected `deny` to `ask`. Each helper now patches `guard.sys.argv` to a clean, flag-free argv alongside its existing environment mock — matching the `run_guard_enabled_argv` helper already in the file — so the environment variable stays the sole channel under test. Test-only isolation seal; no production logic changes. Standard `unittest`/`pytest` invocations never produced such argv, so this closes latent fragility rather than a live failure. Closes #970 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @kyle-sexton's task in 1m 27s —— View job PR Review
SummaryThis PR correctly seals a latent test-isolation seam where three CorrectnessThe three new patches use The clean argv Known gap:
|
|
Claude finished @kyle-sexton's task in 57s —— View job Security Review — PR #971
No security issues found. The three changed files are:
Test-file analysis The only substantive code change is adding one line to each of three test helpers in mock.patch.object(guard.sys, "argv", [str(SCRIPT_DIR / "destructive_guard.py")]),
The PR does exactly what it claims: it seals a latent test-isolation seam. The approach (patching |
|
Claude finished @kyle-sexton's task in 1m 7s —— View job PR Review — #971
SummaryThis PR seals a latent test-isolation seam: CorrectnessAll three additions follow the correct form — targeting Patching The patched argv Known gap:
|
|
Reviewed personally (rule 10): small, exactly matches the described fix, test-only, no production-logic drift. Independently confirmed live CI green (not just the worker's local run). Flipping to ready. |
|
Claude finished @kyle-sexton's task in 54s —— View job Security Review — PR #971
No security issues found. The three changed files are:
Test-file analysis The only substantive code change adds one line to each of three test helpers: mock.patch.object(guard.sys, "argv", [str(SCRIPT_DIR / "destructive_guard.py")]),
Pre-existing condition (not introduced by this PR)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2aeae81af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… kill-switch argv seam (#974) ## Summary `resolve_disk_hygiene_enabled()` reads `--disk-hygiene-enabled` from `sys.argv[1:]` before the environment fallback (introduced in #382). The `run_guard_powershell` helper in `plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py` — the enabled-PowerShell sibling of the three helpers sealed in #971 — patched `os.environ` to drive the kill switch but left `sys.argv` unpatched. If a test runner's real invocation argv happened to carry `--disk-hygiene-enabled <value>`, it would silently override the env-var mock the test intends to exercise. This is test-isolation fragility, not a live failure: standard `unittest`/`pytest` invocations never produce such argv, so CI is unaffected today. The fix seals the one latent seam #971 deliberately left out of scope, bringing all five `run_guard*` helpers to parity. ## Change `run_guard_powershell` now patches `guard.sys.argv` to a clean, flag-free argv (`[str(SCRIPT_DIR / "destructive_guard.py")]`) alongside its existing `os.environ` mock — the exact pattern the four now-fixed helpers (`run_guard`, `run_guard_disabled`, `run_guard_powershell_disabled`, `run_guard_enabled_argv`) already use. With no argv flag present, `resolve_disk_hygiene_enabled()` falls through to the environment mock, keeping the env var the sole channel under test. No production logic is touched. Version bumped `0.4.5 → 0.4.6` (patch — pure test isolation, no behavior change) with a matching `CHANGELOG.md` entry. ## Verification - `python -m unittest -v test_hygiene.py` — 81 passed, 4 skipped (platform gates). - `ruff check` on the touched file — All checks passed. - `markdownlint-cli2` on `CHANGELOG.md` — 0 errors. - `check-changelog-parity.sh --check` and `--check-bump origin/main` — pass. - `scripts/validate-plugins.sh` — manifests + catalog validated. ## Related - #970 / #971 — the sibling fix this completes; #971 sealed the same seam in the other four `run_guard*` helpers and its own body flagged this enabled PowerShell helper as a deliberately out-of-scope follow-up. - The Codex P2 review thread on #971 that formally raised this (non-blocking, deferred to keep #971 landing clean) and filed it here as #973. - #382 — the argv-reading precedence in `resolve_disk_hygiene_enabled()` that this test change seals against. Closes #973 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
resolve_disk_hygiene_enabled()reads--disk-hygiene-enabledfromsys.argv[1:]before the environment fallback (introduced in #382). Three helpers inplugins/disk-hygiene/skills/clean/scripts/test_hygiene.py—run_guard,run_guard_disabled, andrun_guard_powershell_disabled— patchedos.environto drive the kill switch but leftsys.argvunpatched. If a test runner's real invocation argv happened to carry--disk-hygiene-enabled <value>, it would silently override the env-var mock and arun_guard_powershell_disabled-based test would observeaskwheredenyis expected.This is test-isolation fragility, not a live failure: standard
unittest/pytestinvocations never produce such argv, so CI is unaffected today. The fix seals the latent seam.Change
Each of the three helpers now patches
guard.sys.argvto a clean, flag-free argv ([str(SCRIPT_DIR / "destructive_guard.py")]) alongside its existingos.environmock — the exact pattern the newerrun_guard_enabled_argvhelper already established. With no argv flag present,resolve_disk_hygiene_enabled()falls through to the environment mock, keeping the env var the sole channel under test. No production logic is touched; the underlying #968 fix is correct and security-reviewed clean.Version bumped
0.4.4 → 0.4.5(patch — pure test isolation, no behavior change) with a matchingCHANGELOG.mdentry.Verification
python -m unittest -v test_hygiene.py— 81 passed, 4 skipped (platform gates).ruff checkon the touched file — All checks passed.markdownlint-cli2onCHANGELOG.md— 0 errors.check-changelog-parity.sh --checkand--check-bump origin/main— pass.scripts/validate-plugins.sh— manifests + catalog validated.Note (out of scope, follow-up candidate)
run_guard_powershell(the enabled PowerShell helper) carries the identical env-only seam but is not named in #970, so it is deliberately left untouched here to keep this PR atomic to the issue's stated scope. Worth a follow-up to seal for full consistency.Related
resolve_disk_hygiene_enabled()that this test change seals against.Closes #970
🤖 Generated with Claude Code