diff --git a/docs/testing/frontend-platform-testing-strategy.md b/docs/testing/frontend-platform-testing-strategy.md index 7439f848..f0ea21ab 100644 --- a/docs/testing/frontend-platform-testing-strategy.md +++ b/docs/testing/frontend-platform-testing-strategy.md @@ -708,6 +708,10 @@ feature 제거 시 해당 contribution도 함께 제거할 수 있고 공통 evi sample feature가 아니라 `tests/helpers/external-contract-fixture.ts`의 테스트 계약 3개(조회 목록, 조회 단건, 명령)로 돌므로 sample을 지워도 남는다(0929/10-02). 바이트 상한·명령 여부·성공 status는 계약에서 읽는다. +feature 테스트는 catalog를 고치지 않는다. 자기 설치 계약을 +`tests/mocks/handlers/http-scenarios.ts`의 +`createHttpScenarioHandler(<계약>, { scenario, payload })`에 넘기면 그 operation의 +경로·성공 status·응답 상한으로 시나리오 응답을 받는다(16-02). ### 11.1 목표 구조 diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index 80c77364..4f59907e 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -140,6 +140,8 @@ const commonTestPaths = [ "tests/integration/http-scenario-catalog.test.ts", "tests/mocks/scenarios/catalog.ts", "tests/mocks/handlers/test-entities.ts", + // 16-02. Feature tests answer their own operations with it. + "tests/mocks/handlers/http-scenarios.ts", "tests/fixtures/typecheck/fixture-feature-contract.ts", "tests/fixtures/typecheck/invalid-feature-input.ts", "tests/fixtures/typecheck/invalid-reference-operation.ts", diff --git a/tests/component/product-feature-switch.test.tsx b/tests/component/product-feature-switch.test.tsx index d91b04a4..7ee7e1f9 100644 --- a/tests/component/product-feature-switch.test.tsx +++ b/tests/component/product-feature-switch.test.tsx @@ -5,7 +5,7 @@ import { describe, expect, it } from "vitest"; import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts"; import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts"; -import { INSTALLED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts"; +import { REFERENCE_FEATURE_ID } from "../../src/features/reference-feature/contracts/reference-feature-contract.ts"; import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx"; import { PreferenceProviders } from "../../src/presentation/providers/preference-providers.tsx"; import { AppRouter } from "../../src/presentation/routes/app-router.tsx"; @@ -21,7 +21,9 @@ import { createProductFeaturesStub } from "../helpers/runtime-capabilities-stub. * here, on the same render, so the switch cannot be half-wired. */ -const FEATURE_ID = INSTALLED_PRODUCT_FEATURE_IDS[0]!; +// 16-02. The feature that owns FEATURE_ROUTE, not whichever installed feature +// sorts first. +const FEATURE_ID = REFERENCE_FEATURE_ID; const FEATURE_ROUTE = ROUTE_REGISTRY.REFERENCE_RESOURCE_LIST; function renderAt(path: string, disabled: boolean) { diff --git a/tests/features/reference-feature/installed-context-routing.test.ts b/tests/features/reference-feature/installed-context-routing.test.ts index ac16c22f..00cd6118 100644 --- a/tests/features/reference-feature/installed-context-routing.test.ts +++ b/tests/features/reference-feature/installed-context-routing.test.ts @@ -3,15 +3,21 @@ import { describe, expect, it } from "vitest"; import { TEMPLATE_APP_MODULE } from "../../../src/apps/template-app.ts"; import { createAppRouteModules } from "../../../src/platform/routing/context-route-module.ts"; +// 16-02. Other installed features bring their own contexts; only the +// reference context is this sample's to check. +const REFERENCE_CONTEXT_ID = "reference-context"; + describe("installed context routing", () => { it("boots one bounded-context entry instead of flattening feature routes", () => { const modules = createAppRouteModules(TEMPLATE_APP_MODULE); - expect(modules.map((module) => module.id)).toEqual(["reference-context"]); + expect(modules.map((module) => module.id)).toContain(REFERENCE_CONTEXT_ID); expect(modules.some((module) => module.id === "REFERENCE_RESOURCE_LIST")).toBe(false); }); it("loads the reference feature routes lazily without changing public URLs", async () => { - const [context] = createAppRouteModules(TEMPLATE_APP_MODULE); + const context = createAppRouteModules(TEMPLATE_APP_MODULE).find( + (module) => module.id === REFERENCE_CONTEXT_ID, + ); expect(context).toBeDefined(); const routes = await context!.loadRoutes(); expect(routes.map((route) => [route.id, route.path])).toEqual([ diff --git a/tests/integration/http-scenario-catalog.test.ts b/tests/integration/http-scenario-catalog.test.ts index d9809d29..b1e48676 100644 --- a/tests/integration/http-scenario-catalog.test.ts +++ b/tests/integration/http-scenario-catalog.test.ts @@ -21,16 +21,18 @@ import { type RetryReason, } from "../../scripts/lib/http-scenario-evidence.ts"; import { writeValidatedJsonArtifact } from "../../scripts/lib/validated-json-artifact.ts"; +import { TEST_LIST_HTTP_CONTRACT } from "../helpers/external-contract-fixture.ts"; +import { createHttpScenarioHandler } from "../mocks/handlers/http-scenarios.ts"; import { createTestEntityScenarioHandlers } from "../mocks/handlers/test-entities.ts"; import { createStrictMockServer } from "../mocks/server.ts"; import { + assertOperationScenario, HTTP_SCENARIO_CONTRACTS, HTTP_SCENARIO_EXECUTION_IDS, HTTP_SCENARIO_EXPECTATIONS, HTTP_SCENARIO_RECEIPT_SCHEMA_VERSION, OPERATION_SCENARIO_CATALOG, type HttpScenarioExpectation, - type HttpScenarioOperationId, } from "../mocks/scenarios/catalog.ts"; /** A low-cardinality route identity, as a feature binding passes it. */ @@ -53,7 +55,9 @@ type AttemptTrace = { cancelled: boolean; }; -function operationFor(operationId: HttpScenarioOperationId) { +type CatalogOperationId = HttpScenarioExpectation["operationId"]; + +function operationFor(operationId: CatalogOperationId) { return HTTP_SCENARIO_CONTRACTS[operationId] as InstalledHttpContract< unknown, unknown, @@ -61,7 +65,7 @@ function operationFor(operationId: HttpScenarioOperationId) { >; } -function inputFor(operationId: HttpScenarioOperationId): unknown { +function inputFor(operationId: CatalogOperationId): unknown { if (operationId === "TEST_LIST_ENTITIES") return { limit: 20 }; if (operationId === "TEST_GET_ENTITY") return { entityId: "entity-1" }; return { name: "Created" }; @@ -406,3 +410,52 @@ describe("HTTP scenario catalog execution evidence", () => { }); }, 30_000); }); + +describe("HTTP scenario handler for an operation outside the catalog", () => { + // 16-02. A feature test passes its own installed contract; the catalog has + // no entry for it. The ceiling is larger than the catalog's, so the + // oversized body shows it was read from this descriptor. + const featureList = Object.freeze({ + ...TEST_LIST_HTTP_CONTRACT, + contract: Object.freeze({ + ...TEST_LIST_HTTP_CONTRACT.contract, + operationId: "FEATURE_LIST_ITEMS", + pathTemplate: "/api/feature-groups/{groupId}/items", + }), + frontend: Object.freeze({ + ...TEST_LIST_HTTP_CONTRACT.frontend, + responseByteLimit: 65_536, + }), + }); + + it("answers on the descriptor's route with the descriptor's ceiling", async () => { + const attempts: unknown[] = []; + mockApi.server.use( + createHttpScenarioHandler(featureList, { + scenario: "response-too-large", + payload: [], + onAttempt: (attempt) => attempts.push(attempt), + }), + ); + try { + const response = await fetch("https://api.test/api/feature-groups/g-1/items"); + expect(response.status).toBe(200); + expect((await response.arrayBuffer()).byteLength).toBe(65_537); + expect(attempts).toEqual([ + { + operationId: "FEATURE_LIST_ITEMS", + scenarioId: "response-too-large", + attempt: 1, + }, + ]); + } finally { + mockApi.reset(); + } + }); + + it("keeps the catalog's evidence to its own operations", () => { + expect(() => + assertOperationScenario("FEATURE_LIST_ITEMS", "success"), + ).toThrow("FEATURE_LIST_ITEMS is not a catalog operation"); + }); +}); diff --git a/tests/mocks/handlers/http-scenarios.ts b/tests/mocks/handlers/http-scenarios.ts new file mode 100644 index 00000000..44bc3e89 --- /dev/null +++ b/tests/mocks/handlers/http-scenarios.ts @@ -0,0 +1,150 @@ +import { delay, http, HttpResponse, type JsonBodyType } from "msw"; + +import { + httpScenarioOperationFacts, + type HttpScenarioContract, + type HttpScenarioId, + type HttpScenarioOperationId, +} from "../scenarios/catalog.ts"; + +/** + * 16-02. One MSW handler that answers an installed HTTP operation with one + * catalog scenario. The route, the success status and the response ceiling + * come from the operation's own descriptor, so a feature test passes its + * contract and needs no catalog entry: + * + * server.use(createHttpScenarioHandler(LIST_X_CONTRACT, { + * scenario: "server-terminal-503", payload: [...], + * })); + */ +export type HttpScenarioHandlerOptions = Readonly<{ + baseUrl?: string; + scenario?: HttpScenarioId; + /** The success body; `empty` answers `[]` instead. */ + payload: JsonBodyType; + onAttempt?(attempt: Readonly<{ + operationId: HttpScenarioOperationId; + scenarioId: HttpScenarioId; + attempt: number; + }>): void; +}>; + +export function createHttpScenarioHandler( + installed: HttpScenarioContract, + options: HttpScenarioHandlerOptions, +) { + const { operationId, method, pathTemplate } = installed.contract; + const scenarioId = options.scenario ?? "success"; + const facts = httpScenarioOperationFacts(installed); + // MSW path params are `:name`; descriptors write `{name}`. + const url = `${options.baseUrl ?? "https://api.test"}${pathTemplate.replace( + /\{([^}]+)\}/gu, + ":$1", + )}`; + let attempt = 0; + return http[method.toLowerCase() as Lowercase](url, () => { + attempt += 1; + options.onAttempt?.({ operationId, scenarioId, attempt }); + return scenarioResponse( + scenarioId, + scenarioId === "empty" ? [] : options.payload, + attempt, + facts, + ); + }); +} + +async function scenarioResponse( + scenario: HttpScenarioId, + payload: JsonBodyType, + attempt: number, + { ceiling, successStatus }: ReturnType, +) { + if (scenario === "slow") await delay(50); + if (scenario === "timeout" || scenario === "aborted") { + await delay("infinite"); + } + if (scenario === "network-error") return HttpResponse.error(); + if (scenario === "content-type-mismatch") { + return new HttpResponse("not json", { + status: successStatus, + headers: { "Content-Type": "text/html" }, + }); + } + if (scenario === "malformed-json") { + return new HttpResponse("{invalid", { + status: successStatus, + headers: { "Content-Type": "application/json" }, + }); + } + if (scenario === "envelope-mismatch") { + return HttpResponse.json({ data: payload }, { status: successStatus }); + } + if (scenario === "schema-mismatch") { + return HttpResponse.json({ unexpected: true }, { status: successStatus }); + } + if (scenario === "unauthenticated-401") { + return HttpResponse.json(problem(401, "AUTH_REQUIRED"), { status: 401 }); + } + if (scenario === "forbidden-403") { + return HttpResponse.json(problem(403, "FORBIDDEN"), { status: 403 }); + } + if (scenario === "not-found-404") { + return HttpResponse.json(problem(404, "NOT_FOUND"), { status: 404 }); + } + if (scenario === "conflict-409") { + return HttpResponse.json(problem(409, "CONFLICT"), { status: 409 }); + } + if (scenario === "in-flight-409") { + return HttpResponse.json(problem(409, "IDEMPOTENT_IN_FLIGHT"), { + status: 409, + }); + } + if (scenario === "validation-422") { + return HttpResponse.json(problem(422, "VALIDATION_REJECTED"), { + status: 422, + }); + } + if (scenario === "rate-limited-429") { + return HttpResponse.json(problem(429, "RATE_LIMITED"), { + status: 429, + headers: { "Retry-After": "1" }, + }); + } + if ( + scenario === "server-terminal-503" || + (scenario === "server-retry-success" && attempt === 1) + ) { + return HttpResponse.json(problem(503, "SERVER_FAILURE"), { status: 503 }); + } + if (scenario === "response-too-large") { + const bytes = new Uint8Array(ceiling + 1).fill(0x20); + bytes[0] = 0x5b; + bytes[bytes.length - 1] = 0x5d; + return new HttpResponse( + new ReadableStream({ + start(controller) { + controller.enqueue(bytes); + controller.close(); + }, + }), + { + status: successStatus, + headers: { + "Content-Type": "application/json", + "Content-Length": String(bytes.byteLength), + }, + }, + ); + } + return HttpResponse.json(payload, { status: successStatus }); +} + +function problem(status: number, code: string) { + return Object.freeze({ + type: `https://api.test/problems/${code.toLowerCase()}`, + title: code, + status, + code, + }); +} diff --git a/tests/mocks/handlers/test-entities.ts b/tests/mocks/handlers/test-entities.ts index 5cdc5db6..937b4928 100644 --- a/tests/mocks/handlers/test-entities.ts +++ b/tests/mocks/handlers/test-entities.ts @@ -1,12 +1,15 @@ -import { delay, http, HttpResponse, type JsonBodyType } from "msw"; - import { assertOperationScenario, - httpScenarioOperationFacts, - HTTP_SCENARIO_ENTITY, + HTTP_SCENARIO_CONTRACTS, + HTTP_SCENARIO_OPERATION_IDS, + HTTP_SCENARIO_PAYLOADS, type HttpScenarioId, type HttpScenarioOperationId, } from "../scenarios/catalog.ts"; +import { + createHttpScenarioHandler, + type HttpScenarioHandlerOptions, +} from "./http-scenarios.ts"; /** * MSW handlers for the test contracts in `tests/helpers/external-contract-fixture.ts` @@ -16,144 +19,19 @@ import { type ScenarioOptions = Readonly<{ baseUrl?: string; scenarios?: Partial>; - onAttempt?(attempt: Readonly<{ - operationId: HttpScenarioOperationId; - scenarioId: HttpScenarioId; - attempt: number; - }>): void; + onAttempt?: HttpScenarioHandlerOptions["onAttempt"]; }>; -async function scenarioResponse( - operationId: HttpScenarioOperationId, - scenario: HttpScenarioId, - payload: JsonBodyType, - attempt: number, -) { - const { ceiling, successStatus } = httpScenarioOperationFacts(operationId); - if (scenario === "slow") await delay(50); - if (scenario === "timeout" || scenario === "aborted") { - await delay("infinite"); - } - if (scenario === "network-error") return HttpResponse.error(); - if (scenario === "content-type-mismatch") { - return new HttpResponse("not json", { - status: successStatus, - headers: { "Content-Type": "text/html" }, - }); - } - if (scenario === "malformed-json") { - return new HttpResponse("{invalid", { - status: successStatus, - headers: { "Content-Type": "application/json" }, - }); - } - if (scenario === "envelope-mismatch") { - return HttpResponse.json({ data: payload }, { status: successStatus }); - } - if (scenario === "schema-mismatch") { - return HttpResponse.json({ unexpected: true }, { status: successStatus }); - } - if (scenario === "unauthenticated-401") { - return HttpResponse.json(problem(401, "AUTH_REQUIRED"), { status: 401 }); - } - if (scenario === "forbidden-403") { - return HttpResponse.json(problem(403, "FORBIDDEN"), { status: 403 }); - } - if (scenario === "not-found-404") { - return HttpResponse.json(problem(404, "NOT_FOUND"), { status: 404 }); - } - if (scenario === "conflict-409") { - return HttpResponse.json(problem(409, "CONFLICT"), { status: 409 }); - } - if (scenario === "in-flight-409") { - return HttpResponse.json(problem(409, "IDEMPOTENT_IN_FLIGHT"), { - status: 409, - }); - } - if (scenario === "validation-422") { - return HttpResponse.json(problem(422, "VALIDATION_REJECTED"), { - status: 422, - }); - } - if (scenario === "rate-limited-429") { - return HttpResponse.json(problem(429, "RATE_LIMITED"), { - status: 429, - headers: { "Retry-After": "1" }, - }); - } - if ( - scenario === "server-terminal-503" || - (scenario === "server-retry-success" && attempt === 1) - ) { - return HttpResponse.json(problem(503, "SERVER_FAILURE"), { status: 503 }); - } - if (scenario === "response-too-large") { - const bytes = new Uint8Array(ceiling + 1).fill(0x20); - bytes[0] = 0x5b; - bytes[bytes.length - 1] = 0x5d; - return new HttpResponse( - new ReadableStream({ - start(controller) { - controller.enqueue(bytes); - controller.close(); - }, - }), - { - status: successStatus, - headers: { - "Content-Type": "application/json", - "Content-Length": String(bytes.byteLength), - }, - }, - ); - } - return HttpResponse.json(payload, { status: successStatus }); -} - -function problem(status: number, code: string) { - return Object.freeze({ - type: `https://api.test/problems/${code.toLowerCase()}`, - title: code, - status, - code, - }); -} - export function createTestEntityScenarioHandlers(options: ScenarioOptions = {}) { - const baseUrl = options.baseUrl ?? "https://api.test"; - const attempts = new Map(); - const answer = (operationId: HttpScenarioOperationId, payload: JsonBodyType) => { - const scenarioId = assertOperationScenario( - operationId, - options.scenarios?.[operationId] ?? "success", - ); - const attempt = (attempts.get(operationId) ?? 0) + 1; - attempts.set(operationId, attempt); - options.onAttempt?.({ operationId, scenarioId, attempt }); - return scenarioResponse( - operationId, - scenarioId, - scenarioId === "empty" ? [] : payload, - attempt, - ); - }; - - return [ - http.get(`${baseUrl}/api/test-entities`, () => - answer("TEST_LIST_ENTITIES", [{ ...HTTP_SCENARIO_ENTITY }]), - ), - http.post(`${baseUrl}/api/test-entities`, async ({ request }) => { - const body = (await request.json()) as Readonly>; - return answer("TEST_CREATE_ENTITY", { - id: "entity-created", - name: String(body.name ?? "Created"), - }); + return HTTP_SCENARIO_OPERATION_IDS.map((operationId) => + createHttpScenarioHandler(HTTP_SCENARIO_CONTRACTS[operationId], { + baseUrl: options.baseUrl, + scenario: assertOperationScenario( + operationId, + options.scenarios?.[operationId] ?? "success", + ), + payload: HTTP_SCENARIO_PAYLOADS[operationId], + onAttempt: options.onAttempt, }), - http.get(`${baseUrl}/api/test-entities/:entityId`, ({ params }) => - answer("TEST_GET_ENTITY", { - ...HTTP_SCENARIO_ENTITY, - id: String(params.entityId), - }), - ), - ] as const; + ); } diff --git a/tests/mocks/scenarios/catalog.ts b/tests/mocks/scenarios/catalog.ts index a7dc2b81..13b63c44 100644 --- a/tests/mocks/scenarios/catalog.ts +++ b/tests/mocks/scenarios/catalog.ts @@ -1,3 +1,5 @@ +import type { JsonBodyType } from "msw"; + import type { AttemptStatus, BodyDisposition, @@ -11,6 +13,7 @@ export type { HttpScenarioAssertionGroups, RetryReason, } from "../../../scripts/lib/http-scenario-evidence.ts"; +import type { InstalledHttpContract } from "../../../src/contracts/external-contract-runtime.ts"; import { TEST_CLASSIFIED_CREATE_HTTP_CONTRACT, TEST_DETAIL_HTTP_CONTRACT, @@ -56,10 +59,32 @@ export const HTTP_SCENARIO_CONTRACTS = Object.freeze({ TEST_CREATE_ENTITY: TEST_CLASSIFIED_CREATE_HTTP_CONTRACT, }); -export type HttpScenarioOperationId = keyof typeof HTTP_SCENARIO_CONTRACTS; +/** + * 16-02. Any installed operation, not only the catalog's: a feature test + * answers its own operation with `createHttpScenarioHandler` + * (`tests/mocks/handlers/http-scenarios.ts`) without editing this file. + */ +export type HttpScenarioOperationId = string; + +/** + * The part of an installed (V3) descriptor a scenario reads. Every + * `InstalledHttpContract` fits it, whatever its input and output types. + */ +export type HttpScenarioContract = Readonly<{ + contract: Readonly< + Pick< + InstalledHttpContract["contract"], + "operationId" | "method" | "pathTemplate" | "acceptedStatuses" + > & { commandEffect: unknown } + >; + frontend: Readonly<{ responseByteLimit: number }>; +}>; + +/** The operations this catalog's evidence (FE-GATE-007) is recorded for. */ +type CatalogOperationId = keyof typeof HTTP_SCENARIO_CONTRACTS; export const HTTP_SCENARIO_OPERATION_IDS = Object.freeze( - Object.keys(HTTP_SCENARIO_CONTRACTS) as HttpScenarioOperationId[], + Object.keys(HTTP_SCENARIO_CONTRACTS) as CatalogOperationId[], ); for (const operationId of HTTP_SCENARIO_OPERATION_IDS) { @@ -70,11 +95,11 @@ for (const operationId of HTTP_SCENARIO_OPERATION_IDS) { } export type HttpScenarioExecutionId = - `${HttpScenarioOperationId}::${HttpScenarioId}`; + `${CatalogOperationId}::${HttpScenarioId}`; export type HttpScenarioExpectation = Readonly<{ executionId: HttpScenarioExecutionId; - operationId: HttpScenarioOperationId; + operationId: CatalogOperationId; scenarioId: HttpScenarioId; expected: HttpScenarioAssertionGroups; testDeadlineOverrideMs: number | null; @@ -92,19 +117,21 @@ export const HTTP_SCENARIO_CREATED_ENTITY = Object.freeze({ name: "Created", }); -/** What a scenario's answer depends on, from the operation's contract. */ -export function httpScenarioOperationFacts(operationId: HttpScenarioOperationId) { - const installed = HTTP_SCENARIO_CONTRACTS[operationId]; +/** The success body each catalog operation answers with. */ +export const HTTP_SCENARIO_PAYLOADS: Readonly< + Record +> = Object.freeze({ + TEST_LIST_ENTITIES: Object.freeze([HTTP_SCENARIO_ENTITY]), + TEST_GET_ENTITY: HTTP_SCENARIO_ENTITY, + TEST_CREATE_ENTITY: HTTP_SCENARIO_CREATED_ENTITY, +}); + +/** What a scenario's answer depends on, read from the installed descriptor. */ +export function httpScenarioOperationFacts(installed: HttpScenarioContract) { return Object.freeze({ command: installed.contract.commandEffect !== null, ceiling: installed.frontend.responseByteLimit, successStatus: installed.contract.acceptedStatuses[0]!, - payload: - operationId === "TEST_LIST_ENTITIES" - ? [HTTP_SCENARIO_ENTITY] - : operationId === "TEST_GET_ENTITY" - ? HTTP_SCENARIO_ENTITY - : HTTP_SCENARIO_CREATED_ENTITY, }); } @@ -126,11 +153,13 @@ function attemptBody( } function expectationFor( - operationId: HttpScenarioOperationId, + operationId: CatalogOperationId, scenarioId: HttpScenarioId, ): HttpScenarioExpectation { - const { command, ceiling, successStatus, payload } = - httpScenarioOperationFacts(operationId); + const { command, ceiling, successStatus } = httpScenarioOperationFacts( + HTTP_SCENARIO_CONTRACTS[operationId], + ); + const payload = HTTP_SCENARIO_PAYLOADS[operationId]; let statuses: AttemptStatus[] = [successStatus]; let kind = "SUCCESS"; let detail: string | null = null; @@ -432,7 +461,7 @@ const OPERATION_SCENARIOS = Object.freeze({ ), ), } satisfies Readonly< - Record + Record >); export const HTTP_SCENARIO_EXPECTATIONS = Object.freeze( @@ -458,7 +487,7 @@ export const OPERATION_SCENARIO_CATALOG = Object.freeze( ), ]), ) as Readonly< - Record + Record >, ); @@ -466,7 +495,15 @@ export function assertOperationScenario( operationId: HttpScenarioOperationId, scenario: HttpScenarioId, ) { - if (!OPERATION_SCENARIO_CATALOG[operationId].includes(scenario)) { + const catalog: Readonly>> = + OPERATION_SCENARIO_CATALOG; + const declared = catalog[operationId]; + if (declared === undefined) { + throw new Error( + `${operationId} is not a catalog operation; answer it with createHttpScenarioHandler`, + ); + } + if (!declared.includes(scenario)) { throw new Error(`Scenario ${scenario} is not declared for ${operationId}`); } return scenario; diff --git a/tests/runtime-schema/release-manifest.test.ts b/tests/runtime-schema/release-manifest.test.ts index 549f2f5b..e0ed2b9d 100644 --- a/tests/runtime-schema/release-manifest.test.ts +++ b/tests/runtime-schema/release-manifest.test.ts @@ -5,8 +5,14 @@ import { ReleaseManifestError, } from "../../src/bootstrap/load-release-manifest.ts"; import { computeContractSetDigest } from "../../src/contracts/contract-set-canonical.ts"; +import { EXPECTED_CONTRACT_SET_PACKAGES } from "../../src/features/installed-contract-contributions.ts"; const EMPTY_SET_DIGEST = await computeContractSetDigest([]); +// 16-02. The build compiles the installed features' packages, so a coherent +// manifest carries exactly that set, whatever is installed. +const INSTALLED_SET_DIGEST = await computeContractSetDigest( + EXPECTED_CONTRACT_SET_PACKAGES, +); const runtime: Parameters[0] = { build: { @@ -49,8 +55,8 @@ const manifest = { routeChunks: { "route-home": "assets/home.js" }, contractSet: { setAlgorithm: "CA_CONTRACT_SET_V1", - setDigest: EMPTY_SET_DIGEST, - packages: [], + setDigest: INSTALLED_SET_DIGEST, + packages: EXPECTED_CONTRACT_SET_PACKAGES, }, };