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 통과.
This commit is contained in:
DongHyeonka
2026-11-08 14:07:53 +09:00
parent 794a51a37d
commit b2042de9be
7 changed files with 208 additions and 170 deletions
+60 -55
View File
@@ -5,22 +5,22 @@ import { describe, expect, it } from "vitest";
import {
FEATURE_SHAPE_BASELINE_PATH,
FEATURE_SHAPE_CEILINGS_PATH,
FEATURES_PER_CONTEXT,
initialJavascriptRecordDrift,
measureInitialJavascriptCosts,
renameReferenceFeature,
planShapeFeatures,
shapeFeature,
type InitialJavascriptCosts,
} 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.
* measurement with copies of a real feature: since 2026-11-07 the one
* `create:feature` writes, before that the template's reference sample.
*/
const context = { id: "shape-context-0", routeRoot: "shape-0" } as const;
type Run = Readonly<{
addedFeatures: number;
routes: number;
@@ -34,55 +34,49 @@ type Run = Readonly<{
}>;
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");
it("plans each copy with create:feature, 200 to a context", () => {
const copies = FEATURES_PER_CONTEXT + 1;
const files = planShapeFeatures(copies);
const first = shapeFeature(0);
const last = shapeFeature(copies - 1);
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");
expect([...files.keys()].filter((file) => file.endsWith("/context-module.ts"))).toEqual([
`src/contexts/${first.context.id}/context-module.ts`,
`src/contexts/${last.context.id}/context-module.ts`,
]);
expect(last.context.id).not.toBe(first.context.id);
for (const index of [0, FEATURES_PER_CONTEXT - 1, FEATURES_PER_CONTEXT]) {
const { id, context } = shapeFeature(index);
const module = files.get(`src/features/${id}/feature-module.ts`);
expect(module, id).toContain(`FEATURE_CONTEXT_ID = "${context.id}"`);
// The write slice: its detail and create pages are planned too.
expect([...files.keys()].filter((file) => file.startsWith(`src/features/${id}/`))).toEqual(
expect.arrayContaining([
expect.stringMatching(/-detail-page\.tsx$/u),
expect.stringMatching(/-create-page\.tsx$/u),
]),
);
}
// Only what a build reads: no tests, no accessibility records.
expect([...files.keys()].every((file) => file.startsWith("src/"))).toBe(true);
});
// 1101/07-04 made assembly refuse a TEMPLATE_FIXTURE contribution outside
// the reference feature, so every copy must pin an EXTERNAL_PACKAGE the way
// a product feature does.
it("turns the copied fixture source into an external package", () => {
const source = [
" source: Object.freeze({",
' kind: "TEMPLATE_FIXTURE" as const,',
' fixtureId: "REFERENCE_FEATURE_V1" as const,',
" revision: 1 as const,",
" }),",
" contractPackages: Object.freeze([]),",
].join("\n");
const renamed = renameReferenceFeature(source, "s007", context);
expect(renamed).not.toContain("TEMPLATE_FIXTURE");
expect(renamed).toContain('kind: "EXTERNAL_PACKAGE" as const');
expect(renamed.match(/packageId: "@feature-shape\/s007"/gu)).toHaveLength(2);
expect(renamed).not.toContain("contractPackages: Object.freeze([])");
});
it("keeps platform-owned names that only contain the word", () => {
const source =
"REFERENCE_FEATURE_V1 supportReference";
expect(renameReferenceFeature(source, "s001", context)).toBe(source);
// 1101/07-04. Assembly refuses the template fixture source in a product
// feature, so every copy pins an external package of its own, and has a
// topic of its own.
it("pins a package and a topic of its own for every copy", () => {
const files = planShapeFeatures(3);
const contracts = [0, 1, 2].map((index) => {
const { id } = shapeFeature(index);
const contract = [...files].find(([file]) =>
file.startsWith(`src/features/${id}/contracts/`) && file.endsWith("-feature-contract.ts"),
)?.[1];
expect(contract, id).toContain(`packageId: "@feature-shape/${id}"`);
return contract ?? "";
});
const topics = contracts.map((contract) => /"(qinv\.[0-9a-z]{26})"/u.exec(contract)?.[1]);
expect(new Set(topics).size).toBe(3);
expect(contracts.join("\n")).not.toContain("PLACEHOLDER_CONTRACT_PACKAGE");
});
it("commits a baseline measured at 25 and 100 real-shape features, twice each", async () => {
@@ -113,7 +107,7 @@ describe("feature-shape growth measurement (11-04)", () => {
// 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.
// Every copy contributes the generated feature's own routes.
expect((run.routes - origin!.routes) % size).toBe(0);
expect(run.routes).toBeGreaterThan(origin!.routes);
expect(run.build.lazyJavascriptFiles).toBeGreaterThan(
@@ -140,8 +134,12 @@ describe("feature-shape growth measurement (11-04)", () => {
* 1103/15-04. The first copy also adds a context (shape-context-0), so one
* number mixed a context's cost with a feature's and had 40 B left under
* the bound. A second copy in the same context is one more feature alone;
* the rest of the first copy is the context. Each has its own bound and
* the failure names which one grew.
* the second copy in a context of its own is one more context. Each has its
* own bound and the failure names which one grew. 2026-11-07: with no
* feature in the template, the first copy also brings the code all features
* share into the initial chunks (`firstFeatureGzipBytes`); it is paid once
* and recorded, not bounded here: the initial budget (check:bundle) bounds
* the total.
*
* 1103/15-02. The record in config/scale/feature-shape-ceilings.json is the
* one place the documents take the template's baseline from. Written by
@@ -176,6 +174,7 @@ describe("feature-shape growth measurement (11-04)", () => {
const measured = {
gzipBytes: 200_000,
files: 25,
firstFeatureGzipBytes: 5_000,
perFeatureGzipBytes: 700,
perContextGzipBytes: 250,
};
@@ -203,6 +202,12 @@ describe("feature-shape growth measurement (11-04)", () => {
expect(
initialJavascriptRecordDrift(measured, { ...measured, perFeatureGzipBytes: 800 }),
).toEqual(["perFeatureGzipBytes: record 800, build 700"]);
// A cost of a few bytes keeps a floor: gzip moves it by a byte or two.
const tiny = { ...measured, perContextGzipBytes: 4 };
expect(initialJavascriptRecordDrift(tiny, { ...tiny, perContextGzipBytes: 6 })).toEqual([]);
expect(initialJavascriptRecordDrift(tiny, { ...tiny, perContextGzipBytes: 30 })).toEqual([
"perContextGzipBytes: record 30, build 4",
]);
});
it("states in the committed rationale what the ceilings rest on", async () => {
@@ -218,7 +223,7 @@ describe("feature-shape growth measurement (11-04)", () => {
expect(rationale.baseline).toBe(FEATURE_SHAPE_BASELINE_PATH);
expect(rationale.ceilings).toEqual({
contextMaxFeatures: CONTEXT_MAX_FEATURES,
contextMaxFeatures: FEATURES_PER_CONTEXT,
appMaxContexts: APP_MAX_CONTEXTS,
});
expect(rationale.axes.map((row) => row.axis)).toEqual(
+2 -2
View File
@@ -6,8 +6,8 @@ import { FEATURE_TRACKED_FILE_REWRITES } from "../../scripts/create-feature.ts";
/**
* 1105/16-01. Adding a feature changes two tracked template files: the dev
* server's manifest (`create:feature` rewrites it) and, while the sample is
* installed, the initial JavaScript record (rewritten by command). The 03
* server's manifest (`create:feature` rewrites it) and the initial
* JavaScript record (rewritten by command). The 03
* manual's section A said the command writes two files outside the feature
* folder and named neither, the canonical table in starter-experience.md
* had neither, and nothing said what to do when two feature branches change