|
1 | 1 | import fs from "node:fs"; |
2 | 2 |
|
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); |
10 | 5 |
|
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")); |
13 | 37 | throw new Error("unexpected restart-required reload line found"); |
14 | 38 | } |
15 | | -for (const line of reloadLines) { |
| 39 | +for (const line of result.reloadLines) { |
16 | 40 | for (const needle of ["gateway.auth.token", "plugins.entries.firecrawl.config.webFetch"]) { |
17 | 41 | if (line.includes(needle)) { |
18 | | - console.error(log.split("\n").slice(-160).join("\n")); |
| 42 | + console.error(result.lines.slice(-160).join("\n")); |
19 | 43 | throw new Error(`runtime-only path appeared in reload diff: ${needle}`); |
20 | 44 | } |
21 | 45 | } |
22 | 46 | } |
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")); |
25 | 49 | throw new Error("expected config reload detection log after metadata write"); |
26 | 50 | } |
0 commit comments