Files
clean-architecture-frontend…/scripts/test-feature-scaffold.ts
T
DongHyeonka b433286eb0 fix(scaffold): 기능 생성 드릴이 로컬에서도 release candidate를 만든다
문제
e1b4e28 뒤 test:feature-scaffold는 merge 단계 명령을 모두 돈다. 실제 실행
(snapshot b6bfc9b, CI env 없음)에서 검사 75개 중 FE-GATE-013의 두 개만
실패했다. build:release-candidate가 build의 commitSha를 source.revision으로
기록하는데, VITE_COMMIT_SHA가 없으면 commitSha가 "local"이라 schema(40·64자리
16진수)가 거부한다. verify:local-evidence는 그 결과를 읽어 따라 실패했다.
CI workflow는 VITE_COMMIT_SHA를 전체 env로 주므로 CI에서는 나지 않는다.

고른 방법
- VITE_COMMIT_SHA가 비었을 때만 드릴이 fixture의 봉인 commit(git rev-parse
  HEAD)을 넣는다. CI 값은 그대로 둔다. test:system의 provider fixture도 같은
  방법으로 commit을 준다.
- 버린 대안: build:release-candidate·verify:local-evidence를 제외 목록에
  넣기. 생성 기능 파일이 후보의 추적 파일 목록과 공급망 증거에 들어가는지를
  보지 못한다.

위험·한계
- 로컬 실행에서 빌드 산출물의 commitSha가 "local" 대신 fixture commit이 된다.
  fixture 안에서만이다.

검증
- 수정 전 드릴 실행: create-feature, merge 명령 73개(음성 fixture 포함),
  feature-removal 통과. 실패는 위 두 개뿐(866초, load 10~25).
- 수정 뒤 eslint·tsc 통과, feature-scaffold-drill 6건 통과. 드릴 재실행 결과는
  이 커밋 메시지에 적지 않았다(공유 잠금).

Refs: docs/reviews/2026-11-03-maturity-review/12-guardrails-ci.md 12-02
2026-11-04 22:23:31 +09:00

92 lines
3.7 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdir, rm, writeFile } from "node:fs/promises";
import { loadCiGateContract } from "./contracts/ci-gates.ts";
import {
runScaffoldDrillCommand,
scaffoldDrillCommands,
} from "./lib/feature-scaffold-drill.ts";
import {
createRemovalFixtureRoot,
prepareRemovalFixture,
REMOVAL_FIXTURE_COPY_TARGETS,
REMOVAL_FIXTURE_DOCUMENT_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 merge stage of its
* config/ci/gates.json: every command except those
* SCAFFOLD_DRILL_EXCLUDED_SCRIPTS names with a reason (the browser gates,
* test:system, the install check and the removal drills). 1103/12-02: this
* used to be a hand-kept list of 15 commands.
*
* 1103/16-02. The generated feature is then removed again with
* `test:sample-removal -- --feature=<id>`, the path the manual tells every
* product feature to take and that no gate ran.
*
* 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 fixtureCommit(root: string): string {
const head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" });
if (head.status !== 0) throw new Error(`feature scaffold fixture has no commit: ${head.stderr}`);
return head.stdout.trim();
}
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,
...REMOVAL_FIXTURE_DOCUMENT_TARGETS,
]);
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);
// build:release-candidate records the build's commit and refuses one that
// is not a commit ID. CI sets VITE_COMMIT_SHA for the whole workflow; a
// local run gets the copy's own sealed commit instead of "local".
if (!process.env["VITE_COMMIT_SHA"]?.trim()) {
process.env["VITE_COMMIT_SHA"] = fixtureCommit(fixtureRoot);
}
for (const command of scaffoldDrillCommands(await loadCiGateContract(fixtureRoot))) {
checks.push(runScaffoldDrillCommand(command, fixtureRoot, pnpmCli));
}
checks.push(check("feature-removal", "test:sample-removal", ["--", `--feature=${FEATURE_ID}`]));
}
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 });
}