test(engine): pin the pid filter, dedup and tasklist memory guard in sampleProcessRss

Review of 76d8e2682 found three surviving mutants: removing the
`Number.isInteger(p) && p > 0` filter, dropping the `new Set` dedup, and
weakening `kb <= 0` to `kb < 0` all passed the plan's 8 tests. The filter is
the guard that matters most: Task 2 feeds `browser.process()?.pid`, and a
single NaN or undefined reaching `ps -p` makes ps exit non-zero, which the
never-rejects catch turns into `[]` for every pid in the sample.

Mutation check: each of the three mutants now fails exactly one test
("drops invalid pids and duplicates before calling ps" for the filter and
dedup, "returns [] when the memory column is not a positive number" for the
tasklist guard); restored source is 10/10 green.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-09-18 20:52:01 -07:00
co-authored by Claude Fable 5.1
parent bc70156f00
commit 645cbdce4e
@@ -26,6 +26,10 @@ describe("parseTasklistCsv", () => {
parseTasklistCsv(4242, "INFO: No tasks are running which match the specified criteria."),
).toEqual([]);
});
it("returns [] when the memory column is not a positive number", () => {
expect(parseTasklistCsv(7, '"chrome.exe","7","Console","1","N/A"\r\n')).toEqual([]);
});
});
describe("sampleProcessRss", () => {
@@ -54,6 +58,18 @@ describe("sampleProcessRss", () => {
expect(result).toEqual([{ pid: 9, rssMb: 2 }]);
});
it("drops invalid pids and duplicates before calling ps", async () => {
const calls: readonly string[][] = [];
const exec = async (_file: string, args: readonly string[]) => {
calls.push(args);
return { stdout: " 3 1024\n 4 2048\n" };
};
// NaN / 0 / -1 / 2.5 must never reach `ps -p`: one bad pid fails the
// whole call and every other pid's sample is lost with it.
await sampleProcessRss([3, 3, NaN, 0, -1, 2.5, 4], exec, "darwin");
expect(calls).toEqual([["-o", "pid=,rss=", "-p", "3,4"]]);
});
it("returns [] on empty input without calling exec", async () => {
let called = false;
const exec = async () => {