test(code-runtime-python): cover the zero-content open-continuation skip

The skip branch (an empty open continuation is not pushed into the hold) needs
coverage; a case drives an empty continuation between a first fragment and the
closing frame and asserts the merged entry is unchanged.
This commit is contained in:
Chinesezjc
2026-08-31 15:06:05 +08:00
committed by Tianyi Cui
parent d9ed44d62c
commit 716060a04a
@@ -1906,6 +1906,26 @@ describe('PythonCodeRuntime — programs and bindings', () => {
expect(result.logs).toEqual(['committed'])
}, 15_000)
it('skips the hold for a zero-content open continuation', async () => {
// An empty open continuation bills 0 and is NOT pushed into the held
// fragment array (an empty fragment contributes nothing to the merged
// entry, and holding it would let a forged empty-open flood grow host
// memory without touching the ledger).
const { runtime } = await setup({ maxLogBytes: 64 })
const result = await runtime.run({
program: [
'import os',
"os.write(3, b'{\"type\":\"log\",\"text\":\"x\",\"open\":true}\\n')",
"os.write(3, b'{\"type\":\"log\",\"text\":\"\",\"open\":true}\\n')",
"os.write(3, b'{\"type\":\"log\",\"text\":\"y\"}\\n')",
'return "done"',
].join('\n'),
bindings: [],
})
expect(result.error).toBeUndefined()
expect(result.logs).toEqual(['xy'])
}, 15_000)
it('bounds a forged open-frame flood against the log budget', async () => {
// The open hold must be bounded by the ledger: without the exact-cost check
// a forged open flood would grow the held fragment without touching