// Test participant: publishes an owner record and stays alive until the done // file appears, without ever clearing the lock. By default it writes the // round-five shape, {pid, start, at} with no boot id, as an already-running // connector from before the upgrade would have. Optional third and fourth // arguments override the recorded start and boot ("-" omits the field, "real" // records the genuine value), so tests can publish corrupt identity metadata // under a live pid. Prints "legacy-published" on stdout. import { existsSync, mkdirSync, writeFileSync, renameSync } from "node:fs"; import { join } from "node:path"; import { processStart, bootId } from "../src/journal.mjs"; const [dir, done, startArg = "real", bootArg = "-"] = process.argv.slice(2); const rec = { pid: process.pid, at: new Date().toISOString() }; if (startArg !== "-") rec.start = startArg === "real" ? processStart(process.pid) : startArg; if (bootArg !== "-") rec.boot = bootArg === "real" ? bootId() : bootArg; const lock = join(dir, "run.lock"); mkdirSync(lock, { mode: 0o700 }); const tmp = join(lock, "owner.json.tmp"); writeFileSync(tmp, JSON.stringify(rec) + "\n", { mode: 0o600 }); renameSync(tmp, join(lock, "owner.json")); process.stdout.write("legacy-published\n"); const deadline = Date.now() + 10_000; while (!existsSync(done)) { if (Date.now() > deadline) process.exit(2); Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 2); }