Files
clean-architecture-frontend…/scripts/test-feature-scaffold.ts
DongHyeonka b2042de9be test(scale): 규모 측정을 참조 기능 대신 생성 기능 사본으로 잰다
규모 측정(S4 3.1절 S-6)은 참조 기능을 복사해 이름을 바꿔 잰다.

create:feature의 planFeature로 사본마다 --with-create --keyed 기능
파일을 만든다(자기 계약 패키지와 topic, context당 200개). 초기 JS
기록에 firstFeatureGzipBytes를 더하고, context 비용은 둘째 기능을 새
context에 둘 때와 같은 context에 둘 때의 차이로 잰다. 옛 정의는 기능이
없는 템플릿에서 첫 기능의 공용 코드까지 context 비용으로 세어 5,788B로
상한 512B를 넘었다. 몇 바이트짜리 비용에는 기록 허용치 하한 16B를
둔다(빌드 ID에 따라 gzip이 1~2B 흔들린다). 이 트리(샘플이 아직 있는
상태)의 기록: 204,266B, 27파일, 첫 기능 797B, 기능 521B, context 12B.

위험: 성장 기준선(0·25·100개)은 샘플을 지운 트리에서 뒤 커밋이 다시
잰다. 이 커밋의 기준선 파일은 아직 참조 사본으로 잰 값이다.

검증(desktop): feature-shape-growth 등 4파일 57 passed, test:unit 통과.
2026-11-08 14:07:53 +09:00

122 lines
5.0 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import { mkdir, rm, writeFile } from "node:fs/promises";
import path from "node:path";
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 a default feature and a `--with-create --keyed` one, 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";
/** 1103/09-06. The `--with-create --keyed` slice, in its own context. */
const WRITE_FEATURE_ID = "scaffold-write-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 createdWrite = check("create-feature-write", "create:feature", [
WRITE_FEATURE_ID,
"--with-create",
"--keyed",
]);
const checks: RemovalCheck[] = [created, createdWrite];
if (created.passed && createdWrite.passed) {
// The generator's Next: 3. A project re-records the initial JavaScript
// with its features (config/scale/feature-shape-ceilings.json, which
// test:unit compares with a build) and commits it with them. A project
// that deleted the measurement has no record to keep.
const measurement = "scripts/scale/measure-feature-shape-growth.ts";
if (existsSync(path.join(fixtureRoot, measurement))) {
const recorded = spawnSync(process.execPath, [measurement, "--initial-baseline", "--write"], {
cwd: fixtureRoot,
stdio: "inherit",
}).status;
checks.push(
recorded === 0
? { name: "initial-javascript-record", passed: true }
: {
name: "initial-javascript-record",
passed: false,
failure: `node ${measurement} --initial-baseline --write exited ${recorded ?? "on a signal"}`,
},
);
}
// 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 });
}