test(code-runtime-python): cover the finish-residual sealed side; use a block array for the open seal

The review's two remaining non-blocking items: (1) a case where the run ends
with a SEALED open hold (past MAX_PENDING_CHUNKS) — finish() must commit the
sealed prefix, verified to fail if finish drops openSealed. (2) openSealed is
now a block ARRAY (one joined block per seal) matching the fd-3 reader's
blocks and the stray capture's seal, instead of one repeated string concat
that leaned on V8 ConsString amortization.
This commit is contained in:
Chinesezjc
2026-08-31 15:06:50 +08:00
committed by Tianyi Cui
parent 74e9d97e37
commit 771872a73d
2 changed files with 38 additions and 17 deletions
@@ -1890,6 +1890,25 @@ describe('PythonCodeRuntime — programs and bindings', () => {
expect(result.logs).toEqual(['ab'])
}, 15_000)
it('keeps a SEALED open hold when the run ends with it still open', async () => {
// The finish-residual's sealed side: an open hold past MAX_PENDING_CHUNKS
// lands in openSealed, and the run ends without a closing frame — finish()
// must commit the SEALED prefix, not only the current fragments.
const { runtime } = await setup({ maxLogBytes: 65536 })
const result = await runtime.run({
program: [
'import os',
"os.write(3, b'{\"type\":\"log\",\"text\":\"x\",\"open\":true}\\n')",
'for _ in range(3000):',
" os.write(3, b'{\"type\":\"log\",\"text\":\"a\",\"open\":true}\\n')",
'return "done"',
].join('\n'),
bindings: [],
})
expect(result.error).toBeUndefined()
expect(result.logs).toEqual(['x' + 'a'.repeat(3000)])
}, 15_000)
it('keeps a flushed unterminated line when the run ends with it still open', async () => {
// The settlement flush pushes the residual with `open: true`; finish()
// admits it so a program that commits a partial line and returns does not