Files
clean-architecture-frontend…/tests/unit/route-runtime.test.ts
T
DongHyeonka e4ace51099 fix(features): 기능이 하나도 없을 때도 타입 검사와 커버리지가 통과하게 한다 (15-01)
문제: 샘플 제거 드릴(test:sample-removal)이 reference feature를 지우면
설치된 기능이 0개가 된다. 15-01 이후 그 상태에서 기능 기여 타입이 never가
되어 installed-feature-adapters.ts와 테스트 2개가 타입 검사에서 실패했다.
features.load는 기능 테스트로만 검증되고 있어서, 기능 테스트가 같이
지워지면 create-application.ts 커버리지가 90% 아래로 떨어졌다. 드릴 사본에
README.md·CHANGELOG.md가 없어 문서 테스트 2개도 실패했다.

방법: never일 때도 통과하는 넓은 타입으로 받아서 읽는다(as 단언 없이 대입).
features.load는 가짜 로더로 플랫폼 테스트를 추가했다(한 번만 적재, 남의
input 거부, 실패 후 재시도). 문서 테스트 2개는 드릴 제외 목록에 넣었다.
드릴 사본에 문서를 복사하는 안은 버렸다. 기능 제거와 무관한 파일이 사본
목록에 들어간다.

위험: 넓힌 타입은 기여 타입이 바뀌어도 featureId 검사 부분은 잡지 못한다.
그 검사는 실행 시 TypeError로 남아 있다.

검증: tsc -p tsconfig.test.json 통과, check:types 통과, 관련 단위 테스트
20/20 통과. 드릴은 고치기 전 실행에서 coverage PASS를 확인했고 타입 오류
2건이 남아 있었다. 그 2건을 고친 뒤 드릴 전체는 다시 돌리지 않았다.
2026-11-01 23:44:29 +09:00

66 lines
2.6 KiB
TypeScript

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<string, Readonly<Record<string, unknown>>>();
// 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<readonly Readonly<{ handle?: unknown }>[]>;
}>;
}>[] = 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<Record<string, unknown>> }>
| 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 });
});
});