diff --git a/packages/core/test/pty/pty-session.test.ts b/packages/core/test/pty/pty-session.test.ts index f74abf88a80..a238ffb579c 100644 --- a/packages/core/test/pty/pty-session.test.ts +++ b/packages/core/test/pty/pty-session.test.ts @@ -80,17 +80,19 @@ const attachCollecting = Effect.fn("PtySessionTest.attachCollecting")(function* return { attachment, output, ended } }) -const waitForOutput = (output: Queue.Queue, text: string) => - Effect.gen(function* () { - let received = "" +const waitForOutput = (output: Queue.Queue, text: string) => { + let received = "" + const pull = Effect.gen(function* () { while (!received.includes(text)) received += yield* Queue.take(output) return received - }).pipe( + }) + return pull.pipe( Effect.timeoutOrElse({ duration: PTY_TEST_TIMEOUT, // kilocode_change - orElse: () => Effect.fail(new Error(`timeout waiting for output containing ${JSON.stringify(text)}`)), + orElse: () => Effect.fail(new Error(`timeout waiting for output containing ${JSON.stringify(text)}, received ${JSON.stringify(received)}`)), }), ) +} describe("pty", () => { it.live("returns typed not found errors for missing sessions", () => @@ -143,11 +145,13 @@ describe("pty", () => { ) // (script terminals forward raw output to xterm without transcoding). + // The child must outlive its output: an immediate exit can race bun-pty's + // reader thread and drop trailing bytes under load, so print then sleep. ptyTest("round-trips non-ASCII output byte-identically", () => Effect.gen(function* () { const pty = yield* Pty.Service const marker = "café-über-北京-🚀" - const info = yield* createPty("sh", ["-c", "printf 'caf\\303\\251-\\303\\274ber-\\345\\214\\227\\344\\272\\254-\\360\\237\\232\\200\\n'"]) + const info = yield* createPty("sh", ["-c", "printf 'caf\\303\\251-\\303\\274ber-\\345\\214\\227\\344\\272\\254-\\360\\237\\232\\200\\n'; sleep 5"]) const attached = yield* attachCollecting(info.id) expect(yield* waitForOutput(attached.output, marker)).toContain(marker) }),