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:
@@ -39,9 +39,10 @@
|
||||
}
|
||||
],
|
||||
"initialJavascript": {
|
||||
"gzipBytes": 204193,
|
||||
"gzipBytes": 204266,
|
||||
"files": 27,
|
||||
"perFeatureGzipBytes": 751,
|
||||
"perContextGzipBytes": 245
|
||||
"firstFeatureGzipBytes": 797,
|
||||
"perFeatureGzipBytes": 521,
|
||||
"perContextGzipBytes": 12
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ Files outside the feature directory. Everything else a feature needs is in
|
||||
| --- | --- | --- |
|
||||
| `src/.generated/*` | never by hand: every build and check script regenerates it | — |
|
||||
| `public/release-manifest.json` (tracked, the dev server's manifest) | every added or removed feature: `create:feature` rewrites it (`node scripts/write-dev-release-manifest.ts`). Commit it with the feature. Two feature branches change its `setDigest` line; on a merge conflict take either side and run the command again (1105/16-01) | `test:unit` (`tests/unit/dev-release-manifest.test.ts`) names the command; the dev server does not boot (`CONTRACT_SET_PACKAGE_MISSING`) |
|
||||
| `config/scale/feature-shape-ceilings.json` `initialJavascript` (tracked, only while the sample is installed) | every added or removed feature, and every template change that moves the initial JavaScript: `node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write`. Commit it with the change; on a merge conflict run the command again | `test:unit` (the feature-shape growth test compares it with a build) |
|
||||
| `config/scale/feature-shape-ceilings.json` `initialJavascript` (tracked) | every added or removed feature, and every template change that moves the initial JavaScript: `node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write`. Commit it with the change; on a merge conflict run the command again | `test:unit` (the feature-shape growth test compares it with a build) |
|
||||
| `src/contexts/<context>/context-module.ts` | the feature needs a new context | `generate:feature-index`: `Feature <id> belongs to undeclared context <context>` |
|
||||
| `src/contexts/<context>/context-layout.tsx` | the context needs its own frame instead of `AppShell` (see "Product home and layouts" below) | nothing: without it the context renders in `AppShell` |
|
||||
| `artifacts/tests/a11y-manual/<ROUTE_ID>.md` | every route the feature adds. Copy a record and reset it to `Status: pending-manual-review` | `test:unit` (`tests/unit/manual-a11y-evidence.test.ts`), `verify:documentation` (names the route IDs) and FE-GATE-009 (`review:a11y-manual -- --format-only`). FE-GATE-028 requires the signed review at release |
|
||||
|
||||
@@ -1709,7 +1709,7 @@ export const FEATURE_TRACKED_FILE_REWRITES = Object.freeze([
|
||||
Object.freeze({
|
||||
path: "config/scale/feature-shape-ceilings.json",
|
||||
command: "node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write",
|
||||
when: "by hand while the sample is installed (the file goes with it): test:unit compares it with a build",
|
||||
when: "by hand with the feature: test:unit compares it with a build",
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1772,7 +1772,7 @@ function report(plan: FeaturePlan): string {
|
||||
" 2. Run the merge gates: corepack pnpm ci:gate -- FE-GATE-<NNN> for each gate of the merge stage in config/ci/gates.json (README lists the loop). test:feature-scaffold runs them on a generated feature except the browser gates FE-GATE-008/009 and test:system.",
|
||||
` The feature's own tests: node scripts/run-vitest.ts run tests/features/${plan.id} (test:coverage runs them in CI)`,
|
||||
" A failing gate's log is artifacts/quality/gates/FE-GATE-<NNN>.txt. Locally FE-GATE-013 needs VITE_COMMIT_SHA=$(git rev-parse HEAD); to run them as CI does, set CI=true and the CI build identity (README).",
|
||||
" 3. The initial JavaScript changes. While config/scale/feature-shape-ceilings.json exists (the sample is installed), rewrite it with node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write and commit it with the feature; test:unit compares it with a build. corepack pnpm check:bundle checks the budget.",
|
||||
" 3. The initial JavaScript changes. Rewrite config/scale/feature-shape-ceilings.json with node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write and commit it with the feature; test:unit compares it with a build. corepack pnpm check:bundle checks the budget.",
|
||||
" public/release-manifest.json (the dev server's manifest) now names the feature's contract package; commit it with the feature.",
|
||||
" Two feature branches change the same lines of these files. On a merge conflict, take either side and run the command again:",
|
||||
...FEATURE_TRACKED_FILE_REWRITES.map((file) => ` ${file.path}: ${file.command}`),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { cp, mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { availableParallelism, cpus, loadavg, tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { gzipSync } from "node:zlib";
|
||||
|
||||
import { PLATFORM_ROUTE_REGISTRY } from "../../src/contracts/routes.ts";
|
||||
import { planFeature, type InstalledFacts } from "../create-feature.ts";
|
||||
import { classifyViteJavascript } from "../lib/classify-vite-bundle.ts";
|
||||
import { linkFixtureNodeModules } from "../lib/fixture-node-modules.ts";
|
||||
import { VITE_BUILD_INPUTS } from "../lib/vite-build-inputs.ts";
|
||||
@@ -12,11 +14,13 @@ import { parseTscExtendedDiagnostics, type TscDiagnostics } from "./collect-tsc-
|
||||
|
||||
/**
|
||||
* 11-04 (D-18). Cost of one app as its feature count grows, measured with
|
||||
* features shaped like the real one: `src/features/reference-feature` copied N
|
||||
* times with every feature-owned identifier renamed (feature id, route ids and
|
||||
* paths, API operations, schemas, query namespace, invalidation topic,
|
||||
* messages). The copies live in contexts of their own (200 features each, the
|
||||
* context ceiling) so the reference context is unchanged.
|
||||
* features shaped like a real one: N copies of the feature `create:feature`
|
||||
* writes with `--with-create --keyed` (a list, a detail and a create with its
|
||||
* form), each planned by the command's own planner (`planFeature`) with its
|
||||
* own ids and its own pinned contract package. The copies live in contexts of
|
||||
* their own, 200 features each (the context ceiling the baseline records).
|
||||
* 2026-11-07: the copies were the template's reference sample, renamed; the
|
||||
* template ships no sample now.
|
||||
*
|
||||
* For each N the script runs the product generator, `tsc --extendedDiagnostics`
|
||||
* over tsconfig.app.json and `vite build`, and records compiler counts, wall
|
||||
@@ -36,70 +40,102 @@ export const FEATURE_SHAPE_BASELINE_PATH = "config/scale/feature-shape-growth.js
|
||||
/** What the declared ceilings rest on, derived by hand from the baseline. */
|
||||
export const FEATURE_SHAPE_CEILINGS_PATH = "config/scale/feature-shape-ceilings.json";
|
||||
|
||||
const SOURCE_FEATURE = "src/features/reference-feature";
|
||||
const FEATURES_PER_CONTEXT = 200;
|
||||
// Platform-owned names that only happen to contain "reference".
|
||||
const PLATFORM_TOKENS = [
|
||||
"REFERENCE_FEATURE_V1",
|
||||
"supportReference",
|
||||
] as const;
|
||||
/** The command each copy is, as the baseline records it. */
|
||||
export const SHAPE_FEATURE_COMMAND = "create:feature <id> --with-create --keyed";
|
||||
export const FEATURES_PER_CONTEXT = 200;
|
||||
|
||||
/** Renames every feature-owned identifier of the reference feature for copy `id`. */
|
||||
export function renameReferenceFeature(
|
||||
text: string,
|
||||
id: string,
|
||||
context: Readonly<{ id: string; routeRoot: string }>,
|
||||
): string {
|
||||
const upper = id.toUpperCase();
|
||||
// 1101/07-04. Assembly refuses the reference fixture source in any other
|
||||
// feature, so a copy pins an external package and declares it in its
|
||||
// contracts, as a product feature would.
|
||||
const contractPackage = [
|
||||
"Object.freeze({",
|
||||
` packageId: "@feature-shape/${id}",`,
|
||||
' version: "1.0.0",',
|
||||
' digest: `sha256:${"0".repeat(64)}`,',
|
||||
" runtimeProtocolVersion: 1 as const,",
|
||||
' sourceRevision: "0000000",',
|
||||
" })",
|
||||
].join("\n");
|
||||
let renamed = text
|
||||
.replace(
|
||||
/source: Object\.freeze\(\{\s*kind: "TEMPLATE_FIXTURE" as const,\s*fixtureId: "REFERENCE_FEATURE_V1" as const,\s*revision: 1 as const,\s*\}\)/u,
|
||||
`source: Object.freeze({\n kind: "EXTERNAL_PACKAGE" as const,\n package: ${contractPackage},\n })`,
|
||||
)
|
||||
.replace(
|
||||
"contractPackages: Object.freeze([]),",
|
||||
`contractPackages: Object.freeze([${contractPackage}]),`,
|
||||
/** Copy `index`: its feature id and the context it lands in. */
|
||||
export function shapeFeature(index: number, featuresPerContext = FEATURES_PER_CONTEXT) {
|
||||
const contextNumber = Math.floor(index / featuresPerContext);
|
||||
return Object.freeze({
|
||||
id: `s${String(index).padStart(3, "0")}-feature`,
|
||||
context: Object.freeze({ id: `shape-context-${contextNumber}`, routeRoot: `shape-${contextNumber}` }),
|
||||
});
|
||||
}
|
||||
|
||||
function contextModule(context: Readonly<{ id: string; routeRoot: string }>): string {
|
||||
return (
|
||||
`export const CONTEXT_MODULE_ID = "${context.id}";\n` +
|
||||
`export const CONTEXT_APP_ID = "template-app";\n` +
|
||||
`export const CONTEXT_ROUTE_PATH = "${context.routeRoot}/*";\n` +
|
||||
`export const CONTEXT_MAX_FEATURES = ${FEATURES_PER_CONTEXT};\n`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The source files of `features` copies: the context declarations and what
|
||||
* `create:feature` writes under src/features (its tests and accessibility
|
||||
* records are not part of a build). Each copy pins `@feature-shape/<id>`, as
|
||||
* a product feature pins its published package, and gets a topic of its own.
|
||||
*/
|
||||
export function planShapeFeatures(
|
||||
features: number,
|
||||
featuresPerContext = FEATURES_PER_CONTEXT,
|
||||
): ReadonlyMap<string, string> {
|
||||
const files = new Map<string, string>();
|
||||
const contexts: { id: string; routePath: string }[] = [];
|
||||
const routes: InstalledFacts["routes"][number][] = Object.values(PLATFORM_ROUTE_REGISTRY).map(
|
||||
(route) => ({
|
||||
routeId: route.routeId,
|
||||
path: route.path,
|
||||
chunkId: route.chunkId,
|
||||
navigationOrder: route.navigationOrder,
|
||||
}),
|
||||
);
|
||||
const featureIds: string[] = [];
|
||||
const topics: string[] = [];
|
||||
for (let index = 0; index < features; index += 1) {
|
||||
const { id, context } = shapeFeature(index, featuresPerContext);
|
||||
if (index % featuresPerContext === 0) {
|
||||
contexts.push({ id: context.id, routePath: `${context.routeRoot}/*` });
|
||||
files.set(`src/contexts/${context.id}/context-module.ts`, contextModule(context));
|
||||
}
|
||||
const navigationOrder =
|
||||
Math.max(0, ...routes.flatMap((route) => (route.navigationOrder === null ? [] : [route.navigationOrder]))) + 10;
|
||||
const plan = planFeature(
|
||||
{
|
||||
id,
|
||||
context: context.id,
|
||||
write: "KEYED",
|
||||
contractPackage: {
|
||||
packageId: `@feature-shape/${id}`,
|
||||
version: "1.0.0",
|
||||
digest: `sha256:${"0".repeat(64)}`,
|
||||
sourceRevision: "0000000",
|
||||
},
|
||||
},
|
||||
{
|
||||
appIds: ["template-app"],
|
||||
featureIds,
|
||||
contexts,
|
||||
contextDirectories: contexts.map((declared) => declared.id),
|
||||
routes,
|
||||
topics,
|
||||
messageKeys: [],
|
||||
},
|
||||
() => String(index).padStart(26, "0"),
|
||||
);
|
||||
PLATFORM_TOKENS.forEach((token, index) => {
|
||||
renamed = renamed.replaceAll(token, `\u0000${index}\u0000`);
|
||||
});
|
||||
renamed = renamed
|
||||
.replaceAll("/examples/reference-resources", `/${context.routeRoot}/${id}-resources`)
|
||||
.replaceAll("qinv.01k10f7m3w9p6r2c8v5n4x", `qinv.shape.${id}`)
|
||||
.replaceAll("NoRequest", `${upper}NoRequest`)
|
||||
.replaceAll("reference-context", context.id)
|
||||
.replaceAll("REFERENCE", upper)
|
||||
.replaceAll("Reference", upper)
|
||||
.replaceAll("reference", id);
|
||||
PLATFORM_TOKENS.forEach((token, index) => {
|
||||
renamed = renamed.replaceAll(`\u0000${index}\u0000`, token);
|
||||
});
|
||||
return renamed;
|
||||
}
|
||||
|
||||
async function copyRenamed(from: string, to: string, rename: (text: string) => string) {
|
||||
await mkdir(to, { recursive: true });
|
||||
for (const entry of await readdir(from, { withFileTypes: true })) {
|
||||
const source = path.join(from, entry.name);
|
||||
const target = path.join(to, rename(entry.name));
|
||||
if (entry.isDirectory()) await copyRenamed(source, target, rename);
|
||||
else await writeFile(target, rename(await readFile(source, "utf8")));
|
||||
for (const [file, content] of plan.files) {
|
||||
if (file.startsWith("src/")) files.set(file, content);
|
||||
}
|
||||
featureIds.push(id);
|
||||
topics.push(plan.topic);
|
||||
for (const route of plan.routes) {
|
||||
routes.push({
|
||||
routeId: route.routeId,
|
||||
path: route.path,
|
||||
chunkId: `${route.routeId}-chunk`,
|
||||
navigationOrder: route.routeId === plan.routeId ? navigationOrder : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
async function createFixture(features: number): Promise<string> {
|
||||
async function createFixture(
|
||||
features: number,
|
||||
featuresPerContext = FEATURES_PER_CONTEXT,
|
||||
): Promise<string> {
|
||||
const root = await mkdtemp(path.join(tmpdir(), `feature-shape-${features}-`));
|
||||
for (const input of VITE_BUILD_INPUTS) {
|
||||
await mkdir(path.dirname(path.join(root, input)), { recursive: true });
|
||||
@@ -107,26 +143,9 @@ async function createFixture(features: number): Promise<string> {
|
||||
}
|
||||
await rm(path.join(root, "src/.generated"), { recursive: true, force: true });
|
||||
await linkFixtureNodeModules(root);
|
||||
for (let index = 0; index < features; index += 1) {
|
||||
const contextNumber = Math.floor(index / FEATURES_PER_CONTEXT);
|
||||
const context = { id: `shape-context-${contextNumber}`, routeRoot: `shape-${contextNumber}` };
|
||||
if (index % FEATURES_PER_CONTEXT === 0) {
|
||||
const contextFile = path.join(root, "src/contexts", context.id, "context-module.ts");
|
||||
await mkdir(path.dirname(contextFile), { recursive: true });
|
||||
await writeFile(
|
||||
contextFile,
|
||||
`export const CONTEXT_MODULE_ID = "${context.id}";\n` +
|
||||
`export const CONTEXT_APP_ID = "template-app";\n` +
|
||||
`export const CONTEXT_ROUTE_PATH = "${context.routeRoot}/*";\n` +
|
||||
`export const CONTEXT_MAX_FEATURES = ${FEATURES_PER_CONTEXT};\n`,
|
||||
);
|
||||
}
|
||||
const id = `s${String(index).padStart(3, "0")}`;
|
||||
await copyRenamed(
|
||||
path.resolve(SOURCE_FEATURE),
|
||||
path.join(root, "src/features", `${id}-feature`),
|
||||
(text) => renameReferenceFeature(text, id, context),
|
||||
);
|
||||
for (const [file, content] of planShapeFeatures(features, featuresPerContext)) {
|
||||
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
|
||||
await writeFile(path.join(root, file), content);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
@@ -166,15 +185,15 @@ async function javascriptGzipBytes(root: string, files: readonly string[]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 15-01. Initial JavaScript of the app with `features` reference copies
|
||||
* added: the generator and `vite build` only, no typecheck. The unit suite
|
||||
* 15-01. Initial JavaScript of the app with `features` copies added: the generator and `vite build` only, no typecheck. The unit suite
|
||||
* (merge stage) bounds what one more feature adds to the initial chunk with
|
||||
* it, so the growth is caught on the PR instead of at the next release.
|
||||
*/
|
||||
async function measureInitialJavascript(
|
||||
features: number,
|
||||
featuresPerContext = FEATURES_PER_CONTEXT,
|
||||
): Promise<Readonly<{ gzipBytes: number; files: number }>> {
|
||||
const root = await createFixture(features);
|
||||
const root = await createFixture(features, featuresPerContext);
|
||||
try {
|
||||
run(process.execPath, [path.resolve("scripts/generate-product-feature-index.ts"), `--root=${root}`], root);
|
||||
run(path.resolve("node_modules/.bin/vite"), ["build", "--logLevel", "error"], root);
|
||||
@@ -187,17 +206,20 @@ async function measureInitialJavascript(
|
||||
}
|
||||
|
||||
/**
|
||||
* 1103/15-02, 15-04. The template's initial JavaScript and what one more
|
||||
* feature and one more context add to it. The first copy lands in a new
|
||||
* context (shape-context-0) and the second in the same one, so the second
|
||||
* copy is a feature alone and the rest of the first is the context.
|
||||
* `initialJavascript` in config/scale/feature-shape-ceilings.json records
|
||||
* these numbers; tests/unit/feature-shape-growth.test.ts compares them with
|
||||
* the build on every unit run.
|
||||
* 1103/15-02, 15-04. The template's initial JavaScript and what features add
|
||||
* to it. Two copies in one context against one copy are one more feature
|
||||
* alone; the same two copies in two contexts against that are one more
|
||||
* context. 2026-11-07: the template has no feature, so the first copy also
|
||||
* brings the code every feature shares into the initial chunks; that is
|
||||
* `firstFeatureGzipBytes`, paid once. `initialJavascript` in
|
||||
* config/scale/feature-shape-ceilings.json records these numbers;
|
||||
* tests/unit/feature-shape-growth.test.ts compares them with the build on
|
||||
* every unit run.
|
||||
*/
|
||||
export type InitialJavascriptCosts = Readonly<{
|
||||
gzipBytes: number;
|
||||
files: number;
|
||||
firstFeatureGzipBytes: number;
|
||||
perFeatureGzipBytes: number;
|
||||
perContextGzipBytes: number;
|
||||
}>;
|
||||
@@ -205,13 +227,14 @@ export type InitialJavascriptCosts = Readonly<{
|
||||
export async function measureInitialJavascriptCosts(): Promise<InitialJavascriptCosts> {
|
||||
const none = await measureInitialJavascript(0);
|
||||
const one = await measureInitialJavascript(1);
|
||||
const two = await measureInitialJavascript(2);
|
||||
const perFeatureGzipBytes = two.gzipBytes - one.gzipBytes;
|
||||
const twoInOneContext = await measureInitialJavascript(2);
|
||||
const twoInTwoContexts = await measureInitialJavascript(2, 1);
|
||||
return {
|
||||
gzipBytes: none.gzipBytes,
|
||||
files: none.files,
|
||||
perFeatureGzipBytes,
|
||||
perContextGzipBytes: one.gzipBytes - none.gzipBytes - perFeatureGzipBytes,
|
||||
firstFeatureGzipBytes: one.gzipBytes - none.gzipBytes,
|
||||
perFeatureGzipBytes: twoInOneContext.gzipBytes - one.gzipBytes,
|
||||
perContextGzipBytes: twoInTwoContexts.gzipBytes - twoInOneContext.gzipBytes,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -228,10 +251,18 @@ export const INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES = 256;
|
||||
|
||||
/**
|
||||
* Fields of the record that no longer describe the build. The total may be
|
||||
* INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES off; the per-feature and
|
||||
* per-context costs are differences of builds with the same id but only a
|
||||
* few hundred bytes, so 10%; the file count is exact.
|
||||
* INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES off; the first-feature,
|
||||
* per-feature and per-context costs are differences of builds with the same
|
||||
* id, so 10%, and at least COST_RECORD_TOLERANCE_BYTES: a context costs a few
|
||||
* bytes now, and gzip moves a difference that small by a byte or two when
|
||||
* the build id changes. The file count is exact.
|
||||
*/
|
||||
export const COST_RECORD_TOLERANCE_BYTES = 16;
|
||||
|
||||
function costTolerance(bytes: number): number {
|
||||
return Math.max(Math.abs(bytes) * 0.1, COST_RECORD_TOLERANCE_BYTES);
|
||||
}
|
||||
|
||||
export function initialJavascriptRecordDrift(
|
||||
measured: InitialJavascriptCosts,
|
||||
record: InitialJavascriptCosts,
|
||||
@@ -239,8 +270,9 @@ export function initialJavascriptRecordDrift(
|
||||
const allowed: Readonly<Record<keyof InitialJavascriptCosts, number>> = {
|
||||
gzipBytes: INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES,
|
||||
files: 0,
|
||||
perFeatureGzipBytes: Math.abs(measured.perFeatureGzipBytes) * 0.1,
|
||||
perContextGzipBytes: Math.abs(measured.perContextGzipBytes) * 0.1,
|
||||
firstFeatureGzipBytes: costTolerance(measured.firstFeatureGzipBytes),
|
||||
perFeatureGzipBytes: costTolerance(measured.perFeatureGzipBytes),
|
||||
perContextGzipBytes: costTolerance(measured.perContextGzipBytes),
|
||||
};
|
||||
return (Object.keys(allowed) as (keyof InitialJavascriptCosts)[])
|
||||
.filter((field) => Math.abs(record[field] - measured[field]) > allowed[field])
|
||||
@@ -393,7 +425,7 @@ async function main(): Promise<void> {
|
||||
vite: version("vite"),
|
||||
},
|
||||
source,
|
||||
sourceFeature: SOURCE_FEATURE,
|
||||
sourceFeature: SHAPE_FEATURE_COMMAND,
|
||||
runs,
|
||||
};
|
||||
const output = process.argv.includes("--write")
|
||||
|
||||
@@ -71,8 +71,8 @@ try {
|
||||
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. Without the
|
||||
// sample there is no record to keep.
|
||||
// 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"], {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user