Skip to content

Commit 863b7cd

Browse files
committed
test(client): state the refused-signal teardown contract precisely
A refused SIGTERM is not proof of exit: it can also mean a companion still running under another owner. Say so, name the consequence (no exit wait, no escalation, state file dropped), and point at the daemon stopper that decides differently with `signal-failed`. Replace the injected waitForProcessExit success stub, which implied a confirmation the production path never makes, with assertions that no exit wait occurs and that the state file is dropped.
1 parent 6b34742 commit 863b7cd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/__tests__/client-metro-companion.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,23 @@ test('stopping a companion survives every process-teardown race', async () => {
363363
assert.equal(killSpy.mock.calls.length, 0);
364364
killSpy.mockRestore();
365365

366-
// 3. SIGTERM loses the race (EPERM): the companion is treated as stopped without escalating.
366+
// 3. SIGTERM is refused (EPERM). The shared stopper reads "signal refused" as
367+
// already-exited, so teardown reports stopped, skips the exit wait and SIGKILL,
368+
// and drops the state file without confirming an exit. EPERM can also mean a
369+
// companion still running under another owner, which is why the daemon's own
370+
// stopper keeps its registration instead (`signal-failed` in
371+
// src/daemon/process/daemon-stop.ts); companion teardown keeps the weaker
372+
// local-dev contract that a pid we cannot signal is not ours to keep tracking.
367373
vi.mocked(isProcessAlive).mockReturnValueOnce(true);
368374
vi.mocked(readProcessCommand).mockReturnValueOnce(companionCommand);
369375
killSpy = vi.spyOn(process, 'kill').mockImplementationOnce(() => {
370376
throw errnoException('EPERM');
371377
});
372-
vi.mocked(waitForProcessExit).mockResolvedValueOnce(true);
373378
statePath = writeOwnCompanionState(projectRoot, 4003);
374379
assert.equal((await stopMetroCompanion({ projectRoot })).stopped, true);
375380
assert.deepEqual(killSpy.mock.calls, [[4003, 'SIGTERM']]);
376381
assert.equal(vi.mocked(waitForProcessExit).mock.calls.length, 0);
382+
assert.equal(fs.existsSync(statePath), false);
377383
killSpy.mockRestore();
378384

379385
// 4. SIGTERM is ignored: escalate to SIGKILL and wait for the exit again.

0 commit comments

Comments
 (0)