From b3afe116319afe2983d7d03615a4ff174a06877c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 07:39:22 +0800 Subject: [PATCH] trae: stream.test breaks the connection by stopping its server, not by erroring the body (#268) Cause: "a stream that breaks off" errored the fake's response body with ctl.error(new Error("connection reset")). Bun prints a response body's error on every run, even with an error handler on the server, so every run of the file printed "error: connection reset" at that line while the test passed. #268 read that print as a red. It was never a failure: 40 of 40 printed it and passed under load on origin/main. The fake now stops its server mid-body, a real broken connection: the plugin still ends with Trae CN's error and [DONE], and nothing is printed. Run on macOS arm64, bun 1.4.2: - origin/main: 8 parallel `bun test --rerun-each 40 -t "breaks off"`: every run printed the error, 0 fail. - This change: 6 parallel `bun test --rerun-each 30 packages/trae/stream.test.mjs` at load average ~55: 6 x 420 pass, 0 fail, 0 printed. - `HOME=$(mktemp -d) bun test` from the root: 1920 pass, 0 fail. `bun scripts/check.mjs`: ok. Test-only, no version bump. --- packages/trae/stream.test.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/trae/stream.test.mjs b/packages/trae/stream.test.mjs index da9fe33..58943e2 100644 --- a/packages/trae/stream.test.mjs +++ b/packages/trae/stream.test.mjs @@ -148,7 +148,9 @@ test("a reply cut at its limit says length", async () => { test("a stream that breaks off ends with an error and [DONE]", async () => { // the connection breaks only once the caller has the first event, so the // plugin has read it: a reset timed by the clock alone can beat that read - // on a busy machine, and Bun then drops the event it had (#124) + // on a busy machine, and Bun then drops the event it had (#124). The fake + // breaks it by stopping its server mid-body, not by erroring the body: + // Bun prints a body's error on every run, and that read as a red (#268) let reset const caught = new Promise((r) => (reset = r)) f = fakeTrae() @@ -158,7 +160,7 @@ test("a stream that breaks off ends with an error and [DONE]", async () => { async pull(ctl) { if (n++ === 0) return ctl.enqueue(new TextEncoder().encode('event: output\ndata: {"response":"half"}\n\n')) await caught - ctl.error(new Error("connection reset")) + f.close() }, }) return new Response(body, { headers: { "content-type": "text/event-stream" } })