Skip to content

Commit a0358bb

Browse files
committed
test(release): wait for config reload log proof
1 parent d93c597 commit a0358bb

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
11
import fs from "node:fs";
22

3-
const log = fs.readFileSync("/tmp/config-reload-e2e.log", "utf8");
4-
const reloadLines = log
5-
.split("\n")
6-
.filter((line) => line.includes("config change detected; evaluating reload"));
7-
const restartLines = log
8-
.split("\n")
9-
.filter((line) => line.includes("config change requires gateway restart"));
3+
const logPath = process.env.OPENCLAW_CONFIG_RELOAD_LOG_PATH ?? "/tmp/config-reload-e2e.log";
4+
const deadlineMs = Date.now() + Number(process.env.OPENCLAW_CONFIG_RELOAD_LOG_TIMEOUT_MS ?? 30_000);
105

11-
if (restartLines.length > 0) {
12-
console.error(log.split("\n").slice(-160).join("\n"));
6+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7+
8+
function readLog() {
9+
return fs.readFileSync(logPath, "utf8");
10+
}
11+
12+
function inspectLog(log) {
13+
const lines = log.split("\n");
14+
const reloadLines = lines.filter((line) =>
15+
line.includes("config change detected; evaluating reload"),
16+
);
17+
const restartLines = lines.filter((line) =>
18+
line.includes("config change requires gateway restart"),
19+
);
20+
return { lines, reloadLines, restartLines };
21+
}
22+
23+
let log = "";
24+
let result = { lines: [], reloadLines: [], restartLines: [] };
25+
26+
while (Date.now() < deadlineMs) {
27+
log = readLog();
28+
result = inspectLog(log);
29+
if (result.restartLines.length > 0 || result.reloadLines.length > 0) {
30+
break;
31+
}
32+
await sleep(500);
33+
}
34+
35+
if (result.restartLines.length > 0) {
36+
console.error(result.lines.slice(-160).join("\n"));
1337
throw new Error("unexpected restart-required reload line found");
1438
}
15-
for (const line of reloadLines) {
39+
for (const line of result.reloadLines) {
1640
for (const needle of ["gateway.auth.token", "plugins.entries.firecrawl.config.webFetch"]) {
1741
if (line.includes(needle)) {
18-
console.error(log.split("\n").slice(-160).join("\n"));
42+
console.error(result.lines.slice(-160).join("\n"));
1943
throw new Error(`runtime-only path appeared in reload diff: ${needle}`);
2044
}
2145
}
2246
}
23-
if (reloadLines.length === 0) {
24-
console.error(log.split("\n").slice(-160).join("\n"));
47+
if (result.reloadLines.length === 0) {
48+
console.error(result.lines.slice(-160).join("\n"));
2549
throw new Error("expected config reload detection log after metadata write");
2650
}

0 commit comments

Comments
 (0)