mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 10:27:42 +00:00
* fix(setup): use native Copilot configuration for VS Code * fix(setup): preserve the legacy VS Code updater contract * docs: clarify Copilot doctor and uninstall commands * test(setup): check the configured client in BOM round trips * test(ci): publish Pascal compiler readiness atomically --------- Co-authored-by: Abotboot <173614984+Abotboot@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
143 lines
4.8 KiB
TypeScript
143 lines
4.8 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
import {
|
|
chmod,
|
|
readFile,
|
|
readdir,
|
|
realpath,
|
|
rm,
|
|
symlink,
|
|
writeFile,
|
|
} from "node:fs/promises";
|
|
import { basename, join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
import { createCanonicalTemporaryDirectory } from "../../../scripts/lib/canonical-temporary-directory.mjs";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
it("uses the canonical spelling for a verifier directory allocated through a symlink", async () => {
|
|
const root = await createTestTempDirectory("rea-pascal-verifier-path-");
|
|
const alias = join(root, "alias");
|
|
await symlink(root, alias, process.platform === "win32" ? "junction" : "dir");
|
|
const allocated = await createCanonicalTemporaryDirectory(
|
|
"rea-pascal-calls-",
|
|
alias,
|
|
);
|
|
try {
|
|
expect(allocated.path).toBe(await realpath(allocated.allocatedPath));
|
|
expect(allocated.path).not.toBe(
|
|
join(alias, basename(allocated.allocatedPath)),
|
|
);
|
|
} finally {
|
|
await rm(allocated.allocatedPath, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it.skipIf(process.platform !== "darwin")(
|
|
"forwards verifier SIGTERM to the owned compiler group and removes its temporary directory",
|
|
async () => {
|
|
const root = await createTestTempDirectory("rea-pascal-verifier-cancel-");
|
|
const fakeCompiler = join(root, "fake-fpc");
|
|
const pidFile = join(root, "compiler-pids.txt");
|
|
const readCompilerPids = async (): Promise<number[]> => {
|
|
const pids = (await readFile(pidFile, "utf8"))
|
|
.trim()
|
|
.split(/\s+/u)
|
|
.map(Number);
|
|
if (
|
|
pids.length !== 2 ||
|
|
pids.some((pid) => !Number.isSafeInteger(pid) || pid <= 0)
|
|
)
|
|
throw new Error("Expected two positive compiler process IDs");
|
|
return pids;
|
|
};
|
|
await writeFile(
|
|
fakeCompiler,
|
|
[
|
|
"#!/usr/bin/env node",
|
|
'import { spawn } from "node:child_process";',
|
|
'import { once } from "node:events";',
|
|
'import { renameSync, writeFileSync } from "node:fs";',
|
|
'const child = spawn(process.execPath, ["-e", "setInterval(() => undefined, 1000)"], { stdio: "ignore" });',
|
|
'await once(child, "spawn");',
|
|
"const receipt = process.env.REA_VERIFY_TEST_PID_FILE;",
|
|
'const staging = receipt + ".tmp";',
|
|
'writeFileSync(staging, process.pid + " " + child.pid + "\\n");',
|
|
"renameSync(staging, receipt);",
|
|
"await new Promise(() => undefined);",
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
await chmod(fakeCompiler, 0o700);
|
|
const verifier = spawn(
|
|
process.execPath,
|
|
["scripts/verify-native-pascal-calls.mjs"],
|
|
{
|
|
cwd: process.cwd(),
|
|
env: {
|
|
...process.env,
|
|
TMPDIR: root,
|
|
REA_VERIFY_FPC_COMMAND: fakeCompiler,
|
|
REA_VERIFY_TEST_PID_FILE: pidFile,
|
|
},
|
|
stdio: "ignore",
|
|
},
|
|
);
|
|
try {
|
|
const deadline = Date.now() + 10_000;
|
|
let pids: number[] | undefined;
|
|
while (Date.now() < deadline) {
|
|
try {
|
|
pids = await readCompilerPids();
|
|
break;
|
|
} catch (cause: unknown) {
|
|
if ((cause as NodeJS.ErrnoException).code !== "ENOENT") throw cause;
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
}
|
|
}
|
|
if (pids === undefined)
|
|
throw new Error("Timed out waiting for the fake compiler to start");
|
|
verifier.kill("SIGTERM");
|
|
const result = await new Promise<{
|
|
code: number | null;
|
|
signal: NodeJS.Signals | null;
|
|
}>((resolve, reject) => {
|
|
verifier.once("error", reject);
|
|
verifier.once("close", (code, signal) => resolve({ code, signal }));
|
|
});
|
|
expect(result).toEqual({ code: 143, signal: null });
|
|
for (const pid of pids) expect(() => process.kill(pid, 0)).toThrow();
|
|
expect(
|
|
(await readdir(root)).filter((name) =>
|
|
name.startsWith("rea-pascal-calls-"),
|
|
),
|
|
).toEqual([]);
|
|
} finally {
|
|
if (verifier.exitCode === null && verifier.signalCode === null) {
|
|
verifier.kill("SIGTERM");
|
|
await new Promise((resolve) => {
|
|
const timer = setTimeout(() => {
|
|
verifier.kill("SIGKILL");
|
|
resolve(undefined);
|
|
}, 1_000);
|
|
verifier.once("close", () => {
|
|
clearTimeout(timer);
|
|
resolve(undefined);
|
|
});
|
|
});
|
|
}
|
|
try {
|
|
const recorded = await readCompilerPids();
|
|
for (const pid of recorded) {
|
|
try {
|
|
process.kill(pid, "SIGKILL");
|
|
} catch {
|
|
// The owned compiler group already exited.
|
|
}
|
|
}
|
|
} catch (cause: unknown) {
|
|
if ((cause as NodeJS.ErrnoException).code !== "ENOENT") throw cause;
|
|
}
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
},
|
|
);
|