The JUnit report said failures="1" and put the residue list into every failed testcase, and three scripts reused a fixed .tmp path without cleanup on error. A shared renderer counts failures and records each check's cause (command and exit code, or its own findings); every script uses mkdtemp and finally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
import {
|
|
mkdir,
|
|
readFile,
|
|
rm,
|
|
writeFile,
|
|
} from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
createRemovalFixtureRoot,
|
|
filesBelow,
|
|
prepareRemovalFixture,
|
|
pruneRemovalFixtureCiContract,
|
|
pruneScriptOrchestration,
|
|
regenerateRemovalFixtureWorkflow,
|
|
renderRemovalJunit,
|
|
requireRemovalFixtureEnvironment,
|
|
runRemovalFixtureCheck,
|
|
type RemovalCheck,
|
|
} from "./lib/removal-fixture.ts";
|
|
|
|
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
|
const fixtureRoot = await createRemovalFixtureRoot("optional-recipe-removal");
|
|
|
|
function check(name: string, script: string): RemovalCheck {
|
|
return runRemovalFixtureCheck(name, fixtureRoot, pnpmCli, script);
|
|
}
|
|
|
|
let checks: RemovalCheck[];
|
|
try {
|
|
await prepareRemovalFixture(fixtureRoot);
|
|
for (const rootOnlyTest of [
|
|
"tests/unit/ci-workflow-generation.test.ts",
|
|
"tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap",
|
|
]) {
|
|
await rm(path.join(fixtureRoot, rootOnlyTest), { force: true });
|
|
}
|
|
await rm(path.join(fixtureRoot, "recipes"), { recursive: true, force: true });
|
|
await rm(path.join(fixtureRoot, "tests/recipes"), {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
|
|
const removedCiScripts = new Set([
|
|
"check:types:recipes",
|
|
"test:recipes",
|
|
"check:optional-recipes",
|
|
"check:optional-recipes:source",
|
|
"check:optional-recipe-fixtures",
|
|
"test:optional-recipe-removal",
|
|
]);
|
|
const fixturePackagePath = path.join(fixtureRoot, "package.json");
|
|
const fixturePackage = JSON.parse(await readFile(fixturePackagePath, "utf8")) as {
|
|
scripts: Record<string, string>;
|
|
};
|
|
pruneScriptOrchestration(fixturePackage.scripts, "check:types", removedCiScripts);
|
|
pruneScriptOrchestration(fixturePackage.scripts, "test:all", removedCiScripts);
|
|
await writeFile(fixturePackagePath, `${JSON.stringify(fixturePackage, null, 2)}\n`);
|
|
await pruneRemovalFixtureCiContract({
|
|
root: fixtureRoot,
|
|
removedScripts: removedCiScripts,
|
|
removedEvidencePathFragments: [
|
|
"optional-recipes",
|
|
"optional-recipe-fixtures",
|
|
"optional-recipe-removal",
|
|
],
|
|
});
|
|
await regenerateRemovalFixtureWorkflow(fixtureRoot);
|
|
|
|
checks = [
|
|
check("typecheck", "check:types"),
|
|
check("architecture", "check:architecture"),
|
|
check("test", "test:all"),
|
|
check("build", "build"),
|
|
check("ci-contract", "check:ci"),
|
|
];
|
|
const residue: string[] = [];
|
|
for (const file of await filesBelow(path.join(fixtureRoot, "dist")).catch(() => [])) {
|
|
if (!/\.(?:js|css|html|json)$/.test(file)) continue;
|
|
const content = await readFile(file, "utf8");
|
|
if (content.includes("frontend-optional-recipe-must-not-reach-production")) {
|
|
residue.push(path.relative(fixtureRoot, file));
|
|
}
|
|
}
|
|
checks.push(
|
|
residue.length === 0
|
|
? { name: "bundle-residue", passed: true }
|
|
: { name: "bundle-residue", passed: false, failure: `residue: ${residue.join(", ")}` },
|
|
);
|
|
} finally {
|
|
await rm(fixtureRoot, { recursive: true, force: true });
|
|
}
|
|
const failed = checks.filter((entry) => !entry.passed);
|
|
await mkdir("artifacts/tests", { recursive: true });
|
|
await writeFile(
|
|
"artifacts/tests/optional-recipe-removal.xml",
|
|
renderRemovalJunit("optional-recipe-removal", checks),
|
|
);
|
|
if (failed.length > 0) {
|
|
process.stderr.write(
|
|
`Optional recipe removal failed: ${failed.map((entry) => entry.name).join(", ")}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Optional recipe removal: PASS (${checks.length} base checks)\n`,
|
|
);
|