Skip to content

Commit 66b91d7

Browse files
committed
fix(e2e): bound release user journey JSON artifacts
1 parent 3753c5e commit 66b91d7

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

scripts/e2e/lib/release-user-journey/assertions.mjs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { readTextFileTail } from "../text-file-utils.mjs";
1414
const SCAN_CHUNK_BYTES = 64 * 1024;
1515
const SCAN_CARRY_CHARS = 256;
1616
const ERROR_DETAIL_TAIL_BYTES = 16 * 1024;
17+
const JSON_ARTIFACT_MAX_BYTES = 2 * 1024 * 1024;
1718

1819
function clickClackHttpTimeoutMs() {
1920
return readPositiveInt(
@@ -31,8 +32,30 @@ function clickClackHttpBodyMaxBytes() {
3132
);
3233
}
3334

34-
function readJson(file) {
35-
return JSON.parse(fs.readFileSync(file, "utf8"));
35+
function readJson(file, maxBytes = JSON_ARTIFACT_MAX_BYTES) {
36+
const stat = fs.statSync(file);
37+
if (!stat.isFile()) {
38+
throw new Error(`${file} is not a file`);
39+
}
40+
if (stat.size > maxBytes) {
41+
throw new Error(
42+
`JSON artifact exceeded ${maxBytes} bytes: ${file} (${stat.size} bytes). Tail: ${readTextFileTail(
43+
file,
44+
ERROR_DETAIL_TAIL_BYTES,
45+
)}`,
46+
);
47+
}
48+
const text = fs.readFileSync(file, "utf8");
49+
const bytes = Buffer.byteLength(text, "utf8");
50+
if (bytes > maxBytes) {
51+
throw new Error(
52+
`JSON artifact exceeded ${maxBytes} bytes: ${file} (${bytes} bytes). Tail: ${readTextFileTail(
53+
file,
54+
ERROR_DETAIL_TAIL_BYTES,
55+
)}`,
56+
);
57+
}
58+
return JSON.parse(text);
3659
}
3760

3861
function readPositiveInt(raw, fallback, label) {

test/scripts/release-user-journey-assertions.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,31 @@ describe("release user journey assertions", () => {
137137
}
138138
});
139139

140+
it("rejects oversized JSON artifacts before parsing release user journey config", () => {
141+
const root = mkdtempSync(path.join(tmpdir(), "openclaw-release-user-assertions-"));
142+
const home = path.join(root, "home");
143+
const configPath = path.join(home, ".openclaw", "openclaw.json");
144+
145+
try {
146+
mkdirSync(path.dirname(configPath), { recursive: true });
147+
writeFileSync(
148+
configPath,
149+
`DO_NOT_DUMP_OLD_JSON${"x".repeat(2 * 1024 * 1024)}\nrecent json tail`,
150+
"utf8",
151+
);
152+
153+
const result = runAssertion(home, ["configure-mock-model", "18080"]);
154+
155+
expect(result.status).not.toBe(0);
156+
expect(result.stderr).toContain("JSON artifact exceeded");
157+
expect(result.stderr).toContain("recent json tail");
158+
expect(result.stderr).not.toContain("DO_NOT_DUMP_OLD_JSON");
159+
expect(result.stderr.length).toBeLessThan(80 * 1024);
160+
} finally {
161+
rmSync(root, { force: true, recursive: true });
162+
}
163+
});
164+
140165
it("fails when uninstall leaves the managed plugin directory behind", () => {
141166
const root = mkdtempSync(path.join(tmpdir(), "openclaw-release-user-assertions-"));
142167
const home = path.join(root, "home");

0 commit comments

Comments
 (0)