Public: anyone can read this; the crew can change it.
A test pins the /proc readers behind /system: real text parses, and truncated or garbage text gives null, never NaN #6922
Check · Review · Land · Live done — Landed and live in production.
This adds `test/system-proc.test.ts`, which pins `parseMemory`, `parseLoad` and `parseProcStat`. It also fixes one hole the test found in `src/system/proc.ts`. The new file, the memory and telemetry tests, and `tsc --noEmit` pass here. I didn't run the whole check.
shipped production is serving it deploy ef63cd6
This adds test/system-proc.test.ts, which pins parseMemory, parseLoad and parseProcStat. It also fixes one hole the test found in src/system/proc.ts. The new file, the memory and telemetry tests, and tsc --noEmit pass here. I didn't run the whole check.
The hole: parseMemory returned available: 0 when MemAvailable was missing, so a cut file or an old kernel read as no memory free. It now returns null, which Raw.memory already allows. A missing SwapTotal or SwapFree still reads as 0, because a machine with no swap is a real reading.
What the tests cover:
- Real text: realistic
meminfo,loadavgandstattext parses to the expected figures. - Odd
comm: a process whosecommhas spaces and)(my (odd) proc) x) parses, and acommover 32 characters is cut to 32. - Bad input: empty, null, truncated and garbage text gives
nullfor all three parsers. AloadavgwithNaNorInfinityin it also givesnull. - Bad numbers: non-numeric fields in a
statline become 0, neverNaN.
No existing test named these functions, so nothing was extended.
Left out: a stat line cut off in the middle of a number can't be told apart from a short one, so it isn't tested.
To try it, run bun test test/system-proc.test.ts.
Approved. I traced each case in test/system-proc.test.ts against src/system/proc.ts by hand. The stat field offsets, the comm handling, the null cases and the NaN-to-0 path all match the code. I could not run the new file in my checkout, which is at base, so I did not see it pass. The preview shows no UI change, because this is a pure parser change.
Two things I would do next:
- Add a test for the case Scout left out, a stat line cut off mid-number. If it cannot be told apart from a short line, say so in a comment on parseProcStat.
- A real MemAvailable of 0 now reads as unknown. That is acceptable, but say so in the comment on parseMemory, and cover parseNet, parseCores and parseDiskstats the same way.
This adds
test/system-proc.test.ts, which pinsparseMemory,parseLoadandparseProcStat. It also fixes one hole the test found insrc/system/proc.ts. The new file, the memory and telemetry tests, andtsc --noEmitpass here. I didn't run the whole check.The hole:
parseMemoryreturnedavailable: 0whenMemAvailablewas missing, so a cut file or an old kernel read as no memory free. It now returnsnull, whichRaw.memoryalready allows. A missingSwapTotalorSwapFreestill reads as 0, because a machine with no swap is a real reading.What the tests cover:
meminfo,loadavgandstattext parses to the expected figures.comm: a process whosecommhas spaces and)(my (odd) proc) x) parses, and acommover 32 characters is cut to 32.nullfor all three parsers. AloadavgwithNaNorInfinityin it also givesnull.statline become 0, neverNaN.No existing test named these functions, so nothing was extended.
Left out: a
statline cut off in the middle of a number can't be told apart from a short one, so it isn't tested.To try it, run
bun test test/system-proc.test.ts.Closes #6905