diff --git a/tests/unit/api-operation-v2.test.ts b/tests/unit/api-operation-v2.test.ts index 21e8f502..86552fd7 100644 --- a/tests/unit/api-operation-v2.test.ts +++ b/tests/unit/api-operation-v2.test.ts @@ -57,6 +57,15 @@ describe("REST operation v2 registry", () => { }), ).toThrow("Incoherent REST replay contract"); }); + + // 07-06 (MX5). A KEYED command without a required idempotency key would be + // resent with no key to bind the retry to. + it("rejects a KEYED_COMMAND whose idempotency key is not required", () => { + expect(() => + defineRestOperation({ ...command(), idempotencyKeyPolicy: "NONE" }), + ).toThrow("Incoherent REST replay contract: CREATE_RESOURCE"); + expect(defineRestOperation(command()).idempotencyKeyPolicy).toBe("REQUIRED"); + }); }); function command(): RestOperationV2 { diff --git a/tests/unit/boundary-mapper.test.ts b/tests/unit/boundary-mapper.test.ts index 6d3c6dc8..8fb4d4be 100644 --- a/tests/unit/boundary-mapper.test.ts +++ b/tests/unit/boundary-mapper.test.ts @@ -35,6 +35,26 @@ describe("platform DTO mapper boundary", () => { ).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, diff --git a/tests/unit/external-contract-runtime.test.ts b/tests/unit/external-contract-runtime.test.ts index c98b1348..cf0495a1 100644 --- a/tests/unit/external-contract-runtime.test.ts +++ b/tests/unit/external-contract-runtime.test.ts @@ -86,6 +86,57 @@ describe("external contract contribution composition", () => { }); }); +// 07-06 (MX1, MX9, MX6). The write-API rules the composer teaches through its +// error messages. TEST_CONTRACT_CONTRIBUTION composing in the first block is +// the valid control. +describe("write operation rules", () => { + const [listRow, , createRow] = TEST_CONTRACT_CONTRIBUTION.http as readonly [ + InstalledContractContribution["http"][number], + InstalledContractContribution["http"][number], + InstalledContractContribution["http"][number], + ]; + + function reasonFor(row: object): string { + return captureContributionError(() => + composeContractContributions([ + contribution("write-rule", [ + row as InstalledContractContribution["http"][number], + ]), + ]), + ).reason; + } + + // The executor decides "write" by `commandEffect !== null`, not by method, + // so this rule is the only thing keeping a GET from running as a command. + it("rejects command descriptors on a read operation", () => { + expect( + reasonFor({ + ...listRow, + contract: { ...listRow.contract, commandEffect: createRow.contract.commandEffect }, + }), + ).toBe("test-feature/TEST_LIST_ENTITIES: read operations carry no command descriptors"); + }); + + it("requires a recovery descriptor on a KEYED command", () => { + expect( + reasonFor({ + ...createRow, + contract: { ...createRow.contract, commandRecovery: null }, + }), + ).toBe("test-feature/TEST_CREATE_ENTITY: KEYED commands require a recovery descriptor"); + }); + + it("rejects a retry budget on a NEVER-retry operation", () => { + expect( + reasonFor({ + ...createRow, + contract: { ...createRow.contract, retrySemantics: "NEVER" }, + frontend: { ...createRow.frontend, retryBudget: 1 }, + }), + ).toBe("test-feature/TEST_CREATE_ENTITY: retry budget contradicts NEVER retry semantics"); + }); +}); + // The sample feature's own cases (its fixture composes, a second one does not) // live in tests/features so they leave with the sample. describe("template fixture provenance (07-04, ยง4.8)", () => {