19 lines
1.1 KiB
JavaScript
19 lines
1.1 KiB
JavaScript
// A stand-in harness turn for the clear context tests (row 271, #1776).
|
|
// session-adapter.mjs's turn, plus what the run sees of the pid namespace:
|
|
// the numeric entries of /proc and pid 1's argv, so a test can tell that the
|
|
// session runs in its own namespace (N6).
|
|
|
|
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const request = process.env.MOSAIC_REQUEST ?? "";
|
|
const body = request.match(/^Message [^\n]*:\n\n([\s\S]*)$/m)?.[1] ?? "";
|
|
const historyFile = join(process.env.MOSAIC_SESSION_DIR, "history");
|
|
const before = existsSync(historyFile) ? readFileSync(historyFile, "utf8").split("\n").filter(Boolean) : [];
|
|
const cwd = process.cwd();
|
|
const pids = readdirSync("/proc").filter((n) => /^\d+$/.test(n)).map(Number).sort((a, b) => a - b);
|
|
const pid1 = readFileSync("/proc/1/cmdline", "utf8").split("\0").filter(Boolean);
|
|
appendFileSync(historyFile, `${body}\n`);
|
|
process.stdout.write(`THREAD ${JSON.stringify({ body, before, cwd, pids, pid1 })}\n`);
|
|
writeFileSync(process.env.MOSAIC_TURN_MARKER, "done\n");
|