Repository navigation
🐛 fix(windows): redact screenshot directory creation errors - #359
Conversation
Hive-Run: hivecommons#358 Hive-Plan: windows-directory-error-redaction Hive-Spec: hivecommons#358#proposed-fix Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
|
hive/awaiting-ci: CI pending — sweep will merge when green. — hive: agent=scanner backend=codex model=gpt-6.1-sol effort=high 🐝 Hive Agent: |
There was a problem hiding this comment.
[correctness] The script change (windows/hotshot-capture.ps1:55-59) matches the fix proposed in #358 and is correct. The new tests, however, never reach the catch, and CI's Pester job is red because of it (4 failures, run 41984966962).
Fixture does not make New-Item fail — windows/tests/hotshot-capture.e2e.tests.ps1:328-330 and :353-356
The fixture writes a file at $script:ShotDir and expects New-Item -ItemType Directory -Force -Path $Dir to throw. On Windows pwsh, -Force against an existing item (file or directory) returns the existing item without error, so the try at hotshot-capture.ps1:55 succeeds and the script continues. CI shows exactly that: Expected 1, but got 0, the stub log contains all nine calls through Invoke-HotshotInjection, and stderr is the stub Set-Content failure (Could not find a part of the path '…\nested\shots\hotshot-stub.png') rather than the redacted hotshot: line. The PR body's "Added Pester end-to-end coverage for directory-creation failure" is therefore not yet true — the catch branch has no coverage.
Put the blocking file one level up instead: a file at the parent (…\nested) forces Directory.CreateDirectory to create nested as an intermediate directory, which fails with IOException ("Cannot create '…' because a file or directory with the same name already exists"), so the rest of the assertions (including -Not -Match 'already\s*exists') keep working. Same edit in both places:
# A file at the PARENT of -Dir makes the real New-Item fail (it must
# create 'nested' as an intermediate directory); -Force on a file
# at -Dir itself silently returns the existing item instead.
New-Item -ItemType Directory -Force -Path $script:TempRoot | Out-Null
Set-Content -LiteralPath (Split-Path -Parent $script:ShotDir) -Value 'blocking-file'
$script:Result = Invoke-CaptureScript -Arguments "-Dir `"$script:ShotDir`"" -WithImage
and at :353-354:
New-Item -ItemType Directory -Force -Path $script:TempRoot | Out-Null
Set-Content -LiteralPath (Split-Path -Parent $script:ShotDir) -Value 'blocking-file'
Please confirm the exception name from the CI output after the change; if .NET surfaces it differently on the runner, loosen the two \(IOException\) assertions (:334, :362) to the observed type rather than changing the fixture back.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
@thatguywob this PR is back in your court ( Review asks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Reviewed by Reviewer notesRead the tree at
No findings from the correctness, security, style, or docs perspectives; the README's "diagnostics omit screenshot directory paths" wording already describes the post-change behaviour. Review findings from The production change is right; the four new Pester tests do not exercise it and are what turns CI red. The What fails (Pester job 127108756395, head
Net: the fixture does not reproduce a directory-creation failure, so the new tests fail without demonstrating the fix, and the body's claim that they cover "directory-creation failure, redaction, and stopping before screenshot reservation" is not borne out by the run. Suggestion, not a defect in the script: trigger a real terminating error from I have not run anything beyond reading the diff, tree and CI log. Evidence bundle `#3597a8fae8` sha256:52c5975bcfae65f8591fea621e14fbcd74b5f98509e9c3cc9b1202bf10bc33a4 — download from the dashboard or `hivectl review evidence #359`. |
Block the screenshot directory's parent so New-Item -Force reaches the real error handler. Check that parent path for leaks while allowing PowerShell's script-location header. Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
|
Check report (hive scanner, read-only — fork branch, nothing pushed) at head f8211b2:
So a blocking file at the parent is not a reliable way to make A. Invalid path segment (keeps B. ACL deny on Either way, drop the 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
|
@thatguywob this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
There was a problem hiding this comment.
The production change is right; the new Pester fixture does not exercise it, and all four new tests fail in CI on this head.
windows/hotshot-capture.ps1:55-59 is exactly the shape #358 proposed and matches the cannot reserve / could not save handlers directly below it (same Get-RedactedPath + GetBaseException().GetType().Name idiom). No concerns with that hunk.
The fixture is the problem. windows/tests/hotshot-capture.e2e.tests.ps1:329 and :355 block creation by writing a file at TempRoot\nested, expecting New-Item -ItemType Directory -Force -Path …\nested\shots to throw. On the CI runner it does not reach the catch: the Pester run for f8211b2 (CI run 41986623226) shows
exits 1 with a hotshot-prefixed error …→Expected 1, but got 0stops before reserving, saving, …→ call log is the full 9-call sequence throughInvoke-HotshotInjection, not@('Start-Process','Wait-HotshotClipboardImage')does not leak …→ the only error on stderr is the stub'sSet-Contentfailing later:Could not find a part of the path '…\nested\shots\hotshot-stub.png'— raw path and all, because that error comes from the stubImage.Save(e2e.tests.ps1:56), not from the script- the verbose-logging case →
Expected 1, but got 0for the same reason
So on this head the script runs to completion and exits 0 with the blocking file in place, and the catch at :57 is never entered — the PR validates nothing about the behaviour it changes (and the body's "Tests … were not run locally" is accurate; CI is the first run).
Suggestion: drive the failure the way the sibling cases do rather than through the filesystem. The stub module already exports functions the script calls, and a function wins command precedence over a cmdlet, so a New-Item function in $script:StubModule that throws [System.UnauthorizedAccessException] (the real case in #358: ACL-denied parent) when HOTSHOT_TEST_MKDIR_FAIL=1, wired up as a -MkdirFails switch on Invoke-CaptureScript like -ReserveFails/-SaveFails, would exercise the catch deterministically and let the assertions check (UnauthorizedAccessException). Alternatively an icacls … /deny on TempRoot\nested, but that needs cleanup and is slower.
Also worth re-checking the expectation '\(IOException\)' once the fixture actually throws — the base-exception type depends on how the failure is induced.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Use Directory.CreateDirectory so file collisions reach the redacted failure handler instead of being suppressed by New-Item -Force. Exercise collisions at the target and parent, and preserve existing directory contents. Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
There was a problem hiding this comment.
Read the change against the tree at 7a8fae8; this looks correct to me.
windows/hotshot-capture.ps1:55-61—[System.IO.Directory]::CreateDirectorywrapped intry/catchroutes throughFail+Get-RedactedPath, exactly like thecannot reservesibling at line 71 and the Linux step atlinux/hotshot-capture.sh:160.GetBaseException()correctly unwraps PowerShell'sMethodInvocationException, so the test's(IOException)assertion holds for both the blocking-parent and blocking-dir cases.Get-RedactedPath(HotshotCapture.psm1:134-142) returns the fixed redaction placeholder unlessHOTSHOT_VERBOSE_LOGGINGis set, so the new Pester assertions on the placeholder and the verbose opt-in test check the real contract, not a side effect.- Existing-directory behaviour is preserved (
CreateDirectoryis a no-op on an existing folder) and is covered by the new "preserves its contents" test.
Closes #358 as stated; no scope beyond it. Windows Pester and PSScriptAnalyzer checks are green on this head. Nothing for a human to decide here beyond the merge itself.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Ready for a human merge: verdict approved @7a8fae8, 7/7 checks green, DCO yes, soak 10m0s elapsed. Blocked only by The hive never approves on your behalf: |
|
/lgtm Posted by @clubanderson from the Hive dashboard; the merge gate decides from here. |
|
@hivecommons-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/approve Posted by @clubanderson from the Hive dashboard; the merge gate decides from here. |
There was a problem hiding this comment.
Approved by @clubanderson for Hive auto-merge on green CI.
Approved from the Hive dashboard by @clubanderson as the owner decision on a Ready-for-human-merge pull request; the hive's merge sweep merges it on green CI.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hivecommons-hive[bot] The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@hivecommons-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Hive queued this PR but could not set the |
|
merged by Hive on behalf of @clubanderson, who approved this head (operator-approval:clubanderson) with "Approve and let hive merge": author @thatguywob holds no trusted-author role; CI green at 7a8fae8. |
Summary
Windows directory-creation failures must follow the documented path-redaction policy, just like screenshot reservation failures. Catching the error keeps private directory names out of normal diagnostics while retaining the exception type and the existing verbose-logging opt-in.
Fixes #358
Validation
git diff --check.— hive: agent=scanner backend=codex model=gpt-6.1-sol effort=high
🐝 Hive Agent:
contributor| SHA:21940f2