Skip to content

Commit 8a061c3

Browse files
committed
test(wake): preserve lock when boot identity goes unknown
1 parent 5722ddf commit 8a061c3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

internal/cli/wake_unix_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,34 @@ func TestShouldReplaceOrphanedWakeLockKeepsLockWhenKillDoesNotTerminate(t *testi
13621362
}
13631363
}
13641364

1365+
func TestTerminateWakeProcessPreservesLiveWakeOnUnknownBootAfterSignal(t *testing.T) {
1366+
const wakePID = 4343
1367+
root := secureTempDirForTest(t)
1368+
lockPath := writeWakeLockForTest(t, root, "codex", wakeLock{PID: wakePID, TTY: "tty", ProcessStart: "start-1", BootID: "boot-1", Executable: "/opt/homebrew/bin/amq"})
1369+
calls := 0
1370+
stubInspectWakeProcess(t, func(pid int) wakeProcessInfo {
1371+
calls++
1372+
info := wakeProcessInfo{PID: pid, Running: true, StartToken: "start-1", Executable: "/opt/homebrew/bin/amq", Args: []string{"/opt/homebrew/bin/amq", "wake", "--root", root, "--me", "codex"}}
1373+
if calls >= 3 { // after SIGTERM: still live, but boot identity is unavailable
1374+
return info
1375+
}
1376+
info.BootID = "boot-1"
1377+
return info
1378+
})
1379+
var signals []os.Signal
1380+
stubSignalWakeProcess(t, func(pid int, sig os.Signal) error { signals = append(signals, sig); return nil })
1381+
inspection := inspectWakeLock(root, "codex")
1382+
if err := terminateWakeProcess(inspection); err == nil {
1383+
t.Fatal("terminateWakeProcess unexpectedly declared success for live wake with unknown boot")
1384+
}
1385+
if len(signals) != 1 || signals[0] != syscall.SIGTERM {
1386+
t.Fatalf("signals = %v, want only SIGTERM", signals)
1387+
}
1388+
if _, err := os.Stat(lockPath); err != nil {
1389+
t.Fatalf("lock was removed or became unreadable: %v", err)
1390+
}
1391+
}
1392+
13651393
func TestShouldReplaceOrphanedWakeLockRevalidatesBeforeSignal(t *testing.T) {
13661394
const wakePID = 4242
13671395
root := secureTempDirForTest(t)

0 commit comments

Comments
 (0)