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)
245 lines
7.7 KiB
TypeScript
245 lines
7.7 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import type { InstalledHttpContract } from "../../../src/contracts/external-contract-runtime.ts";
|
|
import {
|
|
TEST_CREATE_HTTP_CONTRACT,
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
} from "../../helpers/external-contract-fixture.ts";
|
|
import {
|
|
jsonRows,
|
|
manualClock,
|
|
networkFailure,
|
|
scopeSnapshot,
|
|
testExecutionContext,
|
|
testExecutor,
|
|
type Transport,
|
|
} from "../../helpers/traffic-test-kit.ts";
|
|
|
|
const TEST_QUERY = TEST_LIST_HTTP_CONTRACT as InstalledHttpContract<
|
|
unknown,
|
|
unknown,
|
|
unknown
|
|
>;
|
|
const TEST_COMMAND = TEST_CREATE_HTTP_CONTRACT as InstalledHttpContract<
|
|
unknown,
|
|
unknown,
|
|
unknown
|
|
>;
|
|
const ROUTE_ID = "TEST_ROUTE";
|
|
|
|
/** A transport that only ever ends when its request is aborted. */
|
|
function hangingTransport(): Transport & { calls: number } {
|
|
const transport = ((_input: RequestInfo | URL, init?: RequestInit) => {
|
|
transport.calls += 1;
|
|
return new Promise<Response>((_resolve, reject) => {
|
|
init?.signal?.addEventListener(
|
|
"abort",
|
|
() => reject(new DOMException("aborted", "AbortError")),
|
|
{ once: true },
|
|
);
|
|
});
|
|
}) as Transport & { calls: number };
|
|
transport.calls = 0;
|
|
return transport;
|
|
}
|
|
|
|
describe("HTTP dispatch under interaction traffic budgets", () => {
|
|
it("does not dispatch after the interaction physical-request budget is exhausted", async () => {
|
|
const transport = vi.fn<Transport>(networkFailure);
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 1,
|
|
maxRetries: 3,
|
|
});
|
|
|
|
const outcome = await testExecutor(transport).execute(TEST_QUERY, { limit: 5 }, {
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
execution,
|
|
});
|
|
|
|
expect(outcome.kind).toBe("TRANSPORT_FAILURE");
|
|
expect(transport).toHaveBeenCalledTimes(1);
|
|
expect(execution.traffic.requests.consumed).toBe(1);
|
|
});
|
|
|
|
it("rejects a second operation once the shared request budget is gone", async () => {
|
|
const transport = vi.fn<Transport>(networkFailure);
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 1,
|
|
maxRetries: 0,
|
|
});
|
|
const executor = testExecutor(transport);
|
|
const context = { routeId: ROUTE_ID, scope: scopeSnapshot(), execution };
|
|
|
|
await executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
const second = await executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
|
|
expect(second).toMatchObject({
|
|
kind: "TRANSPORT_FAILURE",
|
|
failure: { kind: "OVERLOADED_BEFORE_SEND" },
|
|
});
|
|
expect(transport).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("shares one retry budget across independent failing operations", async () => {
|
|
const transport = vi.fn<Transport>(networkFailure);
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 10,
|
|
maxRetries: 1,
|
|
});
|
|
const executor = testExecutor(transport);
|
|
const context = { routeId: ROUTE_ID, scope: scopeSnapshot(), execution };
|
|
|
|
await executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
await executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
|
|
// First operation: attempt + its one shared retry. Second: attempt only.
|
|
expect(transport).toHaveBeenCalledTimes(3);
|
|
expect(execution.traffic.retries.consumed).toBe(1);
|
|
});
|
|
|
|
it("does not reset the interaction deadline before retry", async () => {
|
|
const clock = manualClock(0);
|
|
const execution = testExecutionContext({
|
|
deadlineMs: 5_000,
|
|
maxPhysicalRequests: 4,
|
|
maxRetries: 3,
|
|
clock: clock.now,
|
|
});
|
|
const transport = vi.fn<Transport>(() => {
|
|
clock.advance(5_001);
|
|
return networkFailure();
|
|
});
|
|
|
|
const outcome = await testExecutor(transport).execute(TEST_QUERY, { limit: 5 }, {
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
execution,
|
|
});
|
|
|
|
expect(outcome.kind).toBe("TRANSPORT_FAILURE");
|
|
expect(transport).toHaveBeenCalledTimes(1);
|
|
expect(execution.traffic.retries.consumed).toBe(0);
|
|
});
|
|
|
|
it("gives a late operation only the interaction's remaining deadline", async () => {
|
|
const clock = manualClock(0);
|
|
const execution = testExecutionContext({
|
|
deadlineMs: 1_000,
|
|
clock: clock.now,
|
|
});
|
|
clock.advance(1_000);
|
|
const transport = vi.fn<Transport>(async () => jsonRows(1));
|
|
|
|
const outcome = await testExecutor(transport).execute(TEST_QUERY, { limit: 5 }, {
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
execution,
|
|
});
|
|
|
|
expect(outcome).toMatchObject({
|
|
kind: "TRANSPORT_FAILURE",
|
|
failure: { kind: "TIMEOUT" },
|
|
});
|
|
expect(transport).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects instead of queueing beyond the interaction queue bound", async () => {
|
|
const transport = hangingTransport();
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 10,
|
|
maxConcurrentRequests: 1,
|
|
maxQueuedRequests: 0,
|
|
});
|
|
const executor = testExecutor(transport);
|
|
const context = { routeId: ROUTE_ID, scope: scopeSnapshot(), execution };
|
|
|
|
const first = executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
await vi.waitFor(() => expect(transport.calls).toBe(1));
|
|
const second = await executor.execute(TEST_QUERY, { limit: 5 }, context);
|
|
|
|
expect(second).toMatchObject({
|
|
kind: "TRANSPORT_FAILURE",
|
|
failure: { kind: "OVERLOADED_BEFORE_SEND" },
|
|
});
|
|
execution.cancellation.cancel();
|
|
await expect(first).resolves.toMatchObject({ kind: "CANCELLED" });
|
|
expect(transport.calls).toBe(1);
|
|
});
|
|
|
|
it("releases every lease and waiting entry when the interaction is aborted", async () => {
|
|
const transport = hangingTransport();
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 10,
|
|
maxConcurrentRequests: 1,
|
|
maxQueuedRequests: 2,
|
|
});
|
|
const executor = testExecutor(transport);
|
|
const context = { routeId: ROUTE_ID, scope: scopeSnapshot(), execution };
|
|
|
|
const running = [1, 2, 3].map(() =>
|
|
executor.execute(TEST_QUERY, { limit: 5 }, context),
|
|
);
|
|
await vi.waitFor(() => {
|
|
expect(execution.traffic.concurrency.active).toBe(1);
|
|
expect(execution.traffic.concurrency.queued).toBe(2);
|
|
});
|
|
|
|
execution.cancellation.cancel();
|
|
const outcomes = await Promise.all(running);
|
|
|
|
expect(outcomes.map((outcome) => outcome.kind)).toEqual([
|
|
"CANCELLED",
|
|
"CANCELLED",
|
|
"CANCELLED",
|
|
]);
|
|
expect(execution.traffic.concurrency.active).toBe(0);
|
|
expect(execution.traffic.concurrency.queued).toBe(0);
|
|
expect(transport.calls).toBe(1);
|
|
});
|
|
|
|
it("keeps KEYED command replay safety even when the budget allows retries", async () => {
|
|
const transport = vi.fn<Transport>(networkFailure);
|
|
const execution = testExecutionContext({
|
|
maxPhysicalRequests: 10,
|
|
maxRetries: 5,
|
|
});
|
|
|
|
const outcome = await testExecutor(transport).execute(
|
|
TEST_COMMAND,
|
|
{ name: "entity" },
|
|
{
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
execution,
|
|
intent: Object.freeze({
|
|
intentId: "intent-1",
|
|
operationId: "TEST_CREATE_ENTITY",
|
|
canonicalInputIdentity: "opaque",
|
|
idempotencyKey: "key-1",
|
|
createdAtMonotonicMs: 1,
|
|
}),
|
|
},
|
|
);
|
|
|
|
expect(outcome).toMatchObject({
|
|
kind: "TRANSPORT_FAILURE",
|
|
effect: "MAYBE_APPLIED",
|
|
});
|
|
expect(transport).toHaveBeenCalledTimes(1);
|
|
expect(execution.traffic.retries.consumed).toBe(0);
|
|
});
|
|
|
|
it("bounds an execution without an explicit interaction by the default policy", async () => {
|
|
const transport = vi.fn<Transport>(networkFailure);
|
|
|
|
await testExecutor(transport, { maxRetryAttempts: 2 }).execute(
|
|
TEST_QUERY,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
|
|
expect(transport).toHaveBeenCalledTimes(3);
|
|
});
|
|
});
|