import { describe, expect, it } from "vitest"; import type { ApiOperation, RestOperationV2, } from "../../src/contracts/api-operations.ts"; import { INSTALLED_CONTRACT_CONTRIBUTIONS } from "../../src/features/installed-contract-contributions.ts"; import { API_OPERATIONS } from "../../src/features/installed-feature-contracts.ts"; // 07-03 (D-7). FE-REG-API governs the V2 rows while the V3 descriptors are // what executes. Until V2 is generated from V3, both copies must agree. const RETRY_SEMANTICS_FOR_REPLAY_POLICY = Object.freeze({ SAFE: "SAFE", IDEMPOTENT: "IDEMPOTENT", KEYED_COMMAND: "KEYED", NON_REPLAYABLE: "NEVER", } as const); const v3ByOperationId = new Map( INSTALLED_CONTRACT_CONTRIBUTIONS.flatMap((contribution) => contribution.http.map( (descriptor) => [descriptor.contract.operationId, descriptor] as const, ), ), ); const v2Rows = (Object.values(API_OPERATIONS) as readonly ApiOperation[]).filter( (operation): operation is RestOperationV2 => operation.contractVersion === 2, ); describe("HTTP operation V2 rows and V3 descriptors", () => { it("declare the same method, path, statuses, limit, auth profile and replay policy", () => { for (const row of v2Rows) { const descriptor = v3ByOperationId.get(row.operationId); expect(descriptor, `${row.operationId} has no V3 descriptor`).toBeDefined(); if (!descriptor) continue; expect( { method: descriptor.contract.method, path: descriptor.contract.pathTemplate, successStatuses: [...descriptor.contract.acceptedStatuses], maxResponseBytes: descriptor.frontend.responseByteLimit, authProfileId: descriptor.frontend.authProfileId, retrySemantics: descriptor.contract.retrySemantics, }, row.operationId, ).toEqual({ method: row.method, path: row.path, successStatuses: [...row.successStatuses], maxResponseBytes: row.maxResponseBytes, authProfileId: row.authProfileId, retrySemantics: RETRY_SEMANTICS_FOR_REPLAY_POLICY[row.replayPolicy], }); } }); });