Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(processes): preserve UTF-8 across boxed CLI output chunks

Afloatfab23d915343
diff --git a/server/procs.test.ts b/server/procs.test.ts
index 5bb1ffeb1d..f01ef6b496 100644
--- a/server/procs.test.ts
+++ b/server/procs.test.ts
@@ -11,6 +11,7 @@ import {
describeSpawnFailure,
estimatedWindowsCommandLineChars,
execCli,
+ execCliBoxed,
killCliTree,
spawnCli,
WINDOWS_SAFE_COMMAND_LINE_CHARS,
@@ -78,6 +79,20 @@ describe("spawn ENOENT", () => {
});
});
+describe("execCliBoxed output", () => {
+ it("preserves UTF-8 characters across stdout and stderr pipe reads", async () => {
+ const output = "模型é😀".repeat(40_000);
+ const result = await new Promise<{ error: Error | null; stdout: string; stderr: string }>((resolve) => {
+ execCliBoxed(process.execPath, ["-e", "const text = '模型é😀'.repeat(40_000); process.stdout.write(text); process.stderr.write(text);"], {
+ env: process.env, timeout: hostTimeout(5_000), box: { allowEnv: [] },
+ }, (error, stdout, stderr) => resolve({ error, stdout, stderr }));
+ });
+ expect(result.error).toBeNull();
+ expect(result.stdout).toBe(output);
+ expect(result.stderr).toBe(output);
+ });
+});
+
describe("execCli timeout", () => {
it.skipIf(process.platform === "win32")("calls back when the CLI traps SIGTERM and outlives its timeout", async () => {
const started = Date.now();
diff --git a/server/procs.ts b/server/procs.ts
index bce4993523..375b53abd6 100644
--- a/server/procs.ts
+++ b/server/procs.ts
@@ -287,8 +287,10 @@ export function execCliBoxed(
clearTimeout(timer);
cb(err, stdout, stderr);
};
- child.stdout.on("data", (chunk: Buffer) => { if (stdout.length < limit) stdout += chunk.toString("utf8").slice(0, limit - stdout.length); });
- child.stderr.on("data", (chunk: Buffer) => { if (stderr.length < limit) stderr += chunk.toString("utf8").slice(0, limit - stderr.length); });
+ child.stdout.setEncoding("utf8");
+ child.stderr.setEncoding("utf8");
+ child.stdout.on("data", (chunk: string) => { if (stdout.length < limit) stdout += chunk.slice(0, limit - stdout.length); });
+ child.stderr.on("data", (chunk: string) => { if (stderr.length < limit) stderr += chunk.slice(0, limit - stderr.length); });
const timer = setTimeout(() => {
timedOut = true;
void killCliTree(child, 0);