Files
clean-architecture-frontend…/scripts/test-realtime-runtime-removal.ts
T
DongHyeonkaandClaude Opus 5.5 96391dc69a fix(scripts): report each removal check's own failure and isolate fixtures (14-08)
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>
2026-09-25 23:19:09 +09:00

151 lines
4.6 KiB
TypeScript

import {
mkdir,
readFile,
rm,
writeFile,
} from "node:fs/promises";
import path from "node:path";
import {
assertNoRuntimeImports,
createRemovalFixtureRoot,
prepareRemovalFixture,
pruneRemovalFixtureCiContract,
regenerateRemovalFixtureWorkflow,
removeRuntimeDependentTests,
renderRemovalJunit,
requireRemovalFixtureEnvironment,
runRemovalFixtureCheck,
type RemovalCheck,
} from "./lib/removal-fixture.ts";
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
const fixtureRoot = await createRemovalFixtureRoot("realtime-runtime-removal");
const runtimePaths = [
"src/application/ports/realtime",
"src/application/ports/out/web-push-control.ts",
"src/application/policies/bounded-polling.ts",
"src/contracts/realtime-events.ts",
"src/contracts/realtime-streams.ts",
"src/contracts/web-push.ts",
"src/adapters/realtime",
"src/adapters/web-push",
"tests/fixtures/realtime-boundaries",
] as const;
const runtimeSourceRoots = runtimePaths.filter((entry) =>
entry.startsWith("src/"),
);
const runtimeScripts = [
"check:realtime-boundaries",
"check:realtime-boundaries:fixture",
"test:realtime-removal",
] as const;
const removedEvidencePathFragments = [
"realtime-boundaries",
"realtime-runtime-removal",
] as const;
function check(name: string, script: string): RemovalCheck {
return runRemovalFixtureCheck(name, fixtureRoot, pnpmCli, script);
}
let checks: RemovalCheck[];
let removedRuntimeTests: number;
try {
await prepareRemovalFixture(fixtureRoot);
removedRuntimeTests =
await removeRuntimeDependentTests(fixtureRoot, runtimeSourceRoots);
for (const runtimePath of runtimePaths) {
await rm(path.join(fixtureRoot, runtimePath), {
recursive: true,
force: true,
});
}
const outputPortsIndexPath = path.join(
fixtureRoot,
"src/application/ports/out/index.ts",
);
const outputPortsIndex = await readFile(outputPortsIndexPath, "utf8");
await writeFile(
outputPortsIndexPath,
outputPortsIndex.replace(
'export type { WebPushControlPort } from "./web-push-control.ts";\n',
"",
),
);
const catalogPath = path.join(
fixtureRoot,
"config/recipes/frontend-capability-recipes.json",
);
const catalog = JSON.parse(await readFile(catalogPath, "utf8")) as {
recipes: Array<Record<string, unknown>>;
};
const realtimeRecipe = catalog.recipes.find(
(recipe) => recipe.id === "realtime",
);
if (!realtimeRecipe || !Object.hasOwn(realtimeRecipe, "referenceRuntime")) {
throw new Error("Expected realtime reference runtime catalog entry");
}
delete realtimeRecipe.referenceRuntime;
await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`);
for (const scriptPath of [
"scripts/check-realtime-boundaries.ts",
"scripts/check-realtime-boundary-fixtures.ts",
"scripts/lib/realtime-boundaries.ts",
"scripts/test-realtime-runtime-removal.ts",
]) {
await rm(path.join(fixtureRoot, scriptPath), { force: true });
}
// The root snapshot locks the full repository inventory. This removal fixture
// validates its smaller registry through check:ci and its regenerated workflow.
await rm(
path.join(fixtureRoot, "tests/unit/ci-workflow-generation.test.ts"),
{ force: true },
);
await rm(
path.join(
fixtureRoot,
"tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap",
),
{ force: true },
);
await pruneRemovalFixtureCiContract({
root: fixtureRoot,
removedScripts: new Set<string>(runtimeScripts),
removedEvidencePathFragments,
});
await regenerateRemovalFixtureWorkflow(fixtureRoot);
await assertNoRuntimeImports(fixtureRoot, runtimeSourceRoots, "realtime");
checks = [
check("typecheck", "check:types"),
check("lint", "lint"),
check("architecture", "check:architecture"),
check("test", "test:all"),
check("build", "build"),
check("optional-catalog", "check:optional-recipes:source"),
check("ci-contract", "check:ci"),
];
} 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/realtime-runtime-removal.xml",
renderRemovalJunit("realtime-runtime-removal", checks),
);
if (failed.length > 0) {
process.stderr.write(
`Realtime runtime removal failed: ${failed.map((entry) => entry.name).join(", ")}\n`,
);
process.exit(1);
}
process.stdout.write(
`Realtime runtime removal: PASS (${checks.length} base checks, ${removedRuntimeTests} runtime-dependent tests removed by import graph)\n`,
);