pi-mono/packages/codemode/test
robopipi[bot] 33cd7e5079
fix(codemode): print NaN and Infinity in console output and thrown values (#11945)
In codemode scripts, `console.*` showed `NaN`, `Infinity`, and
`-Infinity` as `null`. A thrown non-Error value such as `throw NaN` was
also reported with the message `null`. Both go through `format()` in the
script prelude, which passes every value that is not a string or an
Error to `JSON.stringify`. `JSON.stringify` turns non-finite numbers
into `"null"`. `text()` already printed these values correctly, so the
two output paths disagreed and the model saw `avg null` where it should
have seen `avg NaN`.

`format()` now calls `String()` on numbers. Objects still print as JSON,
so `NaN` inside an object still prints as `null`, as `JSON.stringify`
and `text()` do.

**Testing**
- Added a regression test to `packages/codemode/test/sandbox.test.ts`.
It runs on the worker, inline, and remote backends and checks console
output, `text()`, and `throw NaN`. All three backend runs fail without
the fix and pass with it. The whole file passes (156 tests).
- `npm run check` passes.
- Script `console.log("avg", 0/0, 1/0, -1/0, -0); text(0/0);`: the
console line was `avg null null null 0` before the fix and is `avg NaN
Infinity -Infinity 0` after it. The `text()` item is `NaN` in both
cases.
- `throw NaN`: the error message was `null` before and is `NaN` after.

Fixes #11901

Requested by @badlogic

Co-authored-by: triagent <triagent@localhost>
2026-11-09 09:29:00 +01:00
..
fixtures fix(coding-agent): keep codemode cancellation prompt and bounded 2026-10-13 18:17:31 +02:00
declarations.test.ts fix(coding-agent): follow local schema refs in tool search and codemode summaries (#11850) 2026-11-06 00:19:58 +01:00
deterministic.test.ts feat(durable): durable code mode (@earendil-works/pi-durable/codemode) 2026-10-11 21:31:48 +00:00
portable.test.ts feat(codemode): run sandboxes on Cloudflare Workers via a remote Durable Object 2026-10-10 14:41:36 +02:00
sandbox.test.ts fix(codemode): print NaN and Infinity in console output and thrown values (#11945) 2026-11-09 09:29:00 +01:00
source.test.ts fix(codemode): reject // @options: lines that are not the first line 2026-10-12 17:55:33 +02:00
worker-lifetime.test.ts fix(coding-agent): keep codemode cancellation prompt and bounded 2026-10-13 18:17:31 +02:00