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>
168 lines
5.0 KiB
TypeScript
168 lines
5.0 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("browser-file-storage-runtime-removal");
|
|
const runtimePaths = [
|
|
"src/application/ports/browser-file-storage",
|
|
"src/application/ports/browser-transfer",
|
|
"src/adapters/browser-file-storage",
|
|
"src/adapters/browser-files",
|
|
"src/adapters/browser-transfer",
|
|
"src/adapters/cache-storage",
|
|
"src/adapters/storage/indexeddb",
|
|
"src/adapters/storage/opfs",
|
|
"tests/browser-capabilities",
|
|
"tests/fixtures/browser-file-storage-boundaries",
|
|
// The composition example of this runtime goes with it.
|
|
"recipes/frontend-capabilities/indexeddb-feature-capability.ts",
|
|
] as const;
|
|
const runtimeSourceRoots = runtimePaths.filter((entry) =>
|
|
entry.startsWith("src/"),
|
|
);
|
|
const removedScripts = new Set([
|
|
"test:browser-capabilities",
|
|
"verify:browser-capability-evidence",
|
|
"check:browser-file-storage-boundaries",
|
|
"test:browser-file-storage-removal",
|
|
]);
|
|
const removedEvidencePathFragments = [
|
|
"browser-capabilities",
|
|
"browser-file-storage-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 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 browserFileRuntimeRecipeIds = new Set([
|
|
"offline-indexeddb",
|
|
"service-worker-pwa",
|
|
"file-transfer",
|
|
]);
|
|
let removedRuntimeEntries = 0;
|
|
for (const recipe of catalog.recipes) {
|
|
if (
|
|
typeof recipe.id !== "string" ||
|
|
!browserFileRuntimeRecipeIds.has(recipe.id) ||
|
|
!Object.hasOwn(recipe, "referenceRuntime")
|
|
) {
|
|
continue;
|
|
}
|
|
delete recipe.referenceRuntime;
|
|
removedRuntimeEntries += 1;
|
|
}
|
|
if (removedRuntimeEntries !== 3) {
|
|
throw new Error(
|
|
`Expected three reference runtime catalog entries, removed ${removedRuntimeEntries}`,
|
|
);
|
|
}
|
|
await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`);
|
|
|
|
await rm(path.join(fixtureRoot, "playwright.capabilities.config.ts"), {
|
|
force: true,
|
|
});
|
|
await rm(
|
|
path.join(fixtureRoot, "scripts/check-browser-file-storage-boundaries.ts"),
|
|
{ force: true },
|
|
);
|
|
await rm(
|
|
path.join(fixtureRoot, "scripts/verify-browser-capability-evidence.ts"),
|
|
{ force: true },
|
|
);
|
|
await rm(
|
|
path.join(fixtureRoot, "scripts/test-browser-file-storage-runtime-removal.ts"),
|
|
{ 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,
|
|
removedEvidencePathFragments,
|
|
});
|
|
await regenerateRemovalFixtureWorkflow(fixtureRoot);
|
|
await assertNoRuntimeImports(
|
|
fixtureRoot,
|
|
runtimeSourceRoots,
|
|
"browser file/storage",
|
|
);
|
|
|
|
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/browser-file-storage-runtime-removal.xml",
|
|
renderRemovalJunit("browser-file-storage-runtime-removal", checks),
|
|
);
|
|
if (failed.length > 0) {
|
|
process.stderr.write(
|
|
`Browser file/storage runtime removal failed: ${failed.map((entry) => entry.name).join(", ")}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Browser file/storage runtime removal: PASS (${checks.length} base checks, ${removedRuntimeTests} runtime-dependent tests removed by import graph)\n`,
|
|
);
|