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")); }); });