D-15. `RuntimeValidator` and `MappingResult` in
external-contract-runtime.ts are the canonical validator protocol and
mapping result. The other shapes stay as public names over them:
- schema-registry.ts: `RuntimeSchemaCodec` is documented as the
registry adapter and gains `runtimeSchemaCodecFromValidator`.
- boundary-mapper.ts: the flat `{ ok: false, code }` result is named
`BoundaryMappingResult`; `MappingResult` stays as an alias, and
`toContractMappingResult` converts to the canonical shape.
The reference feature wrapped each zod schema twice (a RuntimeValidator
in the contract contribution and a separate `project`/`codec` in
reference-schemas.ts). It now has one `zodValidator`; the registry
codecs are a one-liner over it, and validateReferencePayload/Request
look up the codec with Object.hasOwn.
Verified: characterization test
tests/features/reference-feature/reference-validator-protocol.test.ts
passed before and after (array paths, dotted paths, codec ids,
SCHEMA_NOT_REGISTERED); adapter case added to boundary-mapper.test.ts;
gates green except the known removal-fixture test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { mapOperationPayload } from "../../src/adapters/http/resource-mapper.ts";
|
|
import {
|
|
composeBoundaryMapperRegistry,
|
|
mappingFailure,
|
|
mappingSuccess,
|
|
toContractMappingResult,
|
|
} from "../../src/contracts/boundary-mapper.ts";
|
|
import { mappingViolation } from "../../src/contracts/external-contract-runtime.ts";
|
|
|
|
describe("platform DTO mapper boundary", () => {
|
|
it("fails closed when no feature mapper was injected", () => {
|
|
expect(mapOperationPayload("UNKNOWN", {})).toEqual({
|
|
ok: false,
|
|
code: "MAPPING_INVARIANT_REJECTED",
|
|
});
|
|
});
|
|
|
|
it("rejects duplicate mapper contributions before installation", () => {
|
|
const mapper = {
|
|
mapperId: "ResourceMapper",
|
|
mapperVersion: 1,
|
|
inputSchemaId: "ResourcePayload",
|
|
outputContractId: "Resource",
|
|
owner: "test",
|
|
maxOutputItems: 1,
|
|
map: (input: unknown) => mappingSuccess(input),
|
|
};
|
|
expect(() =>
|
|
composeBoundaryMapperRegistry([
|
|
{ ResourceMapper: mapper },
|
|
{ ResourceMapper: mapper },
|
|
]),
|
|
).toThrow("duplicate boundary mapper");
|
|
});
|
|
|
|
it("adapts a boundary result to the canonical mapping result (D-15)", () => {
|
|
expect(toContractMappingResult(mappingSuccess(1))).toEqual({
|
|
ok: true,
|
|
value: 1,
|
|
});
|
|
expect(
|
|
toContractMappingResult(mappingFailure("UNSUPPORTED_WIRE_VALUE")),
|
|
).toEqual(mappingViolation("UNSUPPORTED_WIRE_VALUE"));
|
|
});
|
|
});
|