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).
12const fs = require("node:fs");
13
14const pidFile = process.env.PID_FILE;
15const marker = process.env.MARKER ?? "default";
16
17if (!pidFile) {
18 console.error("url-server.cjs: PID_FILE env var is required");
19 process.exit(1);
20}
21
22fs.writeFileSync(pidFile, JSON.stringify({ pid: process.pid, marker }));
23
24const 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
33printLine(process.env.URL_LINE, "URL_STREAM", "URL_DELAY_MS");
34printLine(process.env.URL_LINE_2, "URL_STREAM_2", "URL_DELAY_2_MS");
35
36setInterval(() => {}, 60_000);