55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterEach, expect, it } from "vitest";
|
|
|
|
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
|
|
import {
|
|
pruneRemovalFixtureCiContract,
|
|
} from "../../scripts/lib/removal-fixture.ts";
|
|
|
|
const temporaryRoots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
it("prunes removed command and evidence references from a reduced CI contract", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "removal-fixture-contract-"));
|
|
temporaryRoots.push(root);
|
|
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
|
await writeFile(path.join(root, "config/ci/gates.json"), await readFile("config/ci/gates.json"));
|
|
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
|
|
|
await pruneRemovalFixtureCiContract({
|
|
root,
|
|
removedScripts: new Set(["test:reference-feature"]),
|
|
removedEvidencePathFragments: ["reference-feature.xml"],
|
|
});
|
|
|
|
const contract = await loadCiGateContract(root, { mode: "removal-fixture" });
|
|
expect(contract.commands.some(({ script }) => script === "test:reference-feature")).toBe(false);
|
|
expect(contract.artifacts.some(({ path }) => path.includes("reference-feature.xml"))).toBe(false);
|
|
expect(contract.gates.some(({ commandIds }) => commandIds.includes("test-reference-feature"))).toBe(false);
|
|
expect(contract.gates.some(({ evidenceArtifactIds }) =>
|
|
evidenceArtifactIds.includes("artifact-artifacts-tests-reference-feature-xml")
|
|
)).toBe(false);
|
|
});
|
|
|
|
it("rejects pruning that leaves a reduced gate without commands", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "removal-fixture-empty-gate-"));
|
|
temporaryRoots.push(root);
|
|
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
|
await writeFile(path.join(root, "config/ci/gates.json"), await readFile("config/ci/gates.json"));
|
|
await writeFile(path.join(root, "package.json"), await readFile("package.json"));
|
|
|
|
await expect(pruneRemovalFixtureCiContract({
|
|
root,
|
|
removedScripts: new Set(["test:runtime-schema"]),
|
|
removedEvidencePathFragments: ["runtime-schema.xml"],
|
|
})).rejects.toThrow(/commandIds|too small|at least 1/i);
|
|
});
|