Files
tech-log-frontend/tests/scale/synthetic-topology.ts
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
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 at 8210d48.

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 at
8210d48 first 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)
2026-11-12 08:28:54 +09:00

208 lines
7.2 KiB
TypeScript

import { createHash } from "node:crypto";
import { planTopologyCapacity } from "../../src/platform/cardinality/topology-capacity.ts";
import {
selectAppIndexes,
type ContextDeclaration,
type FeatureDeclaration,
type TopologyDeclarationSource,
} from "../../scripts/generate-product-feature-index.ts";
import {
APP_CONTEXT_BUDGET,
CONTEXT_FEATURE_BUDGET,
SYNTHETIC_APP_SHAPE,
} from "./scale-profile.ts";
/**
* Spec §37. A compact model of a global product topology.
*
* Only counts are stored. An app's contexts and feature ids are derived on
* demand from its index, so a 1,000,000-feature topology costs a handful of
* numbers plus whatever single app a test actually inspects.
*/
export type SyntheticContext = Readonly<{
id: string;
routePath: string;
featureIds: readonly string[];
}>;
export type SyntheticApp = Readonly<{
id: string;
localFeatureCount: number;
contexts: readonly SyntheticContext[];
}>;
export type SyntheticTopology = Readonly<{
globalFeatures: number;
appCount: number;
contextCount: number;
apps: Readonly<{ length: number; [index: number]: SyntheticApp }>;
app(id: string): SyntheticApp;
}>;
function contextFor(appIndex: number, contextIndex: number, features: number): SyntheticContext {
const id = `app${appIndex}-ctx${contextIndex}`;
return Object.freeze({
id,
routePath: `ctx${contextIndex}/*`,
featureIds: Object.freeze(
Array.from({ length: features }, (_, featureIndex) => `${id}-f${featureIndex}`),
),
});
}
export function createSyntheticTopology(
options: Readonly<{ globalFeatures: number }>,
): SyntheticTopology {
const { contextsPerApp, featuresPerContext } = SYNTHETIC_APP_SHAPE;
const plan = planTopologyCapacity({
featureCount: options.globalFeatures,
maxFeaturesPerContext: featuresPerContext,
maxContextsPerApp: contextsPerApp,
});
const featuresPerApp = contextsPerApp * featuresPerContext;
const cache = new Map<number, SyntheticApp>();
function build(appIndex: number): SyntheticApp {
const cached = cache.get(appIndex);
if (cached) return cached;
const firstFeature = appIndex * featuresPerApp;
const localFeatureCount = Math.max(
0,
Math.min(featuresPerApp, options.globalFeatures - firstFeature),
);
const contextCount = Math.ceil(localFeatureCount / featuresPerContext);
const app = Object.freeze({
id: `app-${appIndex}`,
localFeatureCount,
contexts: Object.freeze(
Array.from({ length: contextCount }, (_, contextIndex) =>
contextFor(
appIndex,
contextIndex,
Math.min(featuresPerContext, localFeatureCount - contextIndex * featuresPerContext),
),
),
),
});
// Inspecting an app is local work; the cache never exceeds what the test
// itself asked for.
cache.set(appIndex, app);
return app;
}
const apps = new Proxy(Object.freeze({ length: plan.appCount }), {
get(target, property) {
if (typeof property === "string" && /^\d+$/u.test(property)) {
const index = Number(property);
return index < plan.appCount ? build(index) : undefined;
}
return Reflect.get(target, property);
},
}) as SyntheticTopology["apps"];
return Object.freeze({
globalFeatures: options.globalFeatures,
appCount: plan.appCount,
contextCount: plan.contextCount,
apps,
app(id: string) {
const match = /^app-(\d+)$/u.exec(id);
const index = match ? Number(match[1]) : Number.NaN;
if (!Number.isSafeInteger(index) || index >= plan.appCount) {
throw new RangeError(`unknown synthetic app ${id}`);
}
return build(index);
},
});
}
export type DeclarationReads = { apps: number; contexts: number; features: number };
/**
* The synthetic topology as a production `TopologyDeclarationSource`: the same
* ownership-indexed interface the filesystem source implements. It counts how
* many declarations the production selection actually reads, which is the
* locality evidence at 1,000,000 logical features.
*/
export function declarationSource(
topology: SyntheticTopology,
): TopologyDeclarationSource & Readonly<{ reads: DeclarationReads }> {
const reads: DeclarationReads = { apps: 0, contexts: 0, features: 0 };
const appIndex = (appId: string) => {
const match = /^app-(\d+)$/u.exec(appId);
const index = match ? Number(match[1]) : Number.NaN;
return Number.isSafeInteger(index) && index < topology.appCount ? index : -1;
};
const contextOwner = (contextId: string) => {
const match = /^app(\d+)-ctx(\d+)$/u.exec(contextId);
return match ? { app: `app-${match[1]}`, context: Number(match[2]) } : null;
};
return Object.freeze({
reads,
appIds() {
// Listing app ids is O(apps), never O(features); the generator only
// needs it when no app is selected explicitly.
return Array.from({ length: topology.appCount }, (_, index) => `app-${index}`);
},
app(appId: string) {
if (appIndex(appId) < 0) return undefined;
reads.apps += 1;
return { id: appId, maxContexts: APP_CONTEXT_BUDGET };
},
contextsOf(appId: string): readonly ContextDeclaration[] {
if (appIndex(appId) < 0) return [];
const contexts = topology.app(appId).contexts;
reads.contexts += contexts.length;
return contexts.map((context) => ({
id: context.id,
appId,
routePath: context.routePath,
maxFeatures: CONTEXT_FEATURE_BUDGET,
}));
},
featuresOf(contextId: string): readonly FeatureDeclaration[] {
const owner = contextOwner(contextId);
if (!owner || appIndex(owner.app) < 0) return [];
const context = topology.app(owner.app).contexts[owner.context];
if (!context) return [];
reads.features += context.featureIds.length;
return context.featureIds.map((id) => ({ id, contextId, directory: id }));
},
});
}
/**
* Everything one deployable app compiles and boots with, produced by the
* production generator's own app selection (`selectAppIndexes`).
*/
export function selectAppInputs(topology: SyntheticTopology, appId: string) {
const source = declarationSource(topology);
const selected = selectAppIndexes(source, appId);
const contextIds = [...new Set(selected.entries.map((entry) => entry.contextId))];
const generated = [selected.featureIndex, selected.contextIndex, selected.appIndex];
// Every module the generated entries hand to the compiler/bundler (static
// and lazy imports), resolved from `src/.generated/`.
const compileInputPaths = [
...new Set(
generated.flatMap((text) =>
[...text.matchAll(/(?:from\s+|import\()\s*"(\.\.\/[^"]+)"/gu)].map((match) =>
`src/${(match[1] as string).slice("../".length)}`,
),
),
),
].sort();
return Object.freeze({
contextIds,
featureIds: selected.entries.map((entry) => entry.id),
routeRootIds: [...new Set(selected.entries.map((entry) => entry.contextRoutePath))],
generatedFeatureIndex: selected.featureIndex,
generatedContextIndex: selected.contextIndex,
generatedAppIndex: selected.appIndex,
generatedHashes: generated.map((text) => createHash("sha256").update(text).digest("hex")),
compileInputPaths,
contextBudget: APP_CONTEXT_BUDGET,
reads: { ...source.reads },
});
}