| 1 | // Fixture for DevCommand URL-extraction tests. Writes its PID + marker to |
| 2 | // PID_FILE (so the test can stop the process if needed), then prints whatever |
| 3 | // is in `URL_LINE` to stdout/stderr and stays alive. |
| 4 | // |
| 5 | // `URL_LINE` -> printed verbatim to stdout (can include ANSI escapes). |
| 6 | // `URL_STREAM` -> "stdout" (default) or "stderr". |
| 7 | // `URL_DELAY_MS` -> how long to wait before printing (default 0). Lets the |
| 8 | // test exercise extraction that happens after reconcile starts awaiting. |
| 9 | // `URL_LINE_2` / `URL_STREAM_2` / `URL_DELAY_2_MS` -> an optional second line |
| 10 | // printed independently. Lets a test print an unrelated URL first and the |
| 11 | // real dev-server URL later (issue #695). |
| 12 | const fs = require("node:fs"); |
| 13 | |
| 14 | const pidFile = process.env.PID_FILE; |
| 15 | const marker = process.env.MARKER ?? "default"; |
| 16 | |
| 17 | if (!pidFile) { |
| 18 | console.error("url-server.cjs: PID_FILE env var is required"); |
| 19 | process.exit(1); |
| 20 | } |
| 21 | |
| 22 | fs.writeFileSync(pidFile, JSON.stringify({ pid: process.pid, marker })); |
| 23 | |
| 24 | const printLine = (line, streamEnv, delayEnv) => { |
| 25 | if (!line) return; |
| 26 | const stream = process.env[streamEnv] === "stderr" ? "stderr" : "stdout"; |
| 27 | const delayMs = Number(process.env[delayEnv] ?? 0); |
| 28 | setTimeout(() => { |
| 29 | process[stream].write(`${line}\n`); |
| 30 | }, delayMs); |
| 31 | }; |
| 32 | |
| 33 | printLine(process.env.URL_LINE, "URL_STREAM", "URL_DELAY_MS"); |
| 34 | printLine(process.env.URL_LINE_2, "URL_STREAM_2", "URL_DELAY_2_MS"); |
| 35 | |
| 36 | setInterval(() => {}, 60_000); |