문제: config/scale/feature-shape-growth.json에 측정 시각만 있고 어느
코드를 쟀는지가 없다. 기준선이 지금 코드와 맞는지, 다음 측정과 비교할 수
있는지 알 수 없다. 실제로 기준선은 2026-09-27 측정이고, 그 뒤 15-01이
초기 청크 구조를 바꿨다(ceilings.json도 "baseline predates 15-01"이라고
적고 있었다). 기준선 0개 초기 JS 200,001 B, 기능당 2,907 B는 지금 코드와
다르다.
고른 방법:
- 측정 스크립트가 시작할 때 `git rev-parse HEAD`와 추적 파일 변경 목록
(`git status --porcelain --untracked-files=no`)을 읽어 결과의
`source: { commit, modifiedPaths }`에 싣는다. 변경 목록이 비면 커밋만으로
재현된다는 뜻이다. 측정 중 트리가 바뀔 수 있어 시작할 때 읽는다.
- 기준선을 현재 코드로 다시 잰다(--sizes=0,25,100 --repeats=2 --write).
- ceilings.json의 수치를 새 기준선에 맞춘다. 초기 JS 여유는 리뷰 개선안대로
"예산 − 기준선 ÷ 기능당 증가"로 적는다(2,291 B ÷ 약 610 B ≈ 3개).
- 단위 테스트가 기준선에 40자 commit과 modifiedPaths 배열이 있는지 본다.
버린 대안:
- 기준선 커밋이 현재 이력의 조상인지 테스트로 확인: 이력 없이 3-way로
이식하는 다운스트림(tech-log)에서는 템플릿 커밋이 없어 항상 실패한다.
- dirty 트리면 --write를 거절: 이 커밋처럼 측정 스크립트와 기준선을 한
커밋에 넣을 수 없게 된다. 대신 변경 경로를 그대로 기록한다.
위험·한계:
- 기록된 커밋은 2be973a(이 브랜치의 직전 커밋)이고 modifiedPaths는 측정
스크립트와 그 테스트 2개다. 측정 대상(src, vite 설정)은 그 커밋과 같다.
이 브랜치를 rebase하면 기록된 SHA가 이력에서 사라진다. 그때는 다시 재야
한다.
- 시간 값은 호스트 부하(loadavg 27~29)에 따라 흔들린다. 바이트와
instantiation 수만 비교 대상이다.
- 15-01 커밋 본문의 202,361 B와 이번 0개 측정 202,509 B는 148 B 다르다.
원인은 확인하지 않았다. ceilings.json은 기준선 수치 하나로 통일했다.
검증:
- RED: node scripts/run-vitest.ts run tests/unit/feature-shape-growth.test.ts
-t 'commits a baseline' — "expected undefined to deeply equal { commit:
StringMatching…" 실패.
- 측정(flock): 0개 202,509 B·720,060 inst, 25개 218,010 B, 100개
263,119 B·12,399,171 inst, 반복 2회 바이트·inst 동일. 기능당 초기 JS
약 610 B, lazy 약 8.3 KB·8파일, inst 약 117k, tsc 메모리 약 36 MB,
route 4개.
- 재현: 같은 트리에서 --sizes=0,25 --repeats=1을 다시 돌려 0개 202,509 B,
25개 218,010 B로 같음.
- GREEN: feature-shape-growth.test.ts 5 passed(빌드 측정 테스트 포함).
- tsc(node·test), eslint(바꾼 2파일), verify-documentation-readiness
PASS_SCOPED.
Refs: docs/reviews/2026-09-29-maturity-review/11-tests-browser-release-scale.md 11-05
156 lines
6.1 KiB
TypeScript
156 lines
6.1 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
FEATURE_SHAPE_BASELINE_PATH,
|
|
FEATURE_SHAPE_CEILINGS_PATH,
|
|
measureInitialJavascriptGzipBytes,
|
|
renameReferenceFeature,
|
|
} from "../../scripts/scale/measure-feature-shape-growth.ts";
|
|
import { APP_MAX_CONTEXTS } from "../../src/apps/template-app/app-module.ts";
|
|
import { CONTEXT_MAX_FEATURES } from "../../src/contexts/reference-context/context-module.ts";
|
|
|
|
/**
|
|
* 11-04 (D-18). The scale evidence used to come from stub features that only
|
|
* differ by name, so the cost of one app growing towards its declared ceiling
|
|
* (20 contexts x 200 features) was never measured. The committed baseline is a
|
|
* measurement with copies of the real reference feature.
|
|
*/
|
|
const context = { id: "shape-context-0", routeRoot: "shape-0" } as const;
|
|
|
|
type Run = Readonly<{
|
|
addedFeatures: number;
|
|
routes: number;
|
|
tsc: Readonly<{ passed: boolean; instantiations: number; wallMs: number }>;
|
|
build: Readonly<{
|
|
wallMs: number;
|
|
initialJavascriptGzipBytes: number;
|
|
lazyJavascriptFiles: number;
|
|
}>;
|
|
loadBefore: readonly number[];
|
|
}>;
|
|
|
|
describe("feature-shape growth measurement (11-04)", () => {
|
|
it("renames every feature-owned identifier of a reference copy", () => {
|
|
const source = [
|
|
'featureId: "reference-feature"',
|
|
'path: "/examples/reference-resources/:id"',
|
|
"REFERENCE_RESOURCE_LIST",
|
|
"ReferenceResourcePage",
|
|
'contextId: "reference-context"',
|
|
'topic: "qinv.01k10f7m3w9p6r2c8v5n4x"',
|
|
"NoRequest",
|
|
].join("\n");
|
|
|
|
const renamed = renameReferenceFeature(source, "s007", context);
|
|
|
|
expect(renamed).not.toMatch(/reference/iu);
|
|
expect(renamed).toContain('featureId: "s007-feature"');
|
|
expect(renamed).toContain('path: "/shape-0/s007-resources/:id"');
|
|
expect(renamed).toContain("S007_RESOURCE_LIST");
|
|
expect(renamed).toContain("S007ResourcePage");
|
|
expect(renamed).toContain('contextId: "shape-context-0"');
|
|
expect(renamed).toContain('topic: "qinv.shape.s007"');
|
|
expect(renamed).toContain("S007NoRequest");
|
|
});
|
|
|
|
it("keeps platform-owned names that only contain the word", () => {
|
|
const source =
|
|
"REFERENCE_EXTERNAL_BEARER REFERENCE_FEATURE_V1 supportReference";
|
|
|
|
expect(renameReferenceFeature(source, "s001", context)).toBe(source);
|
|
});
|
|
|
|
it("commits a baseline measured at 25 and 100 real-shape features, twice each", async () => {
|
|
const baseline = JSON.parse(
|
|
await readFile(FEATURE_SHAPE_BASELINE_PATH, "utf8"),
|
|
) as Readonly<{
|
|
environment: Readonly<Record<string, unknown>>;
|
|
source: unknown;
|
|
runs: readonly Run[];
|
|
}>;
|
|
expect(baseline.environment).toMatchObject({
|
|
cpuModel: expect.any(String),
|
|
logicalCpus: expect.any(Number),
|
|
});
|
|
// 11-05 (2026-09-29). Without the commit it measured, nobody can tell
|
|
// whether the baseline still describes the code or compare a new run.
|
|
expect(baseline.source).toEqual({
|
|
commit: expect.stringMatching(/^[0-9a-f]{40}$/u),
|
|
modifiedPaths: expect.any(Array),
|
|
});
|
|
|
|
const bySize = (size: number) =>
|
|
baseline.runs.filter((run) => run.addedFeatures === size);
|
|
const [origin] = bySize(0);
|
|
expect(origin?.tsc.passed).toBe(true);
|
|
for (const size of [25, 100]) {
|
|
const runs = bySize(size);
|
|
// A failed typecheck is the result and is not repeated.
|
|
expect(runs.length).toBeGreaterThanOrEqual(runs[0]?.tsc.passed ? 2 : 1);
|
|
for (const run of runs) {
|
|
// Every copy contributes the reference feature's own routes.
|
|
expect((run.routes - origin!.routes) % size).toBe(0);
|
|
expect(run.routes).toBeGreaterThan(origin!.routes);
|
|
expect(run.build.lazyJavascriptFiles).toBeGreaterThan(
|
|
origin!.build.lazyJavascriptFiles,
|
|
);
|
|
expect(run.loadBefore).toHaveLength(3);
|
|
}
|
|
// Compiler counts are deterministic; only times vary with the host.
|
|
expect(new Set(runs.map((run) => run.tsc.instantiations)).size).toBe(1);
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 15-01. The initial budget (config/performance/budgets.json) is a fixed
|
|
* 200 KiB for the whole app, so what one installed feature adds to the
|
|
* initial chunk decides how many features fit. Before 15-01 every feature's
|
|
* contracts, schemas, mappers, HTTP gateway and API loaded at boot: +3,922 B
|
|
* per copy, and the first added feature exceeded the budget. Only what the
|
|
* shell needs before a feature route is entered may load at boot (route
|
|
* table, navigation and page messages, invalidation identities: 741 B when
|
|
* 15-01 landed); the rest loads with the feature's routes. The bound also
|
|
* fails if the feature-declarations chunk group in vite.config.ts stops
|
|
* matching.
|
|
*/
|
|
it("adds at most 1 KiB of initial JavaScript per reference-shaped feature (15-01)", async () => {
|
|
const withoutCopies = await measureInitialJavascriptGzipBytes(0);
|
|
const withOneCopy = await measureInitialJavascriptGzipBytes(1);
|
|
|
|
expect(withOneCopy - withoutCopies).toBeLessThanOrEqual(1_024);
|
|
}, 120_000);
|
|
|
|
it("states in the committed rationale what the ceilings rest on", async () => {
|
|
// The rationale lives next to the baseline, not in a review document: the
|
|
// history documents may be deleted after copying (README.md).
|
|
const rationale = JSON.parse(
|
|
await readFile(FEATURE_SHAPE_CEILINGS_PATH, "utf8"),
|
|
) as Readonly<{
|
|
baseline: string;
|
|
ceilings: Readonly<{ contextMaxFeatures: number; appMaxContexts: number }>;
|
|
axes: readonly Readonly<Record<string, string>>[];
|
|
}>;
|
|
|
|
expect(rationale.baseline).toBe(FEATURE_SHAPE_BASELINE_PATH);
|
|
expect(rationale.ceilings).toEqual({
|
|
contextMaxFeatures: CONTEXT_MAX_FEATURES,
|
|
appMaxContexts: APP_MAX_CONTEXTS,
|
|
});
|
|
expect(rationale.axes.map((row) => row.axis)).toEqual(
|
|
expect.arrayContaining([
|
|
"Typecheck of one app",
|
|
"Production build",
|
|
"Initial JavaScript",
|
|
"Lazy JavaScript",
|
|
"Routes",
|
|
]),
|
|
);
|
|
for (const row of rationale.axes) {
|
|
for (const column of ["axis", "verified", "condition", "notVerified"])
|
|
expect(row[column], `${row.axis}.${column}`).toMatch(/\S/u);
|
|
}
|
|
});
|
|
});
|