test: isolate cleanup_stale_cowork_socket BATS from host pgrep state (#534)

* test: isolate cleanup_stale_cowork_socket BATS from host pgrep state

Stub `pgrep` inside the `cleanup_stale_cowork_socket: removes stale
socket file` test so it returns nonzero. Without this, the test fails
on any developer machine running Claude Desktop because the real
`pgrep -f cowork-vm-service\.js` finds the live daemon and the
function correctly bails out before removing the socket — the
function's "daemon alive, leave socket alone" branch was leaking into
a test that was supposed to exercise the "no daemon, remove stale
socket" branch.

Fixes #533

* test: address PR #534 review — drop no-op export and stale comment

Per aaddrick's review:
- export -f pgrep is a no-op since cleanup_stale_cowork_socket runs
  in the same shell and bash function lookup beats PATH
- the "socat connection should fail" comment predates the move to
  pgrep checks and is now misleading
This commit is contained in:
Sum Abiut
2026-05-03 09:45:30 +11:00
committed by GitHub
parent 244c08a3bd
commit b367f8e5cc

View File

@@ -455,8 +455,12 @@ s.bind(sys.argv[1])
s.close()
" "$sock" 2>/dev/null || skip "Cannot create test unix socket"
# Stub pgrep so the test is isolated from host process state:
# a real cowork-vm-service daemon on the developer machine would
# trip the function's "daemon alive, leave socket alone" branch.
pgrep() { return 1; }
setup_logging
# socat connection should fail since nothing is listening
cleanup_stale_cowork_socket
[[ ! -S "$sock" ]]
}