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)
166 lines
5.4 KiB
TypeScript
166 lines
5.4 KiB
TypeScript
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);
|
|
});
|
|
});
|