「다음에 읽을 것」에 걸린 결정 링크가 404 였다. 주소는 서버가 게시할 때 만들어 저장한 문자열이라 화면 코드 어디에도 흔적이 없었고, 방문자만 그것을 만났다. - `resolvesToPublicRoute` 가 route contract 에서 읽은 라우트 표에 주소를 맞춰 본다. 맞는 라우트가 없는 줄은 관계 목록이 링크로 그리지 않는다. - 결정 목록의 각 항목이 `slug` 를 element id 로 단다 — 결정의 공개 주소가 이 목록 위의 앵커이므로, id(UUID)를 달면 다른 기록이 건 링크가 갈 곳을 잃는다. - 앵커로 들어오면 그 결정까지 내려간다. 목록은 받아온 뒤에 그려지므로 브라우저의 기본 앵커 이동만으로는 닿지 않는다. 주제 화면 셋을 더하면서 함께 늘려야 했던 것들도 여기서 맞춘다 — nginx 로 나가는 경로 패턴, 라우트마다 하나씩인 수동 접근성 증거, 그리고 그 둘을 세는 CI 게이트 기준값. 게이트 형상 digest 는 이전 gates.json 에서 옛 값(87a22f68…)을 먼저 재현한 뒤 새로 계산했다.
107 lines
4.0 KiB
TypeScript
107 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$",
|
|
"^/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(["^/$"]);
|
|
});
|
|
});
|