fix(cli): refuse to spawn daemon from a test binary - #4
Merged
Conversation
added 2 commits
April 22, 2026 20:59
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.
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.
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
EnsureDaemonso it refuses toSpawnDetached(os.Executable())when the current process is a*.test/*.test.exebinary.go test,os.Executable()is the test runner; detaching it leaks a zombiecli.test.exethat holds handles on itst.TempDirtrees. On Windows this blocks cleanup and spams%TEMP%\Test<Name>*indefinitely (one dir per run × up to 65 nested subdirs each).Test plan
go build ./...go vet ./...go test ./...(non-race, local — no cgo/gcc here; CI covers-race)TestEnsureDaemon_RefusesToSpawnTestBinaryexercises the guard live —os.Executable()is a test binary, so it hits the new error path and asserts the message. Skips gracefully (with a reason) on exotic runners where the basename doesn't match.TestIsTestBinarycovers.test,.test.exe, mixed case, and real binary names likeghosthost/ghosthost.exe.go vet,go test -race, smoke, govulncheck, gosec, fuzz) — must go green before merge.🤖 Generated with Claude Code