fix(cli): don't spawn daemon from cap-with-yes test (Windows CI) - #3
Merged
Conversation
With 65 real temp files and --yes, cmdShare passed validation and called EnsureDaemon, which spawns os.Executable() detached via daemon.SpawnDetached. On Windows that's the test binary itself (cli.test.exe), and the detached child holds it open past the test's end — go test's cleanup then fails with 'unlinkat cli.test.exe: Access is denied' and the CI job exits 1 even though every test passed. Switch to 65 nonexistent paths so atomic pre-flight aborts with ExitSourceBad before reaching EnsureDaemon. The test still proves --yes bypassed the cap (otherwise we'd see ExitUsage). Tightened the sanity assertion to match the literal cap-rejection phrase rather than any "64" substring, because "nope-64.txt" false-positives. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 tasks
godspede
added a commit
that referenced
this pull request
Apr 23, 2026
* fix(cli): refuse to spawn daemon from a test binary EnsureDaemon calls daemon.SpawnDetached(os.Executable()). Under `go test`, os.Executable() is the test runner itself, so the detached child is a zombie cli.test.exe that survives the test run and holds open handles on its t.TempDir trees. On Windows this blocks cleanup, spams %TEMP%\Test<Name>* forever, and caused CI to fail with "unlinkat cli.test.exe: Access is denied" (PR #3 fixed this by reshaping the one test that tripped it). Harden the boundary instead of relying on every test to avoid the call: detect a .test / .test.exe basename in EnsureDaemon and return a descriptive error rather than forking. Real ghosthost / ghosthost.exe binaries are unaffected. Includes a regression test that asserts EnsureDaemon rejects the current process when run under `go test`, so future refactors can't quietly re-enable the zombie path. * fix(smoke): accept JSON array from `--json share` PR2 changed `--json share` to always emit an array (one element per file), including in the single-file case, but the smoke test still unmarshals into a single object. The regression has been latent on main since PR2 merged — PR3's CI stayed green only because the smoke result hit the build cache. This PR touches internal/cli, which invalidates that cache and surfaces the bug. Unmarshal into a []struct, assert len == 1 for this single-file share, and take index 0. --------- Co-authored-by: Zack Frank <Zackary.Frank@gmail.com>
godspede
added a commit
that referenced
this pull request
Jul 17, 2026
…it (#3) With 65 real temp files and --yes, cmdShare passed validation and called EnsureDaemon, which spawns os.Executable() detached via daemon.SpawnDetached. On Windows that's the test binary itself (cli.test.exe), and the detached child holds it open past the test's end — go test's cleanup then fails with 'unlinkat cli.test.exe: Access is denied' and the CI job exits 1 even though every test passed. Switch to 65 nonexistent paths so atomic pre-flight aborts with ExitSourceBad before reaching EnsureDaemon. The test still proves --yes bypassed the cap (otherwise we'd see ExitUsage). Tightened the sanity assertion to match the literal cap-rejection phrase rather than any "64" substring, because "nope-64.txt" false-positives. Co-authored-by: godspede <jehutheawesome@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
godspede
added a commit
that referenced
this pull request
Jul 17, 2026
* fix(cli): refuse to spawn daemon from a test binary EnsureDaemon calls daemon.SpawnDetached(os.Executable()). Under `go test`, os.Executable() is the test runner itself, so the detached child is a zombie cli.test.exe that survives the test run and holds open handles on its t.TempDir trees. On Windows this blocks cleanup, spams %TEMP%\Test<Name>* forever, and caused CI to fail with "unlinkat cli.test.exe: Access is denied" (PR #3 fixed this by reshaping the one test that tripped it). Harden the boundary instead of relying on every test to avoid the call: detect a .test / .test.exe basename in EnsureDaemon and return a descriptive error rather than forking. Real ghosthost / ghosthost.exe binaries are unaffected. Includes a regression test that asserts EnsureDaemon rejects the current process when run under `go test`, so future refactors can't quietly re-enable the zombie path. * fix(smoke): accept JSON array from `--json share` PR2 changed `--json share` to always emit an array (one element per file), including in the single-file case, but the smoke test still unmarshals into a single object. The regression has been latent on main since PR2 merged — PR3's CI stayed green only because the smoke result hit the build cache. This PR touches internal/cli, which invalidates that cache and surfaces the bug. Unmarshal into a []struct, assert len == 1 for this single-file share, and take index 0. --------- Co-authored-by: godspede <jehutheawesome@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the CI failure on
mainafter #2 merged.All tests PASS on
windows-latest, but the job exits 1 becausego testcan't clean up its compiled test binary:```
go: unlinkat C:...\cli.test.exe: Access is denied.
```
Root cause: `TestCmdShare_CapWithYes_BypassesLimit` created 65 real temp files and passed `--yes`, so `cmdShare` sailed through validation and hit `EnsureDaemon`. That calls `daemon.SpawnDetached(os.Executable(), ...)` — which on Windows during test runs is `cli.test.exe` itself. The detached child held the binary open past the test's end and Windows blocked cleanup.
Fix
Pass 65 nonexistent paths with `--yes`. Atomic pre-flight rejects them with `ExitSourceBad` before `EnsureDaemon` is ever called — no daemon spawn, no file lock, no cleanup failure. The test still proves `--yes` bypassed the cap (otherwise the code would exit `ExitUsage` from the cap check before reaching pre-flight).
Also tightened the sanity assertion to match the literal cap-rejection phrase rather than a bare `"64"` substring — the temp filename `nope-64.txt` was a false positive.
Test plan
🤖 Generated with Claude Code