import { mkdir, rm, writeFile } from "node:fs/promises"; import { createRemovalFixtureRoot, prepareRemovalFixture, REMOVAL_FIXTURE_COPY_TARGETS, renderRemovalJunit, requireRemovalFixtureEnvironment, runRemovalFixtureCheck, sealRemovalFixtureRepository, type RemovalCheck, } from "./lib/removal-fixture.ts"; /** * U7. A feature from `create:feature` passes the merge gates without an edit * and breaks no other test. A copy of the repository, sample feature * included, gets one generated feature and then runs the gates. * test:sample-removal repeats the generation after deleting the sample * (decision 4), which proves the command needs nothing from it. */ const FEATURE_ID = "scaffold-feature"; const REPORT = "artifacts/tests/feature-scaffold.xml"; const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath"); const fixtureRoot = await createRemovalFixtureRoot("feature-scaffold"); function check(name: string, script: string, extra: readonly string[] = []): RemovalCheck { return runRemovalFixtureCheck(name, fixtureRoot, pnpmCli, script, extra); } try { // verify:documentation and the documentation tests read these. await prepareRemovalFixture(fixtureRoot, [ ...REMOVAL_FIXTURE_COPY_TARGETS, "README.md", "CHANGELOG.md", "docs", ]); const created = check("create-feature", "create:feature", [FEATURE_ID]); const checks: RemovalCheck[] = [created]; if (created.passed) { // Commits the copy with the feature, as a project would: git-based // checks (git grep, git ls-files) then see the feature's files. sealRemovalFixtureRepository(fixtureRoot); checks.push( check("typecheck", "check:types"), check("lint", "lint"), check("architecture", "check:architecture"), check("registries", "check:registries"), check("i18n", "check:i18n"), check("design-system", "check:design-system"), check("diagnostics", "check:diagnostics"), check("documentation", "verify:documentation"), check("unit", "test:unit"), check("component", "test:component"), check("integration", "test:integration"), check("features", "exec", ["node", "scripts/run-vitest.ts", "run", "tests/features"]), check("coverage", "test:coverage"), check("ci-contract", "check:ci"), check("build", "build"), ); } const failed = checks.filter((entry) => !entry.passed); await mkdir("artifacts/tests", { recursive: true }); await writeFile(REPORT, renderRemovalJunit("feature-scaffold", checks)); if (failed.length > 0) { process.stderr.write( `feature scaffold failed:\n${failed .map((entry) => ` ${entry.name}: ${entry.failure ?? "failed"}`) .join("\n")}\n`, ); process.exitCode = 1; } else { process.stdout.write(`feature scaffold: PASS (${checks.length} checks)\n`); } } finally { await rm(fixtureRoot, { recursive: true, force: true }); }