Skip to content

Commit 06131c4

Browse files
committed
fix(ci): read large ratchet baselines without pipe limits
The mock baseline exceeds the default 1 MiB execFileSync buffer used by the shared Git snapshot reader. This started failing after merge, when the comparison revision first contained the full baseline instead of taking the bootstrap path. Send Git stdout directly to a private temporary file and read it only after successful completion. Preserve synchronous callers, Git errors, and cleanup on failure. Do not increase buffer caps or narrow mock detection. Extend the real Git snapshot regression past 2 MiB for worktree, index, and committed views. P2 review and all 70 Linux ratchet tests pass. The coherent 10,862-factory snapshot passes; current main additionally reports three unchanged unannotated mock sites, which remain strict validation failures. Peer commit 58310ca raised the reader cap to 256 MiB while this fix was in proof. Keep the already-proven permanent file-backed transport instead of a larger pipe cap; the small and 2 MiB tests preserve the peer fix coverage.
1 parent f02d516 commit 06131c4

2 files changed

Lines changed: 50 additions & 28 deletions

File tree

‎scripts/lib/shrink-ratchet.mts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execFileSync } from "node:child_process";
22
import fs from "node:fs";
3+
import os from "node:os";
34
import path from "node:path";
45

56
// Owns file-backed baselines and the per-file count ratchet lifecycle, including
@@ -35,12 +36,21 @@ export function parseRatchetArgs(argv: string[]) {
3536
}
3637

3738
function readGitText(root: string, args: string[]) {
38-
return execFileSync("git", args, {
39-
cwd: root,
40-
encoding: "utf8",
41-
maxBuffer: GIT_MAX_BUFFER,
42-
stdio: ["ignore", "pipe", "ignore"],
43-
});
39+
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-ratchet-git-"));
40+
const output = path.join(temporary, "stdout");
41+
let descriptor: number | undefined;
42+
try {
43+
descriptor = fs.openSync(output, "wx", 0o600);
44+
// Baseline blobs can exceed execFileSync's pipe limit. Git writes directly
45+
// to a file; only a successful command may supply the complete snapshot.
46+
execFileSync("git", args, { cwd: root, stdio: ["ignore", descriptor, "ignore"] });
47+
return fs.readFileSync(output, "utf8");
48+
} finally {
49+
if (descriptor !== undefined) {
50+
fs.closeSync(descriptor);
51+
}
52+
fs.rmSync(temporary, { recursive: true, force: true });
53+
}
4454
}
4555

4656
function resolvesCommit(root: string, ref: string) {

‎test/scripts/shrink-ratchet.test.ts‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,41 @@ describe("shrink-ratchet", () => {
5757
expect(loadRatchetSnapshot<unknown>(root, file, false, parse)).toEqual(expected);
5858
});
5959

60-
it("loads large worktree, index, and reference snapshots", () => {
61-
const root = tempDirs.make("openclaw-shrink-ratchet-git-");
62-
const baselinePath = "baseline.txt";
63-
const absolutePath = path.join(root, baselinePath);
64-
const padding = `# ${"x".repeat(1024 * 1024)}\n`;
65-
execFileSync("git", ["init"], { cwd: root, stdio: "ignore" });
66-
fs.writeFileSync(absolutePath, `${padding}1\n`);
67-
execFileSync("git", ["add", baselinePath], { cwd: root, stdio: "ignore" });
68-
execFileSync(
69-
"git",
70-
["-c", "user.name=OpenClaw", "-c", "[email protected]", "commit", "-m", "base"],
71-
{ cwd: root, stdio: "ignore" },
72-
);
73-
fs.writeFileSync(absolutePath, `${padding}2\n`);
74-
execFileSync("git", ["add", baselinePath], { cwd: root, stdio: "ignore" });
75-
fs.writeFileSync(absolutePath, `${padding}3\n`);
76-
const parse = (source: string) => parseRatchetScalar(source, baselinePath);
60+
it.each([0, 2 * 1024 * 1024])(
61+
"loads worktree, index, and reference snapshots with %i bytes of padding",
62+
(size) => {
63+
const root = tempDirs.make("openclaw-shrink-ratchet-git-");
64+
const baselinePath = "baseline.txt";
65+
const absolutePath = path.join(root, baselinePath);
66+
execFileSync("git", ["init"], { cwd: root, stdio: "ignore" });
67+
const padding = `#${"x".repeat(size)}\n`;
68+
fs.writeFileSync(absolutePath, padding + "1\n");
69+
execFileSync("git", ["add", baselinePath], { cwd: root, stdio: "ignore" });
70+
execFileSync(
71+
"git",
72+
[
73+
"-c",
74+
"user.name=OpenClaw",
75+
"-c",
76+
77+
"commit",
78+
"-m",
79+
"base",
80+
],
81+
{ cwd: root, stdio: "ignore" },
82+
);
83+
fs.writeFileSync(absolutePath, padding + "2\n");
84+
execFileSync("git", ["add", baselinePath], { cwd: root, stdio: "ignore" });
85+
fs.writeFileSync(absolutePath, padding + "3\n");
86+
const parse = (source: string) => parseRatchetScalar(source, baselinePath);
7787

78-
expect(loadRatchetSnapshot(root, baselinePath, false, parse)).toBe(3);
79-
expect(loadRatchetSnapshot(root, baselinePath, true, parse)).toBe(2);
80-
expect(loadRatchetReference(root, "HEAD", baselinePath, parse)).toBe(1);
81-
expect(loadRatchetReference(root, "HEAD", "missing.txt", parse)).toBeNull();
82-
});
88+
expect(loadRatchetSnapshot(root, baselinePath, false, parse)).toBe(3);
89+
expect(loadRatchetSnapshot(root, baselinePath, true, parse)).toBe(2);
90+
expect(loadRatchetReference(root, "HEAD", baselinePath, parse)).toBe(1);
91+
expect(loadRatchetReference(root, "HEAD", "missing.txt", parse)).toBeNull();
92+
expect(() => loadRatchetReference(root, "missing-ref", baselinePath, parse)).toThrow();
93+
},
94+
);
8395

8496
it.each([
8597
() => parseRatchetCounts("src/a.ts\t0\n", "counts.txt"),

0 commit comments

Comments
 (0)