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 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)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createFailure } from "../../../src/contracts/errors.ts";
|
||||
import { isAppError } from "../../../src/platform/errors/app-error.ts";
|
||||
import {
|
||||
REFERENCE_ERRORS,
|
||||
toReferenceError,
|
||||
type ReferenceError,
|
||||
} from "../../../src/features/reference-feature/application/reference-error.ts";
|
||||
|
||||
describe("reference feature-local errors", () => {
|
||||
it("keeps concrete error kinds feature-local", () => {
|
||||
const error: ReferenceError = {
|
||||
kind: "reference.not-found",
|
||||
category: "domain",
|
||||
severity: "warning",
|
||||
retryability: "never",
|
||||
};
|
||||
|
||||
expect(isAppError(error)).toBe(true);
|
||||
for (const known of Object.values(REFERENCE_ERRORS)) {
|
||||
expect(isAppError(known)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("interprets only its own domain outcomes", () => {
|
||||
expect(toReferenceError(createFailure("NOT_FOUND", "GET_REFERENCE_RESOURCE", 0))).toBe(
|
||||
REFERENCE_ERRORS.NOT_FOUND,
|
||||
);
|
||||
expect(toReferenceError(createFailure("CONFLICT", "CREATE_REFERENCE_RESOURCE", 0))).toBe(
|
||||
REFERENCE_ERRORS.CONFLICT,
|
||||
);
|
||||
expect(
|
||||
toReferenceError(createFailure("NETWORK_UNREACHABLE", "GET_REFERENCE_RESOURCE", 0)),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("is not referenced by any global or central error union", async () => {
|
||||
const offenders: string[] = [];
|
||||
const walk = async (directory: string): Promise<void> => {
|
||||
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
||||
const target = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (!target.endsWith(path.join("features", "reference-feature"))) {
|
||||
await walk(target);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!/\.tsx?$/u.test(entry.name)) continue;
|
||||
const source = await readFile(target, "utf8");
|
||||
if (/reference-error\.ts|ReferenceError\b(?!Boundary)/u.test(source)) {
|
||||
offenders.push(target);
|
||||
}
|
||||
}
|
||||
};
|
||||
await walk(path.resolve("src"));
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
createQueryClient,
|
||||
QUERY_CACHE_DEFAULTS,
|
||||
} from "../../../src/adapters/query-cache/tanstack-query-cache.ts";
|
||||
import {
|
||||
jsonRows,
|
||||
networkFailure,
|
||||
type Transport,
|
||||
} from "../../helpers/traffic-test-kit.ts";
|
||||
import { referenceFeatureOver } from "./reference-traffic-kit.ts";
|
||||
|
||||
/**
|
||||
* Spec §16. Multiple consumers of one query identity must not imply multiple
|
||||
* physical requests. TanStack Query owns in-flight coalescing; this suite pins
|
||||
* that the installed query client plus the real V3 executor keep it that way.
|
||||
*/
|
||||
describe("request deduplication and coalescing", () => {
|
||||
function loadSameQuery(
|
||||
client: ReturnType<typeof createQueryClient>,
|
||||
reference: ReturnType<typeof referenceFeatureOver>,
|
||||
key: readonly unknown[] = ["reference", "list", { limit: 20 }],
|
||||
) {
|
||||
return client.fetchQuery({
|
||||
queryKey: key,
|
||||
queryFn: ({ signal }) => reference.listResources({ limit: 20 }, { signal }),
|
||||
});
|
||||
}
|
||||
|
||||
it("coalesces concurrent consumers of the same query identity", async () => {
|
||||
const transport = vi.fn<Transport>(async () => jsonRows(3));
|
||||
const reference = referenceFeatureOver(transport);
|
||||
const client = createQueryClient();
|
||||
|
||||
const results = await Promise.all([
|
||||
loadSameQuery(client, reference),
|
||||
loadSameQuery(client, reference),
|
||||
loadSameQuery(client, reference),
|
||||
]);
|
||||
|
||||
expect(transport).toHaveBeenCalledTimes(1);
|
||||
expect(results.every((result) => result.ok)).toBe(true);
|
||||
client.clear();
|
||||
});
|
||||
|
||||
it("keeps distinct query identities as distinct physical requests", async () => {
|
||||
const transport = vi.fn<Transport>(async () => jsonRows(1));
|
||||
const reference = referenceFeatureOver(transport);
|
||||
const client = createQueryClient();
|
||||
|
||||
await Promise.all([
|
||||
loadSameQuery(client, reference, ["reference", "list", 1]),
|
||||
loadSameQuery(client, reference, ["reference", "list", 2]),
|
||||
]);
|
||||
|
||||
expect(transport).toHaveBeenCalledTimes(2);
|
||||
client.clear();
|
||||
});
|
||||
|
||||
it("does not stack a query-layer retry on top of the executor retry budget", async () => {
|
||||
expect(QUERY_CACHE_DEFAULTS.retry).toBe(false);
|
||||
expect(QUERY_CACHE_DEFAULTS.mutationRetry).toBe(false);
|
||||
|
||||
const transport = vi.fn<Transport>(networkFailure);
|
||||
const reference = referenceFeatureOver(transport, { maxRetryAttempts: 2 });
|
||||
const client = createQueryClient();
|
||||
|
||||
await Promise.all([
|
||||
loadSameQuery(client, reference),
|
||||
loadSameQuery(client, reference),
|
||||
]);
|
||||
|
||||
// One coalesced logical execution: 1 attempt + at most 2 executor retries.
|
||||
expect(transport.mock.calls.length).toBeLessThanOrEqual(3);
|
||||
client.clear();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
assertRequestFanoutWithinBudget,
|
||||
RequestFanoutExceededError,
|
||||
} from "../../../src/platform/traffic/request-fanout.ts";
|
||||
import {
|
||||
jsonRows,
|
||||
paginatedCollection,
|
||||
testExecutionContext,
|
||||
type Transport,
|
||||
} from "../../helpers/traffic-test-kit.ts";
|
||||
import { referenceFeatureOver } from "./reference-traffic-kit.ts";
|
||||
|
||||
/** Physical requests one representative collection load may cost. */
|
||||
const COLLECTION_LOAD_FANOUT_BUDGET = 1;
|
||||
|
||||
describe("request fan-out budget", () => {
|
||||
it.each([10, 50, 100, 1_000])(
|
||||
"loads the first page of a %i-row collection with one physical request",
|
||||
async (totalRows) => {
|
||||
const transport = paginatedCollection(totalRows);
|
||||
const reference = referenceFeatureOver(transport);
|
||||
|
||||
const result = await reference.listResources({ limit: 100 });
|
||||
|
||||
expect(result).toMatchObject({ ok: true });
|
||||
expect(result.ok && result.value).toHaveLength(Math.min(totalRows, 100));
|
||||
expect(() =>
|
||||
assertRequestFanoutWithinBudget(transport.calls, COLLECTION_LOAD_FANOUT_BUDGET),
|
||||
).not.toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
it("walks a 1,000-row collection in page-sized bulk requests, never one per row", async () => {
|
||||
const transport = paginatedCollection(1_000);
|
||||
const reference = referenceFeatureOver(transport);
|
||||
const rows: unknown[] = [];
|
||||
for (let cursor = 0; ; cursor += 100) {
|
||||
const page = await reference.listResources({
|
||||
limit: 100,
|
||||
...(cursor === 0 ? {} : { cursor: String(cursor) }),
|
||||
});
|
||||
expect(page.ok).toBe(true);
|
||||
if (!page.ok || page.value.length === 0) break;
|
||||
rows.push(...page.value);
|
||||
if (page.value.length < 100) break;
|
||||
}
|
||||
expect(rows).toHaveLength(1_000);
|
||||
// ceil(N / pageSize) + one empty terminal page, versus N per-row calls.
|
||||
expect(transport.calls).toBeLessThanOrEqual(Math.ceil(1_000 / 100) + 1);
|
||||
});
|
||||
|
||||
it("rejects a single oversized response in one request without row-proportional fan-out", async () => {
|
||||
const transport = vi.fn<Transport>(async () => jsonRows(1_000));
|
||||
const reference = referenceFeatureOver(transport);
|
||||
|
||||
const result = await reference.listResources({ limit: 100 });
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(transport).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("keeps a whole interaction's request count bounded while cardinality grows", async () => {
|
||||
const counts: number[] = [];
|
||||
for (const rows of [10, 100, 1_000]) {
|
||||
const transport = vi.fn<Transport>(paginatedCollection(rows));
|
||||
const reference = referenceFeatureOver(transport);
|
||||
const execution = testExecutionContext({ maxPhysicalRequests: 3 });
|
||||
await reference.listResources({ limit: 100 }, { execution });
|
||||
counts.push(transport.mock.calls.length);
|
||||
expect(execution.traffic.requests.consumed).toBe(transport.mock.calls.length);
|
||||
}
|
||||
expect(new Set(counts)).toEqual(new Set([1]));
|
||||
});
|
||||
|
||||
it("fails loudly when a flow exceeds its fan-out budget", () => {
|
||||
expect(() => assertRequestFanoutWithinBudget(4, 3)).toThrow(
|
||||
RequestFanoutExceededError,
|
||||
);
|
||||
expect(() => assertRequestFanoutWithinBudget(4, 3)).toThrow(
|
||||
/fan-out 4 exceeds 3/,
|
||||
);
|
||||
expect(() => assertRequestFanoutWithinBudget(1, 0)).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { DemoSessionAdapter } from "../../../src/adapters/auth/external-session-adapter.ts";
|
||||
import { createRuntimeAdapters } from "../../../src/bootstrap/runtime-adapters.ts";
|
||||
import { createRuntimeIdentityRegistry } from "../../../src/contracts/query-keys.ts";
|
||||
import { bindQuery } from "../../../src/contracts/server-state.ts";
|
||||
@@ -9,6 +10,41 @@ import {
|
||||
REFERENCE_RESOURCE_INVALIDATION_TOPIC,
|
||||
} from "../../../src/features/reference-feature/contracts/reference-feature-contract.ts";
|
||||
|
||||
// Template sync (af3d8e6). This product leaves the sample uninstalled
|
||||
// (src/features/reference-feature/NOT_INSTALLED): its feature-module.ts would
|
||||
// load the screens this product deleted. These tests exercise the production
|
||||
// graph with a real feature, so they install the sample themselves, the way
|
||||
// the template's platform tests install their test-only feature: through the
|
||||
// generated index, with the upstream descriptor minus its route runtime.
|
||||
vi.mock("../../../src/.generated/product-feature-index.ts", async () => {
|
||||
const { defineFeatureModule } = await import("../../../src/features/feature-module.ts");
|
||||
const { REFERENCE_FEATURE_ADAPTER_CONTRIBUTION } = await import(
|
||||
"../../../src/features/reference-feature/adapters/create-reference-feature-input.ts"
|
||||
);
|
||||
const { REFERENCE_FEATURE_CONTRACT } = await import(
|
||||
"../../../src/features/reference-feature/contracts/reference-feature-contract.ts"
|
||||
);
|
||||
const { REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION } = await import(
|
||||
"../../../src/features/reference-feature/contracts/reference-feature-contract-contribution.ts"
|
||||
);
|
||||
const { REFERENCE_MESSAGE_CATALOGS } = await import(
|
||||
"../../../src/features/reference-feature/contracts/reference-message-catalog.ts"
|
||||
);
|
||||
const module = defineFeatureModule({
|
||||
id: REFERENCE_FEATURE_CONTRACT.featureId,
|
||||
contracts: REFERENCE_FEATURE_CONTRACT,
|
||||
routes: REFERENCE_FEATURE_CONTRACT.routes,
|
||||
adapters: [REFERENCE_FEATURE_ADAPTER_CONTRIBUTION],
|
||||
runtimes: [],
|
||||
messages: REFERENCE_MESSAGE_CATALOGS,
|
||||
contractContributions: [REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION],
|
||||
});
|
||||
return {
|
||||
DECLARED_PRODUCT_FEATURE_IDS: [module.id],
|
||||
PRODUCT_FEATURE_MODULES: [module],
|
||||
};
|
||||
});
|
||||
|
||||
type Runtime = Parameters<typeof createRuntimeAdapters>[0]["runtime"];
|
||||
type Release = Parameters<typeof createRuntimeAdapters>[0]["release"];
|
||||
|
||||
@@ -44,7 +80,7 @@ const runtime: Runtime = {
|
||||
|
||||
const release: Release = {
|
||||
schemaVersion: 2,
|
||||
appVersion: "0.1.0",
|
||||
appVersion: "0.2.0",
|
||||
buildId: "build-a",
|
||||
commitSha: "abc123",
|
||||
configSchemaVersion: "2.0",
|
||||
@@ -212,4 +248,59 @@ describe("reference feature runtime composition", () => {
|
||||
expect(safeEvidence).not.toContain("private-idempotency-key");
|
||||
adapters.infrastructure.dispose();
|
||||
});
|
||||
|
||||
/**
|
||||
* R-3.2. A request refused before dispatch because no credential exists is
|
||||
* not a session verdict. Reporting it to the owner overwrote a recovering
|
||||
* session and could loop through the scope fence; only a server 401 may.
|
||||
*/
|
||||
it("does not report a request refused before dispatch as a sign-out", async () => {
|
||||
const fetcher = vi.fn(async () => Response.json([]));
|
||||
const adapters = await createRuntimeAdapters({
|
||||
runtime,
|
||||
release,
|
||||
host: {},
|
||||
fetcher,
|
||||
});
|
||||
const session = adapters.outputPorts.session as DemoSessionAdapter;
|
||||
session.setState("recovery-pending");
|
||||
await vi.waitFor(() =>
|
||||
expect(adapters.infrastructure.serverStateScope.getPhase()).toBe("READY"),
|
||||
);
|
||||
const notifications = vi.fn();
|
||||
session.subscribe(notifications);
|
||||
|
||||
await expect(
|
||||
referenceInput(adapters).listResources({ limit: 20 }),
|
||||
).resolves.toMatchObject({ ok: false });
|
||||
|
||||
expect(fetcher).not.toHaveBeenCalled();
|
||||
expect(session.getState()).toBe("recovery-pending");
|
||||
expect(notifications).not.toHaveBeenCalled();
|
||||
adapters.infrastructure.dispose();
|
||||
});
|
||||
|
||||
it("still signs out when the server answers 401", async () => {
|
||||
const fetcher = vi.fn(
|
||||
async () => new Response(null, { status: 401 }),
|
||||
);
|
||||
const adapters = await createRuntimeAdapters({
|
||||
runtime,
|
||||
release,
|
||||
host: {},
|
||||
fetcher,
|
||||
});
|
||||
await adapters.outputPorts.session.beginSignIn();
|
||||
await vi.waitFor(() =>
|
||||
expect(adapters.infrastructure.serverStateScope.getPhase()).toBe("READY"),
|
||||
);
|
||||
|
||||
await expect(
|
||||
referenceInput(adapters).listResources({ limit: 20 }),
|
||||
).resolves.toMatchObject({ ok: false });
|
||||
|
||||
expect(fetcher).toHaveBeenCalledOnce();
|
||||
expect(adapters.outputPorts.session.getState()).toBe("unauthenticated");
|
||||
adapters.infrastructure.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createReferenceFeatureInput } from "../../../src/features/reference-feature/application/reference-feature-api.ts";
|
||||
import { createFailure } from "../../../src/contracts/errors.ts";
|
||||
import type { TelemetryPort } from "../../../src/platform/telemetry/telemetry-port.ts";
|
||||
import {
|
||||
createTelemetryPipeline,
|
||||
type TelemetryTransport,
|
||||
} from "../../../src/platform/telemetry/telemetry-pipeline.ts";
|
||||
import { REFERENCE_FEATURE_ADAPTER_CONTRIBUTION } from "../../../src/features/reference-feature/adapters/create-reference-feature-input.ts";
|
||||
|
||||
function failingGateway() {
|
||||
const failure = Object.freeze({
|
||||
ok: false as const,
|
||||
error: createFailure("REQUEST_TIMEOUT", "LIST_REFERENCE_RESOURCES", 0),
|
||||
});
|
||||
return Object.freeze({
|
||||
list: vi.fn(async () => failure),
|
||||
get: vi.fn(async () => failure),
|
||||
create: vi.fn(async () => failure),
|
||||
});
|
||||
}
|
||||
|
||||
describe("reference feature telemetry through the platform port", () => {
|
||||
it("declares the provider-neutral telemetry capability", () => {
|
||||
expect(REFERENCE_FEATURE_ADAPTER_CONTRIBUTION.needs).toContain("telemetry");
|
||||
});
|
||||
|
||||
it("emits a feature-owned event with a bounded payload on load failure", async () => {
|
||||
const emit = vi.fn<TelemetryPort["emit"]>();
|
||||
const input = createReferenceFeatureInput(failingGateway(), { telemetry: { emit } });
|
||||
|
||||
const result = await input.listResources({ limit: 20 });
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(emit).toHaveBeenCalledWith({
|
||||
kind: "reference.load.failed",
|
||||
severity: "warning",
|
||||
featureId: "reference-feature",
|
||||
payload: { operation: "list", reason: "REQUEST_TIMEOUT" },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns the business result even when the port throws or rejects", async () => {
|
||||
const throwing = createReferenceFeatureInput(failingGateway(), {
|
||||
telemetry: {
|
||||
emit() {
|
||||
throw new Error("port broken");
|
||||
},
|
||||
},
|
||||
});
|
||||
const rejecting = createReferenceFeatureInput(failingGateway(), {
|
||||
telemetry: { emit: () => Promise.reject(new Error("collector down")) },
|
||||
});
|
||||
|
||||
await expect(throwing.getResource("id-1")).resolves.toMatchObject({ ok: false });
|
||||
await expect(rejecting.getResource("id-1")).resolves.toMatchObject({ ok: false });
|
||||
});
|
||||
|
||||
it("collapses a failure storm into bounded sends via the pipeline", async () => {
|
||||
const send = vi.fn<TelemetryTransport["send"]>();
|
||||
const pipeline = createTelemetryPipeline({ transport: { send } });
|
||||
const input = createReferenceFeatureInput(failingGateway(), { telemetry: pipeline });
|
||||
|
||||
for (let i = 0; i < 500; i += 1) await input.listResources({ limit: 20 });
|
||||
await pipeline.flush();
|
||||
|
||||
// The first failure goes out at once; the 499 duplicates ride on the flush.
|
||||
expect(send).toHaveBeenCalledTimes(2);
|
||||
const occurrences = send.mock.calls
|
||||
.flatMap(([batch]) => batch)
|
||||
.reduce((sum, item) => sum + item.occurrences, 0);
|
||||
expect(occurrences).toBe(500);
|
||||
expect(pipeline.stats().deduplicated).toBe(499);
|
||||
pipeline.dispose();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { createReferenceFeatureInstalledInput } from "../../../src/features/reference-feature/adapters/create-reference-feature-input.ts";
|
||||
import {
|
||||
scopeSnapshot,
|
||||
testExecutor,
|
||||
type Transport,
|
||||
} from "../../helpers/traffic-test-kit.ts";
|
||||
|
||||
/**
|
||||
* The reference feature's real application input, wired to the real V3
|
||||
* executor over an injected transport. Used to prove collection loads and
|
||||
* multi-operation interactions stay bounded end to end.
|
||||
*/
|
||||
export function referenceFeatureOver(
|
||||
transport: Transport,
|
||||
options: Parameters<typeof testExecutor>[1] = {},
|
||||
) {
|
||||
const executor = testExecutor(transport, {
|
||||
credentialHeaders: { authorization: "Bearer traffic-test-token" },
|
||||
...options,
|
||||
});
|
||||
return createReferenceFeatureInstalledInput({
|
||||
http: Object.freeze({
|
||||
execute(operation, input, context) {
|
||||
return executor.execute(operation, input, {
|
||||
routeId: context.routeId,
|
||||
scope: scopeSnapshot(),
|
||||
...(context.signal === undefined ? {} : { signal: context.signal }),
|
||||
...(context.intent === undefined ? {} : { intent: context.intent }),
|
||||
...(context.execution === undefined
|
||||
? {}
|
||||
: { execution: context.execution }),
|
||||
});
|
||||
},
|
||||
}),
|
||||
}).input;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { composeContractContributions } from "../../../src/contracts/external-contract-runtime.ts";
|
||||
import { REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION } from "../../../src/features/reference-feature/contracts/reference-feature-contract-contribution.ts";
|
||||
|
||||
describe("reference operation traffic policy", () => {
|
||||
it("declares explicit bounded traffic on every representative reference operation", () => {
|
||||
const composed = composeContractContributions([
|
||||
REFERENCE_FEATURE_TEMPLATE_CONTRIBUTION,
|
||||
]);
|
||||
for (const operationId of [
|
||||
"LIST_REFERENCE_RESOURCES",
|
||||
"GET_REFERENCE_RESOURCE",
|
||||
"CREATE_REFERENCE_RESOURCE",
|
||||
]) {
|
||||
const traffic = composed.httpByOperationId.get(operationId)?.frontend.traffic;
|
||||
expect(traffic, operationId).toBeDefined();
|
||||
expect(Number.isSafeInteger(traffic?.maxPhysicalRequests)).toBe(true);
|
||||
}
|
||||
// A KEYED command never retries automatically; its policy says so too.
|
||||
expect(
|
||||
composed.httpByOperationId.get("CREATE_REFERENCE_RESOURCE")?.frontend
|
||||
.traffic,
|
||||
).toMatchObject({ maxPhysicalRequests: 1, maxRetries: 0 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CREATE_REFERENCE_RESOURCE_CONTRACT,
|
||||
LIST_REFERENCE_RESOURCES_CONTRACT,
|
||||
} from "../../../src/features/reference-feature/contracts/reference-feature-contract-contribution.ts";
|
||||
import {
|
||||
REFERENCE_RUNTIME_SCHEMA_CODECS,
|
||||
validateReferencePayload,
|
||||
validateReferenceRequest,
|
||||
} from "../../../src/features/reference-feature/contracts/reference-schemas.ts";
|
||||
|
||||
/**
|
||||
* Q-6.7-8 characterization. The reference feature exposes one schema through
|
||||
* two protocols: the canonical `RuntimeValidator` (array paths) for the HTTP
|
||||
* contract and the registry-facing `RuntimeSchemaCodec` (dotted paths). Both
|
||||
* must keep answering exactly this after they share one zod wrapper.
|
||||
*/
|
||||
describe("reference validator protocols", () => {
|
||||
const badList = [{ id: "unsafe", name: 42 }];
|
||||
|
||||
it("answers the canonical validator with array paths", () => {
|
||||
expect(
|
||||
LIST_REFERENCE_RESOURCES_CONTRACT.contract.outputValidator.safeParse(
|
||||
badList,
|
||||
),
|
||||
).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: [0, "name"], code: "invalid_type" }],
|
||||
});
|
||||
expect(
|
||||
CREATE_REFERENCE_RESOURCE_CONTRACT.contract.inputValidator.safeParse({
|
||||
name: " Example ",
|
||||
}),
|
||||
).toEqual({ success: true, data: { name: "Example" } });
|
||||
});
|
||||
|
||||
it("answers the schema codec with dotted paths", () => {
|
||||
const codecs = REFERENCE_RUNTIME_SCHEMA_CODECS;
|
||||
expect(codecs.ReferenceResourceListPayload.parse(badList)).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: "0.name", code: "invalid_type" }],
|
||||
});
|
||||
expect(
|
||||
codecs.CreateReferenceResourceCommand.parse({ name: "a", extra: 1 }),
|
||||
).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: "", code: "unrecognized_keys" }],
|
||||
});
|
||||
expect(
|
||||
codecs.ReferenceResourceListQuery.parse({ limit: "5", tags: "open" }),
|
||||
).toEqual({ success: true, data: { limit: 5, tags: ["open"] } });
|
||||
expect(Object.keys(codecs)).toEqual([
|
||||
"ReferenceResourceParams",
|
||||
"ReferenceResourceListQuery",
|
||||
"NoRequest",
|
||||
"CreateReferenceResourceCommand",
|
||||
"ReferenceResourceListPayload",
|
||||
"ReferenceResourcePayload",
|
||||
]);
|
||||
for (const [schemaId, codec] of Object.entries(codecs)) {
|
||||
expect(codec.schemaId).toBe(schemaId);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the payload and request lookups apart", () => {
|
||||
expect(validateReferencePayload("ReferenceResourceListPayload", badList))
|
||||
.toEqual({
|
||||
success: false,
|
||||
issues: [{ path: "0.name", code: "invalid_type" }],
|
||||
});
|
||||
expect(validateReferencePayload("NoRequest", {})).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: "", code: "SCHEMA_NOT_REGISTERED" }],
|
||||
});
|
||||
expect(
|
||||
validateReferenceRequest("CreateReferenceResourceCommand", {
|
||||
name: " Example ",
|
||||
}),
|
||||
).toEqual({ success: true, data: { name: "Example" } });
|
||||
expect(
|
||||
validateReferenceRequest("ReferenceResourcePayload", {}),
|
||||
).toEqual({
|
||||
success: false,
|
||||
issues: [{ path: "", code: "SCHEMA_NOT_REGISTERED" }],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user