Skip to content

Commit c3424e9

Browse files
committed
test(service): pin the platform default, not just the explicit flag
Every existing case passed canRespawn explicitly, so the derivation itself was untested: a regression to `?? false` would have left all five green while Windows silently lost the restart window that lidge-jun#764 needs. The new case drives both platforms through the default with a mocked process.platform -- Linux completes at fake-clock 0 after one probe, Windows polls past 7000. Ablation to `?? false`: 5 pass / 1 fail; restored 6/6. Worth recording why the default is right, since the review checked it properly: the launchd plist does set KeepAlive and the systemd unit uses Restart=on-failure, so both CAN restart a child. But `ocx service stop` unloads the launchd job and issues a blocking `systemctl --user stop`, and neither is the crash exit those policies react to. The Windows scheduler wrapper surviving `schtasks /end` remains the one real survivor case.
1 parent 5530b8c commit c3424e9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/service-stop-verification.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,36 @@ describe("service stop verification (#764)", () => {
9393
});
9494
expect(live).toEqual({ port: 10100 });
9595
});
96+
97+
test("the platform default drives the behavior, not just the explicit flag", async () => {
98+
// Every other test passes canRespawn explicitly, so none of them exercises the DEFAULT --
99+
// a regression to `?? false` would leave them all green while Windows silently lost the
100+
// restart window it needs. These pin the derivation itself.
101+
const original = process.platform;
102+
const setPlatform = (value: string) =>
103+
Object.defineProperty(process, "platform", { value, configurable: true });
104+
try {
105+
setPlatform("linux");
106+
const linuxClock = fakeClock();
107+
let linuxProbes = 0;
108+
await proxyStillLiveAfterStop({
109+
findProxy: async () => { linuxProbes += 1; return null; },
110+
...linuxClock,
111+
});
112+
expect(linuxProbes).toBe(1);
113+
expect(linuxClock.now()).toBe(0);
114+
115+
setPlatform("win32");
116+
const winClock = fakeClock();
117+
let winProbes = 0;
118+
await proxyStillLiveAfterStop({
119+
findProxy: async () => { winProbes += 1; return null; },
120+
...winClock,
121+
});
122+
expect(winProbes).toBeGreaterThan(1);
123+
expect(winClock.now()).toBeGreaterThanOrEqual(7000);
124+
} finally {
125+
Object.defineProperty(process, "platform", { value: original, configurable: true });
126+
}
127+
});
96128
});

0 commit comments

Comments
 (0)