diff --git a/src/shared/node-list-parse.test.ts b/src/shared/node-list-parse.test.ts index 379f4395054..9437e31118a 100644 --- a/src/shared/node-list-parse.test.ts +++ b/src/shared/node-list-parse.test.ts @@ -6,6 +6,7 @@ describe("shared/node-list-parse", () => { expect(parseNodeList({ nodes: [{ nodeId: "node-1" }] })).toEqual([{ nodeId: "node-1" }]); expect(parseNodeList({ nodes: "nope" })).toEqual([]); expect(parseNodeList(null)).toEqual([]); + expect(parseNodeList(["not-an-object"])).toEqual([]); }); it("parses node.pair.list payloads", () => { @@ -20,5 +21,6 @@ describe("shared/node-list-parse", () => { }); expect(parsePairingList({ pending: 1, paired: "x" })).toEqual({ pending: [], paired: [] }); expect(parsePairingList(undefined)).toEqual({ pending: [], paired: [] }); + expect(parsePairingList(["not-an-object"])).toEqual({ pending: [], paired: [] }); }); }); diff --git a/src/shared/pid-alive.test.ts b/src/shared/pid-alive.test.ts index c0d714fb21a..88066f1a794 100644 --- a/src/shared/pid-alive.test.ts +++ b/src/shared/pid-alive.test.ts @@ -59,6 +59,21 @@ describe("isPidAlive", () => { expect(freshIsPidAlive(zombiePid)).toBe(false); }); }); + + it("treats unreadable linux proc status as non-zombie when kill succeeds", async () => { + const readFileSyncSpy = vi.spyOn(fsSync, "readFileSync").mockImplementation(() => { + throw new Error("no proc status"); + }); + const killSpy = vi.spyOn(process, "kill").mockImplementation(() => true); + + await withLinuxProcessPlatform(async () => { + const { isPidAlive: freshIsPidAlive } = await import("./pid-alive.js"); + expect(freshIsPidAlive(42)).toBe(true); + }); + + expect(readFileSyncSpy).toHaveBeenCalledWith("/proc/42/status", "utf8"); + expect(killSpy).toHaveBeenCalledWith(42, 0); + }); }); describe("getProcessStartTime", () => { @@ -114,4 +129,19 @@ describe("getProcessStartTime", () => { expect(fresh(42)).toBe(55555); }); }); + + it("returns null for negative or non-integer start times", async () => { + const fakeStatPrefix = "42 (node) S 1 42 42 0 -1 4194304 12345 0 0 0 100 50 0 0 20 0 8 0 "; + const fakeStatSuffix = + " 123456789 5000 18446744073709551615 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0"; + mockProcReads({ + "/proc/42/stat": `${fakeStatPrefix}-1${fakeStatSuffix}`, + "/proc/43/stat": `${fakeStatPrefix}1.5${fakeStatSuffix}`, + }); + await withLinuxProcessPlatform(async () => { + const { getProcessStartTime: fresh } = await import("./pid-alive.js"); + expect(fresh(42)).toBeNull(); + expect(fresh(43)).toBeNull(); + }); + }); });