다섯 종류는 전부 끝난 일을 남긴다. 없는 것은 읽는 사람이 자기 손으로 다시 하려면 무엇부터 하는가다. Case 의 environment 는 평문 한 칸이라 명령이 들어가지 않고, 같은 셋업을 쓰는 Case 가 넷이면 같은 문장이 네 벌 복제된다. 프로젝트는 필수, 주제는 선택으로 둔다. 주제 없는 셋업이 그 프로젝트의 공통 구성이고, 주제를 붙이면 그 주제의 구성이다 — 스키마를 나누지 않고 두 범위를 같은 종류로 받는다. 버전만 본문 밖에 둔다(pinnedVersions). 이 절차가 어느 버전 위에서 성립했는지는 그 기록의 유효 범위이고, 목록과 머리말이 본문을 열지 않고 보여 줘야 한다. 나머지 셋(실행 절차·구성 값·확인 방법)은 명령과 표를 담아야 하므로 본문이다. 이름은 SETUP 이다. ENVIRONMENT 가 영어로는 자연스럽지만 case_detail.environment 와 겹친다 — 이 저장소가 열네 번 밟은 실패가 「종류를 손으로 나열한 곳을 빠뜨린다」이고 그걸 찾는 수단이 grep 이다. 손으로 나열해 두었던 자리를 이번에 표로 바꿨다. publicPath 의 삼항 사슬은 마지막 else 가 「나머지 전부」여서 새 종류의 주소가 조용히 /questions/… 가 됐고, document-editor 의 칸 경로도 같은 모양이었다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PTnWufiY9ATv57egkKKVAV
108 lines
4.0 KiB
TypeScript
108 lines
4.0 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$",
|
|
"^/setups/[^/]+$",
|
|
"^/topics$",
|
|
"^/topics/[^/]+$",
|
|
"^/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$",
|
|
"^/studio/topics/[^/]+$",
|
|
]);
|
|
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(["^/$"]);
|
|
});
|
|
});
|