Files
tech-log-frontend/tests/unit/tech-log-serving-contract.test.ts
T
DongHyeonkaandClaude Opus 5 071405a6bb feat: 개념의 공개 라우트와 탐색 유형을 설치한다
앞선 커밋은 렌더러와 편집기까지만 붙였다. 화면을 열어 보니 탐색의 유형 선택지에 개념이 없고
`/concepts/:slug` 라우트도 없었다 — 라벨 표만 고치고 실제 선택지와 라우트를 빠뜨렸다.

라우트를 하나 더하자 이 저장소가 라우트 수를 고정해 둔 자리가 전부 울렸다. 라우트 계약,
런타임 등록, 메시지 카탈로그, nginx 서빙 패턴, 코드 분할 청크, 그리고 CI 게이트의 수동
접근성 증거까지 — 라우트마다 증거 문서를 하나씩 갖는 규칙이라 `TECH_LOG_CONCEPT.md` 를
다른 라우트와 같은 `pending-manual-review` 상태로 만들었다. 사람이 서명할 자리는 비워 둔다.

게이트 형상 해시는 규칙대로 다시 계산했다 — 옛 `gates.json` 에서 이전 상수 fb138e7c… 를
먼저 재현해 계산 방법이 맞는지 확인한 뒤 새 파일을 해싱했다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0189NzCryfeqDzS81EWidnBx
2026-08-28 20:17:58 +09:00

104 lines
3.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createTechLogServingContract } from "../../scripts/lib/tech-log-serving-contract.ts";
import { TECH_LOG_ROUTE_REGISTRY } from "../../src/features/tech-log/contracts/tech-log-route-contract.ts";
const publicRoutePaths = Object.values(TECH_LOG_ROUTE_REGISTRY)
.filter((route) => route.layoutGroup === "PUBLIC")
.map((route) => route.path);
const studioRoutePaths = Object.values(TECH_LOG_ROUTE_REGISTRY)
.filter((route) => route.layoutGroup === "STUDIO")
.map((route) => route.path);
describe("TechLog production serving contract", () => {
it("derives one pattern per registered Public route", () => {
const contract = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
expect(contract.schemaVersion).toBe(2);
expect(contract.publicSpaPathPatterns).toEqual([
"^/$",
"^/cases/[^/]+$",
"^/concepts/[^/]+$",
"^/explore$",
"^/explore/[^/]+$",
"^/profile$",
"^/projects$",
"^/projects/[^/]+$",
"^/projects/[^/]+/activity$",
"^/projects/[^/]+/decisions$",
"^/projects/[^/]+/records$",
"^/questions/[^/]+$",
"^/references/[^/]+$",
"^/releases$",
"^/releases/[^/]+$",
"^/search$",
"^/topics/[^/]+$",
]);
expect(contract.studioPathPrefix).toBe("/studio");
// Derived from the route contract and sorted, exactly like the public half.
// The old hand-written array folded the four document sub-screens into one
// alternation; deriving them yields one pattern per route, which is the
// point — a route that exists is served, without anyone remembering to add it.
expect(contract.studioSpaPathPatterns).toEqual([
"^/studio$",
"^/studio/assets$",
"^/studio/documents$",
"^/studio/documents/[^/]+/edit$",
"^/studio/documents/[^/]+/preview$",
"^/studio/documents/[^/]+/publish$",
"^/studio/documents/[^/]+/validation$",
"^/studio/documents/new$",
"^/studio/projects/[^/]+$",
"^/studio/publications$",
"^/studio/publications/[^/]+/preview$",
"^/studio/releases$",
"^/studio/releases/[^/]+$",
"^/studio/taxonomy$",
]);
expect(contract.notFound).toEqual({
status: 404,
contentType: "text/plain;charset=UTF-8",
body: "Not Found",
});
});
/**
* The reason this migration happened: a slug that did not exist at build time
* used to be 404ed by the web server before the SPA was asked. A published
* record must be served whatever its slug.
*/
it("serves a slug the build never saw", () => {
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
const matches = (pathname: string) =>
publicSpaPathPatterns.some((pattern) => new RegExp(pattern).test(pathname));
expect(matches("/cases/a-record-published-yesterday")).toBe(true);
expect(matches("/projects/a-new-project/decisions")).toBe(true);
expect(matches("/topics/a-new-topic")).toBe(true);
});
/** A parameter is one segment. Extra depth is a 404, not a soft 200. */
it("does not let a parameter swallow a slash", () => {
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
const matches = (pathname: string) =>
publicSpaPathPatterns.some((pattern) => new RegExp(pattern).test(pathname));
expect(matches("/cases/a/b")).toBe(false);
expect(matches("/projects/one/two/three")).toBe(false);
expect(matches("/nope")).toBe(false);
});
/**
* The catch-all belongs to the SPA, not to the edge. Serving index.html for
* every unmatched URL would turn a 404 into a soft 200 and hide broken links.
*/
it("drops the catch-all route", () => {
const { publicSpaPathPatterns } = createTechLogServingContract({
publicRoutePaths: ["/", "*"],
studioRoutePaths,
});
expect(publicSpaPathPatterns).toEqual(["^/$"]);
});
});