문제: 1101/07-04 이후 조립 단계는 reference feature 밖의 TEMPLATE_FIXTURE 기여를 거부한다. 규모 측정 생성기는 reference feature를 그대로 복사하므로 +25/+100 측정이 ContractContributionError로 멈췄고, 기준선 source가 작업 트리 SHA(2be973a)로 남아 있었다. 방법: renameReferenceFeature가 복사본의 source를 EXTERNAL_PACKAGE (@feature-shape/<id>)로 바꾸고, 같은 패키지를 contracts.contractPackages에도 선언한다. 제품 기능이 실제로 거치는 경로와 같다. 조립 검사에 측정용 예외를 두는 안은 버렸다. 측정이 제품과 다른 경로를 재게 된다. 위험: reference feature의 source 블록 형태가 바뀌면 정규식이 맞지 않는다. 그때는 조립이 같은 오류로 실패하므로 조용히 틀린 값을 기록하지 않는다. 검증: node scripts/scale/measure-feature-shape-growth.ts --sizes=0,25,100 --repeats=2 --write 성공(초기 JS +0: 203,816 B, +25: 219,508 B, +100: 264,841 B), tests/unit/feature-shape-growth.test.ts 6/6 통과.
177 lines
7.0 KiB
TypeScript
177 lines
7.0 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");
|
|
});
|
|
|
|
// 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_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);
|
|
}
|
|
});
|
|
});
|