// @vitest-environment jsdom import { render, screen } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; 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"; import { createTestApplication } from "../helpers/create-test-application.ts"; /** * 09-09 (0929/08-05). Failures the context gateway catches outside a route's * own boundary: the context boundary (a route handle naming an unregistered * route), the feature boundary (a handle without the codecs its route needs) * and a routes module that fails for a reason other than a missing chunk. * Each has to leave a `ui.render.failed` record whose incident id the screen * shows as `:`. */ vi.mock("../../src/.generated/product-feature-index.ts", async () => ({ DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"], PRODUCT_FEATURE_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE], })); vi.mock("../../src/apps/template-app.ts", async () => { const { FIXTURE_CONTEXT_ROUTES } = await import("../helpers/fixture-feature.tsx"); const items = FIXTURE_CONTEXT_ROUTES.find((route) => route.id === "FIXTURE_ITEMS"); const runtime = (items?.handle as { runtime: unknown }).runtime; return { TEMPLATE_APP_MODULE: { id: "boundary-app", budget: { maxContexts: 3 }, contexts: [ { id: "context-without-codecs", route: { path: "fixture/items/*", loadRoutes: async () => [ { id: "FIXTURE_ITEMS", path: "/fixture/items", handle: { routeId: "FIXTURE_ITEMS", runtime }, }, ], }, }, { id: "context-with-typo", route: { path: "fixture/items/status/*", loadRoutes: async () => [ { id: "FIXTURE_ITEM_STATUSS", path: "/fixture/items/status", handle: { routeId: "FIXTURE_ITEM_STATUSS", runtime }, }, ], }, }, { id: "context-broken", route: { path: "fixture/items/new/*", loadRoutes: async () => { throw new ReferenceError("pageComponent is not defined"); }, }, }, ], }, }; }); afterEach(() => { vi.restoreAllMocks(); }); async function expectReportedFailure( url: string, expected: Readonly<{ routeId: string; boundary: "route" | "feature" }>, ) { // React logs every caught render error; the assertions below are the point. vi.spyOn(console, "error").mockImplementation(() => {}); const record = vi.fn(); window.history.pushState({}, "", url); render( , ); const reference = await screen.findByText(/^지원 참조: build-a:[0-9a-f]{8}$/); const incidentId = reference.textContent?.split(":").at(-1); const failures = record.mock.calls .map(([event]) => event as { eventId: string; context: Record }) .filter((event) => event.eventId === "ui.render.failed"); expect(failures).toEqual([ { level: "error", eventId: "ui.render.failed", context: { route_id: expected.routeId, build_id: "build-a", component_boundary: expected.boundary, correlation_id: incidentId, }, }, ]); } describe("context gateway failure diagnostics", () => { it("reports what the context boundary catches", async () => { await expectReportedFailure("/fixture/items/status", { routeId: "FIXTURE_ITEM_STATUSS", boundary: "route", }); }); it("reports what the feature boundary catches", async () => { await expectReportedFailure("/fixture/items", { routeId: "FIXTURE_ITEMS", boundary: "feature", }); }); it("reports a routes module that fails without a missing chunk", async () => { await expectReportedFailure("/fixture/items/new", { routeId: "FIXTURE_ITEM_FORM", boundary: "route", }); }); });