Sfoglia il codice sorgente

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.
Chinesezjc 1 mese fa
parent
commit
716060a04a

+ 20 - 0
packages/code-runtime/code-runtime-python/tests/runtime.spec.ts

@@ -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