testRunningIsSaidAndReadBack
A process that says it's running is read back with what it said, its process and when it started; a record whose process is gone is cleared away, and what isn't a whole record isn't read.
import { liveRunning, runDir, sayRunning } from "#codebase/tcmts/cli/running"; import assert from "node:assert/strict"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; export const testRunningIsSaidAndReadBack = () => { const root = fs.mkdtempSync(path.join(os.tmpdir(), "tcm running ")); sayRunning(root, { command: "dev", app: "app.main", url: "http://127.0.0.1:5173/", branch: "main", }); fs.writeFileSync( path.join(runDir(root), "4206649.json"), JSON.stringify({ pid: 2 ** 22 + 12345, command: "start", started: 0, parent: 1, args: [] }), ); fs.writeFileSync(path.join(runDir(root), `${process.pid}.json.1234.part`), "{"); const live = liveRunning(root); assert.equal(live.length, 1); const [me] = live; assert.equal(me!.pid, process.pid); assert.equal(me!.command, "dev"); assert.equal(me!.app, "app.main"); assert.equal(me!.url, "http://127.0.0.1:5173/"); assert.equal(me!.branch, "main"); assert.equal(me!.parent, process.ppid); assert.ok(me!.started <= Date.now()); assert.deepEqual( fs.readdirSync(runDir(root)).sort(), [`${process.pid}.json`, `${process.pid}.json.1234.part`].sort(), ); fs.rmSync(root, { recursive: true, force: true }); }