@@ -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+
13651393func TestShouldReplaceOrphanedWakeLockRevalidatesBeforeSignal (t * testing.T ) {
13661394 const wakePID = 4242
13671395 root := secureTempDirForTest (t )
0 commit comments