Skip to content

fix(cli): don't spawn daemon from cap-with-yes test (Windows CI) - #3

Merged
godspede merged 1 commit into
mainfrom
claude/fix-windows-ci-test
Apr 22, 2026
Merged

fix(cli): don't spawn daemon from cap-with-yes test (Windows CI)#3
godspede merged 1 commit into
mainfrom
claude/fix-windows-ci-test

Conversation

@godspede

Copy link
Copy Markdown
Owner

Summary

Fixes the CI failure on main after #2 merged.

All tests PASS on windows-latest, but the job exits 1 because go test can'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

  • `go test ./... -count=1` — all packages green locally
  • `TestCmdShare_CapWithYes_BypassesLimit` passes in isolation
  • CI on windows-latest passes

🤖 Generated with Claude Code

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>
@godspede
godspede merged commit a81ddd4 into main Apr 22, 2026
2 checks passed
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>
@godspede
godspede deleted the claude/fix-windows-ci-test branch July 17, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant