Files
tech-log-frontend/tests/component/chunk-recovery-boundary.test.tsx
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the
generator-built feature index with its app, bounded-context and feature
declarations, the src/platform kernel and scale tooling, the 2026-09-24 src
review fixes, and the 2026-09-25 maturity review round with its CHANGELOG
[보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them
merged with product changes; 127 are not carried.

Product identity is unchanged: name, version 0.1.0, routes, design and the
TechLog domain.

Three decisions worth naming. TechLog stays composed directly, as the last
two syncs recorded; its directory carries a NOT_INSTALLED marker that says so,
and every installed-* composer takes the template's projection with TechLog
added on top. The reference sample is no longer installed: the template now
installs a feature only through feature-module.ts and context-routes.ts,
which load the screens this product deleted, so its three operations, six
schemas and one topic leave the registries, recorded as registry change
evidence. And AppRouter mounts the platform and TechLog routes only; the
template's bounded-context route gateway waits for a generator-installed
feature.

Required fixes: readSubject on the BFF session owner (without it every HTTP
Studio session would close as integration-failed), zod through the facade in
nine TechLog files, noUnusedLocals, and public/config.json written out to
match the local profile. Derived baselines were recomputed after reproducing
both sides' values: CI contract 101 commands / 106 references / 141
artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime
config schema baseline equals the schema at 8210d48.

Verified here: types, lint, architecture, adapter inventory, CI contract,
i18n, design system, diagnostics, browser security, dev release manifest,
TechLog contract and build pass; 220 component, 155 integration, 15
contract, 418 TechLog, 43 reference-feature, 18 recipe and 46
release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at
8210d48 first and unchanged: check:registries (byte-identical),
test:runtime-schema, verify:documentation. Brought by the template and
escalated rather than suppressed: check:request-fanout on TechLog's cursor
pagination, check:remediation-ledger (fails upstream too), the shared-chunk
hash test, and the registry-dependent sample removal and second-feature
tests. Playwright suites were not run.

Full record, the five open questions and the follow-ups in
docs/operations/template-sync-2026-09-29.md.

(cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
2026-11-12 08:28:54 +09:00

226 lines
7.4 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { lazy, Suspense } from "react";
import { describe, expect, it, vi } from "vitest";
import {
ChunkRecoveryBoundary,
isChunkLoadFailure,
} from "../../src/presentation/boundaries/chunk-recovery-boundary.tsx";
import { FeatureBoundary } from "../../src/presentation/boundaries/render-error-boundary.tsx";
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";
import { createTechLogFeatureInstalledInput } from "../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
import { renderWithQueryProviders } from "../helpers/query-providers.tsx";
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../helpers/studio-install-context.ts";
// The Explore page stands in for a route chunk the network could not deliver:
// a rejected lazy module throws its rejection on every render, as this does
// (template sync af3d8e6: upstream uses its states example page, which this
// product deleted).
vi.mock("../../src/features/tech-log/presentation/public/pages/explore-page.tsx", () => ({
ExplorePage: function UnreachableChunk(): never {
throw new TypeError(
"Failed to fetch dynamically imported module: /assets/explore.js",
);
},
}));
function ChunkDefect(): never {
throw new TypeError("Failed to fetch dynamically imported module");
}
function RenderDefect(): never {
throw new Error("ordinary render defect");
}
describe("chunk recovery boundary classification", () => {
it("recognizes lazy module failures without classifying ordinary render errors", () => {
expect(
isChunkLoadFailure(
new TypeError("Failed to fetch dynamically imported module"),
),
).toBe(true);
expect(isChunkLoadFailure(new Error("ordinary render defect"))).toBe(false);
});
it("recognizes the WebKit module failure and the Vite CSS preload failure", () => {
expect(
isChunkLoadFailure(new TypeError("Importing a module script failed.")),
).toBe(true);
expect(
isChunkLoadFailure(
new Error("Unable to preload CSS for /assets/states-3f2a.css"),
),
).toBe(true);
});
it("recovers when Vite rethrows a vite:preloadError into the lazy import", async () => {
// Vite dispatches `vite:preloadError` and, unless a listener prevents it,
// rejects the dynamic import with the same error. That rejection is what
// reaches this boundary.
const Page = lazy(() =>
Promise.reject(new Error("Unable to preload CSS for /assets/states.css")),
);
const recover = vi.fn(async () => ({
action: "support" as const,
reason: "reload-already-attempted",
}));
render(
<Suspense fallback={null}>
<ChunkRecoveryBoundary chunkId="route-states" recover={recover}>
<Page />
</ChunkRecoveryBoundary>
</Suspense>,
);
expect(
await screen.findByRole("heading", {
name: "화면 자산을 복구하지 못했습니다.",
}),
).toBeVisible();
expect(recover).toHaveBeenCalledWith({
chunkId: "route-states",
failureKind: "CHUNK_LOAD_FAILURE",
});
});
it("runs the recovery input only for a lazy chunk rejection", async () => {
const recover = vi.fn(async () => ({
action: "support" as const,
reason: "reload-already-attempted",
}));
render(
<ChunkRecoveryBoundary chunkId="route-home" recover={recover}>
<ChunkDefect />
</ChunkRecoveryBoundary>,
);
expect(
await screen.findByRole("heading", {
name: "화면 자산을 복구하지 못했습니다.",
}),
).toBeVisible();
expect(recover).toHaveBeenCalledOnce();
expect(recover).toHaveBeenCalledWith({
chunkId: "route-home",
failureKind: "CHUNK_LOAD_FAILURE",
});
});
it("rethrows an ordinary component defect to the local render boundary", () => {
const recover = vi.fn();
render(
<FeatureBoundary routeId="APP_HOME" buildId="build-a">
<ChunkRecoveryBoundary chunkId="route-home" recover={recover}>
<RenderDefect />
</ChunkRecoveryBoundary>
</FeatureBoundary>,
);
expect(screen.getByRole("alert")).toHaveTextContent(
"화면을 표시하지 못했습니다.",
);
expect(recover).not.toHaveBeenCalled();
});
it("offers a user-started reload on the failure surface", async () => {
render(
<ChunkRecoveryBoundary
chunkId="route-home"
recover={async () => ({
action: "support" as const,
reason: "reload-already-attempted",
})}
>
<ChunkDefect />
</ChunkRecoveryBoundary>,
);
expect(
await screen.findByRole("button", { name: "한 번 새로고침" }),
).toBeVisible();
});
// 08-07. An unrecovered chunk failure shows a reference the render
// diagnostic also records.
it("shows an unrecovered chunk failure's support reference and records it", async () => {
const record = vi.fn();
window.history.pushState({}, "", "/explore");
render(
renderWithQueryProviders(
<ApplicationProvider
application={createTestApplication({
diagnostics: { record },
featureInputs: {
"tech-log": createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input,
},
})}
>
<PreferenceProviders>
<AppRouter buildId="build-a" />
</PreferenceProviders>
</ApplicationProvider>,
),
);
const reference = await screen.findByText(/^지원 참조: build-a:[0-9a-f]{8}$/);
const incidentId = reference.textContent?.split(":").at(-1);
expect(record).toHaveBeenCalledWith({
level: "error",
eventId: "ui.render.failed",
context: expect.objectContaining({
route_id: "TECH_LOG_EXPLORE",
build_id: "build-a",
correlation_id: incidentId,
}),
});
});
it("clears a failed route chunk when the user moves to a sibling route", async () => {
// React Router reuses the rendered-route instance between sibling routes,
// so a failure latched in one route's boundary would otherwise follow the
// user to every other page until a full reload.
const user = userEvent.setup();
window.history.pushState({}, "", "/explore");
render(
renderWithQueryProviders(
<ApplicationProvider
application={createTestApplication({
featureInputs: {
"tech-log": createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input,
},
})}
>
<PreferenceProviders>
<AppRouter />
</PreferenceProviders>
</ApplicationProvider>,
),
);
expect(
await screen.findByRole("heading", {
name: "화면 자산을 복구하지 못했습니다.",
}),
).toBeVisible();
await user.click(screen.getAllByRole("link", { name: "주제" })[0]!);
expect(
await screen.findByRole(
"heading",
{ name: "주제", level: 1 },
{ timeout: 5000 },
),
).toBeVisible();
expect(
screen.queryByRole("heading", { name: "화면 자산을 복구하지 못했습니다." }),
).toBeNull();
});
});