import { describe, expect, it } from "vitest"; 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("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"); }); // 07-06 (MX2). V2 rows look mappers up by `mapperId`; a registry key that // differs would install a mapper no operation can reach. it("rejects a registry key that is not the mapper's own id", () => { const mapper = { mapperId: "ResourceMapper", mapperVersion: 1, inputSchemaId: "ResourcePayload", outputContractId: "Resource", owner: "test", maxOutputItems: 1, map: (input: unknown) => mappingSuccess(input), }; expect(() => composeBoundaryMapperRegistry([{ OtherMapper: mapper }]), ).toThrow("Invalid or duplicate boundary mapper: OtherMapper"); expect( Object.keys(composeBoundaryMapperRegistry([{ ResourceMapper: mapper }])), ).toEqual(["ResourceMapper"]); }); 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")); }); });