import { spawnSync } from "node:child_process"; import { mkdtemp, readFile, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { REMOVABLE_TEMPLATE_FEATURES } from "../../scripts/lib/removable-template-features.ts"; import { childProcessTimeout } from "../helpers/child-process-timeout.ts"; // 09-07 (D-10). The removal gate takes the feature to remove as an argument // instead of hard-coding the sample; an id no feature declares stops it before // any fixture is built. describe("feature removal argument", { timeout: childProcessTimeout(1_348) }, () => { it("refuses a feature id that no installed feature declares", () => { const run = spawnSync( process.execPath, ["scripts/test-sample-removal.ts", "--feature=missing-feature"], { encoding: "utf8" }, ); expect(run.status).not.toBe(0); expect(run.stderr).toMatch( /No installed feature declares FEATURE_MODULE_ID "missing-feature"/u, ); }); // 2026-11-07. Without --feature (FE-GATE-020) the drill removes the listed // samples. The template lists none: the run says it skipped, and its report // counts a skipped case, not a pass. it("reports the drill as skipped when no sample is listed", async () => { // A project that lists a sample runs the whole drill in FE-GATE-020. if (REMOVABLE_TEMPLATE_FEATURES.length > 0) return; const output = await mkdtemp(path.join(tmpdir(), "sample-removal-skip-")); try { const run = spawnSync(process.execPath, [path.resolve("scripts/test-sample-removal.ts")], { cwd: output, encoding: "utf8", }); expect(run.status, run.stderr).toBe(0); expect(run.stdout).toMatch(/^sample removal: SKIP /mu); expect(await readFile(path.join(output, "artifacts/tests/sample-removal.xml"), "utf8")).toMatch( /tests="1" failures="0" skipped="1">.*