fix(scripts): buffer large plain gh payloads

This commit is contained in:
Vincent Koc
2026-06-23 10:21:36 +08:00
parent 8041813040
commit 90f51eafd5
2 changed files with 36 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { plainGhEnv, resolvePlainGhBin } from "../../scripts/lib/plain-gh.mjs";
import { execPlainGh, plainGhEnv, resolvePlainGhBin } from "../../scripts/lib/plain-gh.mjs";
const tempDirs: string[] = [];
@@ -36,6 +36,21 @@ printf 'COLORTERM_SET=%s\\n' "\${COLORTERM+x}"
return ghPath;
}
function makeLargeFakeGh(): string {
const dir = mkdtempSync(path.join(tmpdir(), "plain-gh-large-"));
tempDirs.push(dir);
const ghPath = path.join(dir, "gh");
writeFileSync(
ghPath,
`#!/usr/bin/env node
const bytes = Number(process.env.PLAIN_GH_FAKE_BYTES ?? "0");
process.stdout.write("x".repeat(bytes));
`,
);
chmodSync(ghPath, 0o755);
return ghPath;
}
describe("plain gh helpers", () => {
it("prefers OPENCLAW_GH_BIN over PATH shims", () => {
const ghPath = makeFakeGh();
@@ -99,6 +114,22 @@ describe("plain gh helpers", () => {
expect(readFileSync(outputPath, "utf8")).toContain("COLORTERM_SET=");
});
it("captures large gh payloads by default", () => {
const ghPath = makeLargeFakeGh();
const bytes = 2 * 1024 * 1024;
const output = execPlainGh(["api", "large"], {
encoding: "utf8",
env: {
...process.env,
OPENCLAW_GH_BIN: ghPath,
PLAIN_GH_FAKE_BYTES: String(bytes),
},
});
expect(output).toHaveLength(bytes);
});
it("keeps the shell resolver on external gh binaries", () => {
const helper = readFileSync("scripts/lib/plain-gh.sh", "utf8");