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)
351 lines
11 KiB
TypeScript
351 lines
11 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createContractHttpExecutor } from "../../src/adapters/http/http-execution-v3.ts";
|
|
import type {
|
|
HttpExecutionObservation,
|
|
} from "../../src/adapters/http/http-execution-v3.ts";
|
|
import { createHttpObservationProjector } from "../../src/bootstrap/runtime-adapters.ts";
|
|
import {
|
|
DIAGNOSTIC_CONTEXT_ALLOWLIST,
|
|
projectDiagnosticRecord,
|
|
type DiagnosticRecordInput,
|
|
} from "../../src/contracts/diagnostics.ts";
|
|
import {
|
|
projectTelemetryEvent,
|
|
type TelemetryEventName,
|
|
} from "../../src/contracts/telemetry.ts";
|
|
import {
|
|
TEST_CREATE_HTTP_CONTRACT,
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
} from "../helpers/external-contract-fixture.ts";
|
|
|
|
const ROUTE_ID = "TEST_ROUTE";
|
|
|
|
function scopeSnapshot(isCurrent: () => boolean = () => true) {
|
|
return Object.freeze({
|
|
generation: 1,
|
|
fingerprint: "scope-1",
|
|
identities: Object.freeze({}) as never,
|
|
signal: new AbortController().signal,
|
|
isCurrent,
|
|
});
|
|
}
|
|
|
|
type RecordedDiagnostic = DiagnosticRecordInput;
|
|
type RecordedTelemetry = Readonly<{
|
|
eventName: TelemetryEventName;
|
|
attributes: Readonly<Record<string, unknown>>;
|
|
}>;
|
|
|
|
function recordingSinks() {
|
|
const diagnostics: RecordedDiagnostic[] = [];
|
|
const telemetry: RecordedTelemetry[] = [];
|
|
return {
|
|
diagnostics,
|
|
telemetry,
|
|
projector: createHttpObservationProjector({
|
|
diagnostics: {
|
|
record(input: DiagnosticRecordInput) {
|
|
diagnostics.push(input);
|
|
},
|
|
},
|
|
telemetry: {
|
|
emit(
|
|
eventName: TelemetryEventName,
|
|
attributes: Record<string, unknown>,
|
|
) {
|
|
telemetry.push(Object.freeze({ eventName, attributes }));
|
|
},
|
|
},
|
|
}),
|
|
};
|
|
}
|
|
|
|
describe("V3 HTTP observability projection", () => {
|
|
it("projects every V3 terminal outcome through the closed diagnostics allowlist", async () => {
|
|
const sinks = recordingSinks();
|
|
|
|
const cases: readonly Readonly<{
|
|
label: string;
|
|
fetcher: typeof fetch;
|
|
}>[] = [
|
|
{
|
|
label: "SUCCESS",
|
|
fetcher: (async () =>
|
|
Response.json([{ id: "a", name: "A" }])) as unknown as typeof fetch,
|
|
},
|
|
{
|
|
label: "PROBLEM",
|
|
fetcher: (async () =>
|
|
Response.json(
|
|
{ type: "about:blank", title: "nope", status: 400 },
|
|
{ status: 400 },
|
|
)) as unknown as typeof fetch,
|
|
},
|
|
{
|
|
label: "TRANSPORT_FAILURE",
|
|
fetcher: (async () => {
|
|
throw new TypeError("network down");
|
|
}) as unknown as typeof fetch,
|
|
},
|
|
{
|
|
label: "CONTRACT_VIOLATION",
|
|
fetcher: (async () =>
|
|
new Response("<html/>", {
|
|
status: 200,
|
|
headers: { "content-type": "text/html" },
|
|
})) as unknown as typeof fetch,
|
|
},
|
|
];
|
|
|
|
for (const testCase of cases) {
|
|
const executor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({
|
|
kind: "READY" as const,
|
|
headers: {},
|
|
}),
|
|
fetcher: testCase.fetcher,
|
|
observe: sinks.projector,
|
|
});
|
|
await executor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
}
|
|
|
|
expect(sinks.diagnostics).toHaveLength(cases.length);
|
|
for (const recorded of sinks.diagnostics) {
|
|
expect(recorded.eventId).toBe("http.request.completed");
|
|
const contextKeys = Object.keys(recorded.context ?? {});
|
|
expect(contextKeys).toEqual(
|
|
expect.arrayContaining([
|
|
"route_id",
|
|
"operation_id",
|
|
"operation",
|
|
"outcome",
|
|
"error_kind",
|
|
"http_status_group",
|
|
"attempt_count_bucket",
|
|
"duration_bucket",
|
|
]),
|
|
);
|
|
for (const key of contextKeys) {
|
|
expect(DIAGNOSTIC_CONTEXT_ALLOWLIST).toContain(key);
|
|
}
|
|
expect(contextKeys).not.toContain("attempts");
|
|
expect(contextKeys).not.toContain("certainty");
|
|
const projection = projectDiagnosticRecord(recorded);
|
|
expect(projection.success).toBe(true);
|
|
}
|
|
});
|
|
|
|
it("emits one failure telemetry event for a non-abort terminal failure", async () => {
|
|
const sinks = recordingSinks();
|
|
const executor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({
|
|
kind: "READY" as const,
|
|
headers: {},
|
|
}),
|
|
fetcher: (async () => {
|
|
throw new TypeError("network down");
|
|
}) as unknown as typeof fetch,
|
|
observe: sinks.projector,
|
|
});
|
|
|
|
const outcome = await executor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
|
|
expect(outcome.kind).toBe("TRANSPORT_FAILURE");
|
|
expect(sinks.telemetry).toHaveLength(1);
|
|
const emitted = sinks.telemetry[0];
|
|
expect(emitted?.eventName).toBe("api.request.failed");
|
|
expect(emitted?.attributes).toMatchObject({
|
|
route_id: ROUTE_ID,
|
|
operation_id: "TEST_LIST_ENTITIES",
|
|
error_kind: "NETWORK_FAILURE",
|
|
http_status_group: "none",
|
|
attempt_count_bucket: "1",
|
|
});
|
|
const projected = projectTelemetryEvent(
|
|
emitted?.eventName ?? "api.request.failed",
|
|
emitted?.attributes ?? {},
|
|
);
|
|
expect(projected.success).toBe(true);
|
|
expect(sinks.diagnostics).toHaveLength(1);
|
|
});
|
|
|
|
it("records the correlation id in diagnostics only (03-03)", async () => {
|
|
const sinks = recordingSinks();
|
|
const executor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({ kind: "READY" as const, headers: {} }),
|
|
fetcher: (async () =>
|
|
new Response(null, {
|
|
status: 503,
|
|
headers: { "x-correlation-id": "server-ref-7" },
|
|
})) as unknown as typeof fetch,
|
|
observe: sinks.projector,
|
|
});
|
|
|
|
await executor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
|
|
expect(sinks.diagnostics[0]?.context).toMatchObject({
|
|
correlation_id: "server-ref-7",
|
|
});
|
|
expect(projectDiagnosticRecord(sinks.diagnostics[0]!).success).toBe(true);
|
|
expect(sinks.telemetry).toHaveLength(1);
|
|
expect(JSON.stringify(sinks.telemetry)).not.toContain("server-ref-7");
|
|
});
|
|
|
|
it("keeps a never-sent unauthenticated request out of telemetry (03-07)", async () => {
|
|
const sinks = recordingSinks();
|
|
const fetcher = vi.fn();
|
|
const executor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({ kind: "UNAUTHENTICATED" as const }),
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
observe: sinks.projector,
|
|
});
|
|
|
|
const outcome = await executor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
|
|
expect(outcome.kind).toBe("UNAUTHENTICATED");
|
|
expect(fetcher).not.toHaveBeenCalled();
|
|
expect(sinks.diagnostics).toHaveLength(1);
|
|
expect(sinks.telemetry).toHaveLength(0);
|
|
|
|
// A server 401 is still an API failure.
|
|
const answered = recordingSinks();
|
|
await createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({ kind: "READY" as const, headers: {} }),
|
|
fetcher: (async () => new Response(null, { status: 401 })) as unknown as typeof fetch,
|
|
observe: answered.projector,
|
|
}).execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot() },
|
|
);
|
|
expect(answered.telemetry).toHaveLength(1);
|
|
});
|
|
|
|
it("does not emit failure telemetry for caller cancellation or scope fencing", async () => {
|
|
const cancelled = recordingSinks();
|
|
const callerController = new AbortController();
|
|
callerController.abort();
|
|
const cancelledExecutor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({
|
|
kind: "READY" as const,
|
|
headers: {},
|
|
}),
|
|
fetcher: (async () =>
|
|
Response.json([{ id: "a", name: "A" }])) as unknown as typeof fetch,
|
|
observe: cancelled.projector,
|
|
});
|
|
const cancelledOutcome = await cancelledExecutor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
signal: callerController.signal,
|
|
},
|
|
);
|
|
expect(cancelledOutcome.kind).toBe("CANCELLED");
|
|
expect(cancelled.diagnostics).toHaveLength(1);
|
|
expect(cancelled.telemetry).toHaveLength(0);
|
|
|
|
const fenced = recordingSinks();
|
|
const fencedExecutor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({
|
|
kind: "READY" as const,
|
|
headers: {},
|
|
}),
|
|
fetcher: (async () =>
|
|
Response.json([{ id: "a", name: "A" }])) as unknown as typeof fetch,
|
|
observe: fenced.projector,
|
|
});
|
|
const fencedOutcome = await fencedExecutor.execute(
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
{ limit: 5 },
|
|
{ routeId: ROUTE_ID, scope: scopeSnapshot(() => false) },
|
|
);
|
|
expect(fencedOutcome.kind).toBe("CONTRACT_VIOLATION");
|
|
expect(fenced.diagnostics).toHaveLength(1);
|
|
expect(fenced.telemetry).toHaveLength(0);
|
|
});
|
|
|
|
it("cannot change the HTTP result when diagnostics or telemetry throws", async () => {
|
|
const projector = createHttpObservationProjector({
|
|
diagnostics: {
|
|
record() {
|
|
throw new Error("diagnostics sink exploded");
|
|
},
|
|
},
|
|
telemetry: {
|
|
emit() {
|
|
throw new Error("telemetry sink exploded");
|
|
},
|
|
},
|
|
});
|
|
const observe = vi.fn((observation: HttpExecutionObservation) => {
|
|
projector(observation);
|
|
});
|
|
const executor = createContractHttpExecutor({
|
|
baseUrl: "https://api.example/",
|
|
maxRetryAttempts: 0,
|
|
attachCredentials: () => ({
|
|
kind: "READY" as const,
|
|
headers: {},
|
|
}),
|
|
fetcher: (async () =>
|
|
Response.json({ id: "created", name: "Created" }, {
|
|
status: 201,
|
|
})) as unknown as typeof fetch,
|
|
observe,
|
|
});
|
|
|
|
const outcome = await executor.execute(
|
|
TEST_CREATE_HTTP_CONTRACT,
|
|
{ name: "Created" },
|
|
{
|
|
routeId: ROUTE_ID,
|
|
scope: scopeSnapshot(),
|
|
intent: Object.freeze({
|
|
intentId: "intent-1",
|
|
operationId: "TEST_CREATE_ENTITY",
|
|
canonicalInputIdentity: "opaque-input-identity",
|
|
idempotencyKey: "key-1",
|
|
createdAtMonotonicMs: 1,
|
|
}),
|
|
},
|
|
);
|
|
|
|
expect(outcome.kind).toBe("SUCCESS");
|
|
expect(observe).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|