Skip to content

Commit ff3d36d

Browse files
committed
test(codex): align app-server CI fixtures
1 parent 50c8358 commit ff3d36d

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

extensions/codex/src/app-server/sandbox-exec-server.pipe-survival.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* (no `error` listener on the stream) and the test fails.
1212
*/
1313
import type { ChildProcessWithoutNullStreams } from "node:child_process";
14+
import { pathToFileURL } from "node:url";
1415
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1516

1617
// Capture every child the exec-server spawns so tests can drive real stream
@@ -45,6 +46,7 @@ import {
4546
} from "./sandbox-exec-server.test-helpers.js";
4647

4748
const TMPDIR = process.env.TMPDIR ?? "/tmp";
49+
const TMPDIR_URL = pathToFileURL(TMPDIR).href;
4850
const WS_OPEN = 1;
4951

5052
function delay(ms: number): Promise<void> {
@@ -98,7 +100,7 @@ describe("sandbox exec-server pipe survival", () => {
98100
const start = (await rpc(socket, "process/start", {
99101
processId,
100102
argv: [process.execPath, "-e", SCRIPT],
101-
cwd: TMPDIR,
103+
cwd: TMPDIR_URL,
102104
tty: false,
103105
pipeStdin: false,
104106
})) as { processId: string };
@@ -122,7 +124,7 @@ describe("sandbox exec-server pipe survival", () => {
122124
await rpc(socket, "process/start", {
123125
processId: followId,
124126
argv: [process.execPath, "-e", "process.stdout.write('bridge-survived')"],
125-
cwd: TMPDIR,
127+
cwd: TMPDIR_URL,
126128
tty: false,
127129
pipeStdin: false,
128130
});

extensions/codex/src/app-server/sandbox-exec-server/streaming-response.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function readStreamingSandboxHttpResponse(params: {
2323
let streamFailure: string | null = null;
2424
let lastBodySeq = 0;
2525
let stdoutBuffer = "";
26+
const stdoutDecoder = new TextDecoder();
2627
let stderr = "";
28+
const stderrDecoder = new TextDecoder();
2729
const finalizeOnClose = async (status: "completed" | "failed", exitCode: number | null) => {
2830
await params.finalizeExec?.({
2931
status,
@@ -58,7 +60,7 @@ export function readStreamingSandboxHttpResponse(params: {
5860
}
5961
};
6062
params.child.stdout.on("data", (chunk: Buffer) => {
61-
stdoutBuffer += chunk.toString("utf8");
63+
stdoutBuffer += stdoutDecoder.decode(chunk, { stream: true });
6264
let newline = stdoutBuffer.indexOf("\n");
6365
while (newline >= 0) {
6466
const line = stdoutBuffer.slice(0, newline).trim();
@@ -101,7 +103,7 @@ export function readStreamingSandboxHttpResponse(params: {
101103
}
102104
});
103105
params.child.stderr.on("data", (chunk: Buffer) => {
104-
stderr = sliceUtf16Safe(`${stderr}${chunk.toString("utf8")}`, -4096);
106+
stderr = sliceUtf16Safe(`${stderr}${stderrDecoder.decode(chunk, { stream: true })}`, -4096);
105107
});
106108
onChildOutputStreamError(params.child, (message) => {
107109
if (failed) {
@@ -126,6 +128,8 @@ export function readStreamingSandboxHttpResponse(params: {
126128
childFailure ??= error.message;
127129
});
128130
params.child.once("close", (code) => {
131+
stdoutBuffer += stdoutDecoder.decode();
132+
stderr = sliceUtf16Safe(`${stderr}${stderrDecoder.decode()}`, -4096);
129133
const exitCode = code ?? 1;
130134
if (streamFailure) {
131135
finalizeAfterClose("failed", exitCode);

0 commit comments

Comments
 (0)