문제: 프론트 PR 실행 p50이 17.7분으로 15분 목표를 넘고, 기능·scaffold 제거 드릴 FE-GATE-020이 PR 대부분(34건 중 25건)에서 돌아 약 6분을 차지한다. CI-X-0002 (다) 결정에 따라 FE-GATE-020을 merge 단계에서 main 단계로 옮긴다. 고른 방법과 버린 대안: - config/ci/gates.json, scripts/contracts/ci-gates.ts(expectedJobOwnership), scripts/lib/promotion-readiness.ts(MERGE_READY·MAIN_READY)에서 FE-GATE-020을 merge/merge_test에서 main/main_gate(FE-GATE-029 다음, FE-GATE-030 앞)로 옮기고 workflow와 스냅샷을 재생성한다. - scripts/lib/feature-scaffold-drill.ts는 되돌림 시 재귀를 막으려 자기 스크립트 (test:sample-removal·test:feature-scaffold)를 제외 목록에 남기되 merge 밖 stale 거절에서만 면제한다. 고른 드릴 명령 29개는 기존과 같다. - config/ci/pr-gate-selection.json의 accessibility-records·scaffold 줄에서 FE-GATE-020을 빼고, scaffold 줄은 되돌림과 계약 시험을 위해 남긴다. - 버린 대안: FE-GATE-020 전용 드릴 입력 목록(효과 미미·거짓 초록 위험), 제외 목록에서 자기 스크립트 삭제(되돌림 시 재귀·미사용 상수 발생). 위험·한계: - 기능·scaffold 드릴 회귀가 PR이 아니라 병합 뒤 main 빨강으로 드러나며, release·tag run과 RELEASE_READY도 FE-GATE-020을 요구하지 않는다. - .claude/skills/fe-structure/SKILL.md:53은 .claude/ 수정 금지 가드로 바꾸지 않았으며, 같은 안내는 docs/work/reference/gates.md에 반영했다. - 생성기·드릴·src/features·src/contexts 규칙을 바꾸는 PR은 scripts/verify.sh gate FE-GATE-020을 직접 돌린다. 검증: - C1 RED (트리 38592b2283d7): ci-workflow-generation rc=1, promotion-readiness rc=1 - C2 RED (트리 06a01260818a): feature-scaffold-drill rc=1 (outside the merge stage) - laptop-gate check:types, lint, verify:documentation, 단위 시험 7파일(538 passed) rc=0 - scripts/verify.sh docs rc=0, scripts/verify.sh hooks rc=0 (112 tests) Refs: CI-FE-0005
186 lines
8.3 KiB
TypeScript
186 lines
8.3 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
|
|
import type { CiGateContract } from "../contracts/ci-gates.ts";
|
|
import { classifyGateStepResult, type GateStepExpectation } from "./ci-step-result.ts";
|
|
import { FIXTURE_PNPM_ENVIRONMENT } from "./fixture-node-modules.ts";
|
|
import type { RemovalCheck } from "./removal-fixture.ts";
|
|
|
|
/**
|
|
* 1103/12-02. test:feature-scaffold proves that a feature from
|
|
* `create:feature` passes the merge gates. It ran a hand-kept list of 15
|
|
* commands while the merge stage has 88, so a template change that broke a
|
|
* generated feature in any other merge command passed FE-GATE-020.
|
|
*
|
|
* The drill now runs the merge stage of the copy's config/ci/gates.json, in
|
|
* stage order, each command once. A command added to the merge stage runs here
|
|
* unless this list names it, with the reason it cannot run in the drill.
|
|
*/
|
|
const BROWSER =
|
|
"needs Playwright browsers. FE-GATE-020 runs in a main job without them " +
|
|
"(main_gate installs none). The generated routes in the browser " +
|
|
"gates are reviewed as 1103/12-01 and 12-03.";
|
|
const DRILL =
|
|
"a removal drill copies the repository again. The drill runs the generated " +
|
|
"feature's own removal instead (feature-removal).";
|
|
/**
|
|
* FE-GATE-020's own drill scripts. Kept in SCAFFOLD_DRILL_EXCLUDED_SCRIPTS
|
|
* even while FE-GATE-020 runs in the main stage (CI-X-0002 (다) / CI-FE-0005)
|
|
* so reverting FE-GATE-020 back to merge cannot make the drill recurse into
|
|
* itself inside its fixture copy.
|
|
*/
|
|
export const SCAFFOLD_DRILL_SELF_SCRIPTS: readonly string[] = Object.freeze([
|
|
"test:sample-removal",
|
|
"test:feature-scaffold",
|
|
]);
|
|
/**
|
|
* The drill runs FE-GATE-005's test:coverage in the same copy, and its paths
|
|
* hold every path of these suites (tests/unit/removal-drill-test-paths.test.ts).
|
|
* Running them plain as well found nothing more and cost about 80 s a drill.
|
|
* tests/unit and tests/contract are not here: the merge stage runs them only in
|
|
* test:coverage (FE-4, scripts/lib/coverage-bundle-junit-reporter.ts).
|
|
*/
|
|
const COVERED =
|
|
"test:coverage runs the same test files in this copy " +
|
|
"(tests/unit/removal-drill-test-paths.test.ts checks the paths).";
|
|
export const SCAFFOLD_DRILL_COVERED_SUITES: readonly string[] = Object.freeze([
|
|
"test:runtime-schema",
|
|
"test:component",
|
|
"test:integration",
|
|
]);
|
|
/**
|
|
* What a removal drill runs next to test:coverage so that every test:all path
|
|
* still runs once in the copy (scripts/test-sample-removal.ts). The rest of
|
|
* test:all, check:release-coherence included, is inside coverage's paths.
|
|
*/
|
|
export const REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE: readonly string[] = Object.freeze([
|
|
"test:recipes",
|
|
]);
|
|
|
|
export const SCAFFOLD_DRILL_EXCLUDED_SCRIPTS: Readonly<Record<string, string>> = Object.freeze({
|
|
"verify:lockfile":
|
|
"runs pnpm install, which writes into the node_modules the copy links from " +
|
|
"the repository (scripts/lib/fixture-node-modules.ts).",
|
|
"test:e2e": BROWSER,
|
|
"test:browser-capabilities": BROWSER,
|
|
"verify:browser-capability-evidence": `reads the test:browser-capabilities results; ${BROWSER}`,
|
|
"test:storybook": BROWSER,
|
|
"test:visual": BROWSER,
|
|
"check:test-evidence:browser": `reads the browser gates' results; ${BROWSER}`,
|
|
"test:a11y": BROWSER,
|
|
"test:system":
|
|
"needs the CI runner's bubblewrap, systemd and cgroup v2 " +
|
|
"(scripts/check-system-test-prerequisites.ts). It tests the provider " +
|
|
"sandbox, which a feature does not reach.",
|
|
...Object.fromEntries(SCAFFOLD_DRILL_COVERED_SUITES.map((script) => [script, COVERED])),
|
|
"test:sample-removal": DRILL,
|
|
"test:feature-scaffold": "is this drill.",
|
|
});
|
|
|
|
export type ScaffoldDrillCommand = Readonly<{
|
|
/** `<gate>:<command id>`, the check's name in the drill report. */
|
|
name: string;
|
|
script: string;
|
|
args: readonly string[];
|
|
expectation: GateStepExpectation;
|
|
}>;
|
|
|
|
type ContractShape = Pick<CiGateContract, "commands" | "gates" | "stages">;
|
|
|
|
export function scaffoldDrillCommands(
|
|
contract: ContractShape,
|
|
excluded: Readonly<Record<string, string>> = SCAFFOLD_DRILL_EXCLUDED_SCRIPTS,
|
|
): readonly ScaffoldDrillCommand[] {
|
|
const merge = contract.stages.find(({ id }) => id === "merge");
|
|
if (!merge) throw new TypeError("the CI contract has no merge stage");
|
|
const commands = new Map(contract.commands.map((command) => [command.id, command]));
|
|
const mergeScripts = new Set<string>();
|
|
const seen = new Set<string>();
|
|
const selected: ScaffoldDrillCommand[] = [];
|
|
// A covered suite is left out only while the drill runs test:coverage. A
|
|
// copy whose merge stage lost it runs the suites plain again.
|
|
const runsCoverage = !Object.hasOwn(excluded, "test:coverage") && merge.gateIds.some((gateId) =>
|
|
contract.gates.find(({ id }) => id === gateId)?.commandIds.some((commandId) =>
|
|
commands.get(commandId)?.script === "test:coverage"));
|
|
const leftOut = (script: string) =>
|
|
Object.hasOwn(excluded, script) &&
|
|
(runsCoverage || !SCAFFOLD_DRILL_COVERED_SUITES.includes(script) || excluded[script] !== COVERED);
|
|
for (const gateId of merge.gateIds) {
|
|
const gate = contract.gates.find(({ id }) => id === gateId);
|
|
if (!gate) throw new TypeError(`the merge stage names an undefined gate: ${gateId}`);
|
|
for (const commandId of gate.commandIds) {
|
|
const command = commands.get(commandId);
|
|
if (!command) throw new TypeError(`${gateId} names an undefined command: ${commandId}`);
|
|
mergeScripts.add(command.script);
|
|
if (seen.has(commandId) || leftOut(command.script)) continue;
|
|
seen.add(commandId);
|
|
selected.push(Object.freeze({
|
|
name: `${gateId}:${commandId}`,
|
|
script: command.script,
|
|
args: Object.freeze([...(command.args ?? [])]),
|
|
expectation: command.expect === "pass"
|
|
? Object.freeze({ kind: "pass" as const })
|
|
: Object.freeze({
|
|
kind: "fail" as const,
|
|
expectedExitCode: command.expectedExitCode ?? 1,
|
|
expectedDiagnosticId: command.expectedDiagnosticId ?? "",
|
|
}),
|
|
}));
|
|
}
|
|
}
|
|
// An exclusion for a command that moved out of the merge stage would hide
|
|
// nothing today and silently drop it if it came back. A command the contract
|
|
// no longer has at all (a removal drill pruned its capability) is not stale,
|
|
// and FE-GATE-020's own drill scripts stay excluded so reverting FE-GATE-020
|
|
// back to merge never recurses.
|
|
const selfScripts = new Set<string>(SCAFFOLD_DRILL_SELF_SCRIPTS);
|
|
const contractScripts = new Set(contract.commands.map(({ script }) => script));
|
|
const stale = Object.keys(excluded).filter(
|
|
(script) => contractScripts.has(script) && !mergeScripts.has(script) && !selfScripts.has(script),
|
|
);
|
|
if (stale.length > 0) {
|
|
throw new TypeError(
|
|
`the scaffold drill excludes scripts the contract runs outside the merge stage: ${stale.join(", ")}`,
|
|
);
|
|
}
|
|
return Object.freeze(selected);
|
|
}
|
|
|
|
/**
|
|
* Runs one merge command in the fixture. A negative fixture command passes
|
|
* only with its registered exit code and diagnostic, as in run-ci-gate.ts.
|
|
*/
|
|
export function runScaffoldDrillCommand(
|
|
command: ScaffoldDrillCommand,
|
|
root: string,
|
|
pnpmCli: string,
|
|
): RemovalCheck {
|
|
const capture = command.expectation.kind === "fail";
|
|
const result = spawnSync(process.execPath, [pnpmCli, command.script, ...command.args], {
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
stdio: capture ? "pipe" : "inherit",
|
|
maxBuffer: 64 * 1024 * 1024,
|
|
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT },
|
|
});
|
|
if (capture) {
|
|
process.stdout.write(result.stdout ?? "");
|
|
process.stderr.write(result.stderr ?? "");
|
|
}
|
|
const classification = classifyGateStepResult(command.expectation, {
|
|
status: result.status,
|
|
signal: result.signal,
|
|
stdout: result.stdout ?? "",
|
|
stderr: result.stderr ?? "",
|
|
...(result.error ? { error: { code: (result.error as NodeJS.ErrnoException).code } } : {}),
|
|
});
|
|
if (classification.expectationMet) return { name: command.name, passed: true };
|
|
const invocation = `corepack pnpm ${[command.script, ...command.args].join(" ")}`;
|
|
return {
|
|
name: command.name,
|
|
passed: false,
|
|
failure: command.expectation.kind === "fail"
|
|
? `${invocation}: ${classification.kind}, expected exit ${command.expectation.expectedExitCode} with ${JSON.stringify(command.expectation.expectedDiagnosticId)}, got exit ${result.status ?? result.signal}`
|
|
: `${invocation} exited ${result.status ?? result.signal ?? "on a spawn error"}`,
|
|
};
|
|
}
|