Carries 359 template commits, tag v0.2.0 plus one documentation commit: the generator-built feature index with its app, bounded-context and feature declarations, the src/platform kernel and scale tooling, the 2026-09-24 src review fixes, and the 2026-09-25 maturity review round with its CHANGELOG [보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them merged with product changes; 127 are not carried. Product identity is unchanged: name, version 0.1.0, routes, design and the TechLog domain. Three decisions worth naming. TechLog stays composed directly, as the last two syncs recorded; its directory carries a NOT_INSTALLED marker that says so, and every installed-* composer takes the template's projection with TechLog added on top. The reference sample is no longer installed: the template now installs a feature only through feature-module.ts and context-routes.ts, which load the screens this product deleted, so its three operations, six schemas and one topic leave the registries, recorded as registry change evidence. And AppRouter mounts the platform and TechLog routes only; the template's bounded-context route gateway waits for a generator-installed feature. Required fixes: readSubject on the BFF session owner (without it every HTTP Studio session would close as integration-failed), zod through the facade in nine TechLog files, noUnusedLocals, and public/config.json written out to match the local profile. Derived baselines were recomputed after reproducing both sides' values: CI contract 101 commands / 106 references / 141 artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime config schema baseline equals the schema at8210d48. Verified here: types, lint, architecture, adapter inventory, CI contract, i18n, design system, diagnostics, browser security, dev release manifest, TechLog contract and build pass; 220 component, 155 integration, 15 contract, 418 TechLog, 43 reference-feature, 18 recipe and 46 release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at8210d48first and unchanged: check:registries (byte-identical), test:runtime-schema, verify:documentation. Brought by the template and escalated rather than suppressed: check:request-fanout on TechLog's cursor pagination, check:remediation-ledger (fails upstream too), the shared-chunk hash test, and the registry-dependent sample removal and second-feature tests. Playwright suites were not run. Full record, the five open questions and the follow-ups in docs/operations/template-sync-2026-09-29.md. (cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
173 lines
7.8 KiB
TypeScript
173 lines
7.8 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterAll, describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
generateAppIndexes,
|
|
selectAppIndexes,
|
|
} from "../../scripts/generate-product-feature-index.ts";
|
|
import {
|
|
APP_A,
|
|
reachableSourceGraph,
|
|
writeFilesystemTopology,
|
|
writeSyntheticApps,
|
|
} from "./filesystem-topology.ts";
|
|
import { APP_CONTEXT_BUDGET, CONTEXT_FEATURE_BUDGET, SCALE_PROFILES } from "./scale-profile.ts";
|
|
import {
|
|
createSyntheticTopology,
|
|
declarationSource,
|
|
selectAppInputs,
|
|
} from "./synthetic-topology.ts";
|
|
|
|
/**
|
|
* Spec §37. The central 1M architectural proof, on the production path.
|
|
*
|
|
* - S0-S2: real on-disk repositories, generated by the production command
|
|
* (`scripts/generate-product-feature-index.ts --app=`), whose discovery reads
|
|
* app/context/feature ownership declarations.
|
|
* - S3/S4: the same production selection (`selectAppIndexes`) over a
|
|
* declaration source that models 100k/1M logical features without writing
|
|
* them; an equivalence test pins that source to the filesystem one.
|
|
*/
|
|
const GENERATOR = path.resolve("scripts/generate-product-feature-index.ts");
|
|
const OUTPUTS = [
|
|
"src/.generated/product-feature-index.ts",
|
|
"src/.generated/product-context-index.ts",
|
|
"src/.generated/product-app.ts",
|
|
] as const;
|
|
const roots: string[] = [];
|
|
|
|
afterAll(async () => {
|
|
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
async function productionBuildInputs(globalFeatures: number) {
|
|
const root = await mkdtemp(path.join(tmpdir(), `topology-${globalFeatures}-`));
|
|
roots.push(root);
|
|
const written = await writeFilesystemTopology(root, { globalFeatures });
|
|
const run = spawnSync(process.execPath, [GENERATOR, `--root=${root}`, `--app=${APP_A.id}`], {
|
|
encoding: "utf8",
|
|
});
|
|
if (run.status !== 0) throw new Error(`generator failed: ${run.stderr}`);
|
|
const generated = await Promise.all(
|
|
OUTPUTS.map((file) => readFile(path.join(root, file), "utf8")),
|
|
);
|
|
const graph = await reachableSourceGraph(root, OUTPUTS);
|
|
return { written, generated, graph };
|
|
}
|
|
|
|
describe("global-to-local independence on the production generator path", () => {
|
|
it(
|
|
"keeps App A's generated indexes and reachable source graph identical from S0 to S2 on disk",
|
|
async () => {
|
|
const s0 = await productionBuildInputs(SCALE_PROFILES.S0);
|
|
const s1 = await productionBuildInputs(SCALE_PROFILES.S1);
|
|
const s2 = await productionBuildInputs(SCALE_PROFILES.S2);
|
|
|
|
expect(s2.written.features).toBe(SCALE_PROFILES.S2);
|
|
expect(s2.written.apps).toBeGreaterThan(s0.written.apps);
|
|
expect(s1.generated).toEqual(s0.generated);
|
|
expect(s2.generated).toEqual(s0.generated);
|
|
expect(s2.graph).toEqual(s0.graph);
|
|
const hash = (texts: readonly string[]) =>
|
|
texts.map((text) => createHash("sha256").update(text).digest("hex"));
|
|
expect(hash(s2.generated)).toEqual(hash(s0.generated));
|
|
|
|
const localFeatures = APP_A.contexts * APP_A.featuresPerContext;
|
|
// Generated indexes + (feature-module, context-routes, page) per local feature.
|
|
expect(s2.graph).toHaveLength(OUTPUTS.length + localFeatures * 3);
|
|
expect(s2.graph.some((file) => file.includes("other-"))).toBe(false);
|
|
expect(s2.generated[1]?.match(/defineBoundedContextModule\(\{/gu)).toHaveLength(APP_A.contexts);
|
|
},
|
|
120_000,
|
|
);
|
|
|
|
it("selects another app from the same repository without App A's features", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "topology-select-"));
|
|
roots.push(root);
|
|
await writeFilesystemTopology(root, { globalFeatures: 1_100 });
|
|
const other = await generateAppIndexes(root, "other-0");
|
|
expect(other.app.id).toBe("other-0");
|
|
expect(other.entries.every((entry) => entry.contextId.startsWith("other-0-"))).toBe(true);
|
|
await expect(generateAppIndexes(root, undefined)).rejects.toThrow(/Select a deployable app/);
|
|
await expect(generateAppIndexes(root, "missing")).rejects.toThrow(/Unknown deployable app/);
|
|
});
|
|
|
|
it("produces the same output from the filesystem source and the S3/S4 declaration source", async () => {
|
|
const topology = createSyntheticTopology({ globalFeatures: SCALE_PROFILES.S0 * 3 });
|
|
const root = await mkdtemp(path.join(tmpdir(), "topology-equivalence-"));
|
|
roots.push(root);
|
|
await writeSyntheticApps(
|
|
root,
|
|
["app-0", "app-1", "app-2"].map((id) => ({
|
|
id,
|
|
maxContexts: APP_CONTEXT_BUDGET,
|
|
contexts: topology.app(id).contexts.map((context) => ({
|
|
...context,
|
|
maxFeatures: CONTEXT_FEATURE_BUDGET,
|
|
})),
|
|
})),
|
|
);
|
|
const fromDisk = await generateAppIndexes(root, "app-0");
|
|
const fromModel = selectAppIndexes(declarationSource(topology), "app-0");
|
|
expect(fromModel.featureIndex).toBe(fromDisk.featureIndex);
|
|
expect(fromModel.contextIndex).toBe(fromDisk.contextIndex);
|
|
expect(fromModel.appIndex).toBe(fromDisk.appIndex);
|
|
});
|
|
|
|
it("keeps one unchanged app's production indexes identical from S0 to S4", () => {
|
|
const s0 = selectAppInputs(createSyntheticTopology({ globalFeatures: SCALE_PROFILES.S0 }), "app-0");
|
|
for (const globalFeatures of Object.values(SCALE_PROFILES)) {
|
|
const current = selectAppInputs(createSyntheticTopology({ globalFeatures }), "app-0");
|
|
expect(current.contextIds).toEqual(s0.contextIds);
|
|
expect(current.featureIds).toEqual(s0.featureIds);
|
|
expect(current.routeRootIds).toEqual(s0.routeRootIds);
|
|
expect(current.generatedFeatureIndex).toBe(s0.generatedFeatureIndex);
|
|
expect(current.generatedContextIndex).toBe(s0.generatedContextIndex);
|
|
expect(current.generatedAppIndex).toBe(s0.generatedAppIndex);
|
|
expect(current.generatedHashes).toEqual(s0.generatedHashes);
|
|
expect(current.compileInputPaths).toEqual(s0.compileInputPaths);
|
|
}
|
|
// The compile input is App A's own modules only: one feature module and
|
|
// one lazy route module per local feature, plus the context descriptor.
|
|
const featureOwned = s0.compileInputPaths.filter((file) => /^src\/features\/[^/]+\//u.test(file));
|
|
expect(featureOwned).toHaveLength(s0.featureIds.length * 2);
|
|
expect(featureOwned.every((file) => file.startsWith("src/features/app0-"))).toBe(true);
|
|
});
|
|
|
|
it("reads only the selected app's declarations, even at 1,000,000 logical features", () => {
|
|
const inputs = selectAppInputs(
|
|
createSyntheticTopology({ globalFeatures: SCALE_PROFILES.S4 }),
|
|
"app-0",
|
|
);
|
|
expect(inputs.reads.apps).toBe(1);
|
|
expect(inputs.reads.contexts).toBe(inputs.contextIds.length);
|
|
expect(inputs.reads.features).toBe(inputs.featureIds.length);
|
|
expect(inputs.featureIds.length).toBeLessThan(SCALE_PROFILES.S0 + 1);
|
|
});
|
|
|
|
it("boots only direct context roots, never the global feature table", () => {
|
|
const inputs = selectAppInputs(
|
|
createSyntheticTopology({ globalFeatures: SCALE_PROFILES.S4 }),
|
|
"app-0",
|
|
);
|
|
expect(inputs.routeRootIds.length).toBe(inputs.contextIds.length);
|
|
expect(inputs.routeRootIds.length).toBeLessThanOrEqual(inputs.contextBudget);
|
|
// Feature executables sit behind the lazy context loader, not in boot imports.
|
|
expect(inputs.generatedContextIndex).toContain("async loadRoutes()");
|
|
expect(inputs.generatedContextIndex).toMatch(/import\("\.\.\/features\//u);
|
|
});
|
|
|
|
it("keeps an app deep in the S4 topology within the same local shape", () => {
|
|
const topology = createSyntheticTopology({ globalFeatures: SCALE_PROFILES.S4 });
|
|
const first = selectAppInputs(topology, "app-0");
|
|
const last = selectAppInputs(topology, `app-${topology.appCount - 1}`);
|
|
expect(last.featureIds.length).toBe(first.featureIds.length);
|
|
expect(last.contextIds.length).toBe(first.contextIds.length);
|
|
});
|
|
});
|