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)
This commit is contained in:
DongHyeonka
2026-11-12 08:28:54 +09:00
parent 585c62431a
commit c80320dfc7
738 changed files with 55027 additions and 13567 deletions
@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import {
requestAmplification,
retryAmplification,
telemetryAmplification,
} from "./amplification-metrics.ts";
describe("amplification metrics", () => {
it("computes exact request and retry amplification", () => {
expect(requestAmplification({
interactions: 1_000,
physicalRequests: 1_150,
})).toBe(1.15);
expect(retryAmplification({
initialRequests: 1_000,
totalRequests: 1_200,
})).toBe(1.2);
expect(telemetryAmplification({ logicalEvents: 100_000, telemetrySends: 20 })).toBe(
0.0002,
);
});
it.each([0, -1, Number.NaN, Number.POSITIVE_INFINITY])(
"rejects an invalid denominator %s",
(denominator) => {
expect(() =>
requestAmplification({ interactions: denominator, physicalRequests: 1 }),
).toThrow(RangeError);
expect(() =>
retryAmplification({ initialRequests: denominator, totalRequests: 1 }),
).toThrow(RangeError);
expect(() =>
telemetryAmplification({ logicalEvents: denominator, telemetrySends: 1 }),
).toThrow(RangeError);
},
);
it("rejects a negative numerator", () => {
expect(() =>
requestAmplification({ interactions: 1, physicalRequests: -1 }),
).toThrow(RangeError);
});
});
@@ -0,0 +1,34 @@
/**
* Spec §34. Operational amplification metrics.
*
* - request amplification = physical requests / logical interactions
* - retry amplification = total physical attempts / initial requests
* - telemetry amplification = telemetry sends / logical failures or events
*/
function ratio(numerator: number, denominator: number, name: string): number {
if (!Number.isFinite(denominator) || denominator <= 0) {
throw new RangeError(`${name} denominator must be positive: ${denominator}`);
}
if (!Number.isFinite(numerator) || numerator < 0) {
throw new RangeError(`${name} numerator must be non-negative: ${numerator}`);
}
return Math.round((numerator / denominator) * 1e9) / 1e9;
}
export function requestAmplification(
input: Readonly<{ interactions: number; physicalRequests: number }>,
): number {
return ratio(input.physicalRequests, input.interactions, "request amplification");
}
export function retryAmplification(
input: Readonly<{ initialRequests: number; totalRequests: number }>,
): number {
return ratio(input.totalRequests, input.initialRequests, "retry amplification");
}
export function telemetryAmplification(
input: Readonly<{ logicalEvents: number; telemetrySends: number }>,
): number {
return ratio(input.telemetrySends, input.logicalEvents, "telemetry amplification");
}
@@ -0,0 +1,165 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import {
manualClock,
scopeSnapshot,
testExecutionContext,
testExecutor,
type Transport,
} from "../../helpers/traffic-test-kit.ts";
import {
requestAmplification,
retryAmplification,
} from "./amplification-metrics.ts";
import { runSyntheticTraffic, TEST_QUERY, upstream } from "./synthetic-traffic.ts";
afterEach(() => {
vi.useRealTimers();
});
describe("total outage", () => {
it("bounds physical requests when all upstream calls fail", async () => {
const result = await runSyntheticTraffic({
interactions: 10_000,
upstream: "always-fail",
maxPhysicalRequestsPerInteraction: 2,
maxRetriesPerInteraction: 1,
});
expect(result.physicalRequests).toBeLessThanOrEqual(20_000);
expect(result.succeeded).toBe(0);
expect(requestAmplification(result)).toBeLessThanOrEqual(2);
expect(
retryAmplification({
initialRequests: result.initialRequests,
totalRequests: result.physicalRequests,
}),
).toBeLessThanOrEqual(2);
}, 60_000);
it("keeps amplification bounded when one interaction fans out into many operations", async () => {
const result = await runSyntheticTraffic({
interactions: 1_000,
upstream: "always-fail",
maxPhysicalRequestsPerInteraction: 3,
maxRetriesPerInteraction: 1,
operationsPerInteraction: 6,
});
// Unbudgeted: 6 operations x 3 attempts = 18 per interaction.
expect(requestAmplification(result)).toBeLessThanOrEqual(3);
}, 60_000);
it("stays at 1x amplification when upstream is healthy", async () => {
const result = await runSyntheticTraffic({
interactions: 2_000,
upstream: "healthy",
maxPhysicalRequestsPerInteraction: 2,
maxRetriesPerInteraction: 1,
});
expect(result.succeeded).toBe(2_000);
expect(requestAmplification(result)).toBe(1);
}, 60_000);
});
describe("partial outage", () => {
it("lets healthy contexts complete while one context fails completely", async () => {
const transports = {
payment: upstream("always-fail"),
order: upstream("healthy"),
catalog: upstream("healthy"),
};
const executors = Object.fromEntries(
Object.entries(transports).map(([contextId, transport]) => [
contextId,
testExecutor(transport, { maxRetryAttempts: 2 }),
]),
) as Record<keyof typeof transports, ReturnType<typeof testExecutor>>;
const successes: Record<string, number> = { payment: 0, order: 0, catalog: 0 };
await Promise.all(
Array.from({ length: 300 }, async (_, index) => {
const contextId = (["payment", "order", "catalog"] as const)[index % 3] as
| "payment"
| "order"
| "catalog";
const execution = testExecutionContext({ maxPhysicalRequests: 2, maxRetries: 1 });
const outcome = await executors[contextId].execute(TEST_QUERY, { limit: 1 }, {
routeId: "TEST_ROUTE",
scope: scopeSnapshot(),
execution,
});
if (outcome.kind === "SUCCESS") successes[contextId] = (successes[contextId] ?? 0) + 1;
}),
);
expect(successes).toEqual({ payment: 0, order: 100, catalog: 100 });
expect(transports.payment.calls).toBeLessThanOrEqual(200);
expect(transports.order.calls).toBe(100);
expect(transports.catalog.calls).toBe(100);
});
});
describe("slow upstream", () => {
it("bounds active and queued work, drains waiters at the deadline, and never retries after it", async () => {
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
const clock = manualClock(0);
let active = 0;
let peakActive = 0;
let calls = 0;
const transport: Transport = (_input, init) => {
calls += 1;
active += 1;
peakActive = Math.max(peakActive, active);
return new Promise<Response>((_resolve, reject) => {
init?.signal?.addEventListener(
"abort",
() => {
active -= 1;
reject(new DOMException("aborted", "AbortError"));
},
{ once: true },
);
});
};
const execution = testExecutionContext({
deadlineMs: 1_000,
maxPhysicalRequests: 20,
maxRetries: 5,
maxConcurrentRequests: 2,
maxQueuedRequests: 3,
clock: clock.now,
});
const executor = testExecutor(transport, { monotonicNow: clock.now });
const context = { routeId: "TEST_ROUTE", scope: scopeSnapshot(), execution };
const pending = Array.from({ length: 10 }, () =>
executor.execute(TEST_QUERY, { limit: 1 }, context),
);
await vi.advanceTimersByTimeAsync(0);
expect(execution.traffic.concurrency.active).toBe(2);
expect(execution.traffic.concurrency.queued).toBe(3);
clock.advance(1_000);
await vi.advanceTimersByTimeAsync(1_000);
const outcomes = await Promise.all(pending);
expect(peakActive).toBeLessThanOrEqual(2);
expect(execution.traffic.concurrency.active).toBe(0);
expect(execution.traffic.concurrency.queued).toBe(0);
expect(calls).toBe(2);
expect(execution.traffic.retries.consumed).toBe(0);
expect(
outcomes.filter(
(outcome) =>
outcome.kind === "TRANSPORT_FAILURE" &&
outcome.failure.kind === "OVERLOADED_BEFORE_SEND",
),
).toHaveLength(5);
expect(
outcomes.filter(
(outcome) =>
outcome.kind === "TRANSPORT_FAILURE" && outcome.failure.kind === "TIMEOUT",
),
).toHaveLength(5);
});
});
@@ -0,0 +1,73 @@
import { describe, expect, it } from "vitest";
import { retryDelayFor } from "../../../src/adapters/http/http-retry-lifecycle.ts";
/** Deterministic per-client PRNG (mulberry32), seeded by client index. */
function seededRandom(seed: number): () => number {
let state = seed >>> 0;
return () => {
state = (state + 0x6d2b79f5) >>> 0;
let value = state;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4_294_967_296;
};
}
function calculateRetryDelay(
options: Readonly<{ retryAfterMs: number; jitterSeed: number; attempt: number }>,
): number {
const delay = retryDelayFor(
options.retryAfterMs,
options.attempt - 1,
seededRandom(options.jitterSeed),
);
if (delay === null) throw new Error("Retry-After above the ceiling is not retried");
return delay;
}
describe("Retry-After jitter distribution", () => {
it("spreads retries around Retry-After instead of synchronizing all clients", () => {
const delays = Array.from({ length: 10_000 }, (_, seed) =>
calculateRetryDelay({
retryAfterMs: 3_000,
jitterSeed: seed,
attempt: 1,
}),
);
expect(new Set(delays).size).toBeGreaterThan(100);
expect(Math.max(...delays) - Math.min(...delays)).toBeGreaterThan(500);
});
it("never retries earlier than the server asked", () => {
for (let seed = 0; seed < 1_000; seed += 1) {
expect(
calculateRetryDelay({ retryAfterMs: 1_000, jitterSeed: seed, attempt: 1 }),
).toBeGreaterThanOrEqual(1_000);
}
});
it("keeps the jitter window bounded", () => {
const delays = Array.from({ length: 5_000 }, (_, seed) =>
calculateRetryDelay({ retryAfterMs: 5_000, jitterSeed: seed, attempt: 3 }),
);
expect(Math.max(...delays)).toBeLessThan(5_000 + 2_000);
});
it("spreads a cohort into many small buckets rather than one spike", () => {
const perBucket = new Map<number, number>();
for (let seed = 0; seed < 10_000; seed += 1) {
const bucket = Math.floor(
calculateRetryDelay({ retryAfterMs: 3_000, jitterSeed: seed, attempt: 1 }) / 50,
);
perBucket.set(bucket, (perBucket.get(bucket) ?? 0) + 1);
}
// No 50ms slice receives more than ~10% of the cohort.
expect(Math.max(...perBucket.values())).toBeLessThan(1_000);
});
it("does not retry when Retry-After exceeds the ceiling", () => {
expect(retryDelayFor(10_000, 0, () => 0.5)).toBeNull();
});
});
+92
View File
@@ -0,0 +1,92 @@
import type { InstalledHttpContract } from "../../../src/contracts/external-contract-runtime.ts";
import { TEST_LIST_HTTP_CONTRACT } from "../../helpers/external-contract-fixture.ts";
import {
jsonRows,
networkFailure,
scopeSnapshot,
testExecutionContext,
testExecutor,
type Transport,
} from "../../helpers/traffic-test-kit.ts";
export const TEST_QUERY = TEST_LIST_HTTP_CONTRACT as InstalledHttpContract<
unknown,
unknown,
unknown
>;
export type UpstreamMode = "always-fail" | "healthy" | "fail-first";
export function upstream(mode: UpstreamMode): Transport & { calls: number } {
let seen = 0;
const transport = (async () => {
transport.calls += 1;
seen += 1;
if (mode === "always-fail") return networkFailure();
if (mode === "fail-first" && seen % 2 === 1) return networkFailure();
return jsonRows(1);
}) as unknown as Transport & { calls: number };
transport.calls = 0;
return transport;
}
export type SyntheticTrafficResult = Readonly<{
interactions: number;
physicalRequests: number;
initialRequests: number;
succeeded: number;
failed: number;
}>;
/**
* Spec §32 / §42. Drives many independent interactions through the real V3
* executor, each with its own interaction budget, and counts physical
* dispatches at the transport.
*/
export async function runSyntheticTraffic(
options: Readonly<{
interactions: number;
upstream: UpstreamMode;
maxPhysicalRequestsPerInteraction: number;
maxRetriesPerInteraction: number;
operationsPerInteraction?: number;
batchSize?: number;
}>,
): Promise<SyntheticTrafficResult> {
const transport = upstream(options.upstream);
const executor = testExecutor(transport, { maxRetryAttempts: 2 });
const operations = options.operationsPerInteraction ?? 1;
const batchSize = options.batchSize ?? 500;
let succeeded = 0;
let failed = 0;
for (let start = 0; start < options.interactions; start += batchSize) {
const size = Math.min(batchSize, options.interactions - start);
const outcomes = await Promise.all(
Array.from({ length: size }, async () => {
const execution = testExecutionContext({
maxPhysicalRequests: options.maxPhysicalRequestsPerInteraction,
maxRetries: options.maxRetriesPerInteraction,
maxConcurrentRequests: 2,
maxQueuedRequests: 8,
});
const context = { routeId: "TEST_ROUTE", scope: scopeSnapshot(), execution };
return Promise.all(
Array.from({ length: operations }, () =>
executor.execute(TEST_QUERY, { limit: 1 }, context),
),
);
}),
);
for (const outcome of outcomes.flat()) {
if (outcome.kind === "SUCCESS") succeeded += 1;
else failed += 1;
}
}
return Object.freeze({
interactions: options.interactions,
physicalRequests: transport.calls,
initialRequests: options.interactions * operations,
succeeded,
failed,
});
}