import { describe, expect, it } from "vitest"; import { ROUTE_FEATURE_OWNER, ROUTE_REGISTRY, ROUTE_RUNTIME_CONTRACT, } from "../../src/features/installed-feature-contracts.ts"; import { PLATFORM_ROUTE_REGISTRY } from "../../src/contracts/routes.ts"; import { PRODUCT_CONTEXT_MODULES } from "../../src/.generated/product-context-index.ts"; import { PLATFORM_ROUTE_CODECS } from "../../src/presentation/routes/platform-route-codecs.ts"; import { parseRouteInput } from "../../src/presentation/routes/route-codecs.ts"; import { PLATFORM_ROUTE_RUNTIME } from "../../src/presentation/routes/route-runtime.tsx"; describe("typed installed route catalog", () => { it("keeps contract and executable runtime contributions complete", () => { expect(Object.keys(ROUTE_RUNTIME_CONTRACT).sort()).toEqual( Object.keys(ROUTE_REGISTRY).sort(), ); expect(Object.keys(PLATFORM_ROUTE_RUNTIME).sort()).toEqual( Object.keys(PLATFORM_ROUTE_REGISTRY).sort(), ); }); // 15-01. Feature route codecs moved from the boot-time feature module to the // context route handles; every codec a route names must still resolve. it("resolves every route's codecs from the platform or its context route handle", async () => { const featureCodecs = new Map>>(); // Widened so the test still type-checks with no installed context // (test:sample-removal), where the module type is `never`. const contexts: readonly Readonly<{ route?: Readonly<{ loadRoutes(): Promise[]>; }>; }>[] = PRODUCT_CONTEXT_MODULES; for (const context of contexts) { for (const route of (await context.route?.loadRoutes()) ?? []) { const handle = route.handle as | Readonly<{ routeId: string; codecs?: Readonly> }> | undefined; if (handle) featureCodecs.set(handle.routeId, handle.codecs ?? {}); } } for (const [routeId, runtime] of Object.entries(ROUTE_RUNTIME_CONTRACT)) { const available = { ...PLATFORM_ROUTE_CODECS, ...(ROUTE_FEATURE_OWNER[routeId] === undefined ? {} : featureCodecs.get(routeId)), }; for (const codecId of [runtime.paramsCodec, runtime.searchCodec]) { expect(Object.hasOwn(available, codecId), `${routeId}: ${codecId}`).toBe(true); } } }); it("accepts the platform not-found splat owner", () => { expect( parseRouteInput( "NOT_FOUND", { "*": "missing/path" }, new URLSearchParams(), ), ).toMatchObject({ success: true }); }); });