docs(code-runtime-python): trim metering prose and cover encodeJsonPlain depth

- Drop the review-history narrative from checkDoneValue's JSDoc (the "in the
  previous implementation … now avoids" clause); state the current contract only.
- Assert encodeJsonPlain on the same 100k-deep value the metering test uses:
  its headline contract is stack-safety (JSON.stringify would throw), but no
  test exercised the encoder on a deep value.
This commit is contained in:
Chinesezjc
2026-08-07 13:27:54 +08:00
parent 4674d8fa92
commit 203bfca0ea
2 changed files with 8 additions and 4 deletions
@@ -283,11 +283,15 @@ describe('checkDoneValue', () => {
expect(checkDoneValue(Infinity, 3)).toEqual({ ok: false, reason: 'over-budget' })
})
it('meters deep nesting iteratively without overflowing the stack', () => {
it('meters and encodes deep nesting iteratively without overflowing the stack', () => {
let deep: unknown = 0
for (let i = 0; i < 100_000; i++) deep = [deep]
// 100000 '[' + '0' + 100000 ']' = 200001 bytes.
expect(checkDoneValue(deep, 1_000_000)).toEqual({ ok: true, bytes: 200_001 })
// encodeJsonPlain's headline contract is the same stack-safety (JSON.stringify
// recurses per level and throws RangeError a few thousand deep), so exercise
// it on the same 100k-deep value — JSON.stringify would throw here.
expect(encodeJsonPlain(deep)).toBe(`${'['.repeat(100_000)}0${']'.repeat(100_000)}`)
})
it('emits exact digits for beyond-safe integral doubles', () => {