Files
tech-log-frontend/tests/unit/tech-log-serving-contract.test.ts
T
DongHyeonka 11c2713139 feat: let Studio create the topics and projects publishing requires
Publishing needs a topic and nothing could create one. The backend now owns
that surface; this is its consumer — the management contract vendored, a
gateway over its nine operations, and one Studio screen that lists, creates,
and deletes topics and projects.

The screen adds no CSS. It reuses the classes the working-copy list already
uses, so it inherits Studio's spacing, type, and colour rather than growing a
second visual vocabulary beside them. Scope stops at list/create/delete:
renaming, phase changes, and visibility are implemented in the backend and
declared in the contract, but their screens are a separate design.

Two real defects surfaced while making the public port async, and both would
have shipped:

The search page and the header search dialog shared a query key. With an empty
query, `["tech-log","search",""]` was identical for both, so react-query
handed one surface the other's cache — different shapes — and the page died
reading a field that was not there. Keys now name the surface.

The explore filter's selects are uncontrolled and read `defaultValue`, which
React applies once. Their options arrive later now, so the first render had
nothing to match and the value stayed empty: a topic in the URL no longer
showed as selected. The form key includes whether the catalog has arrived, so
it remounts with the options present. Controlled inputs would be the other
answer, but this form submits to build a URL — the URL owns the value.

The route brought its own bookkeeping: a build chunk, a manual accessibility
evidence file, and the CI artifact baseline that counts them. The gate pins a
digest of its own shape precisely so a new route cannot slip in without that
count being reviewed.

Test harnesses that render public screens now assemble the query providers and
await the settled paint, because the screens they render became async.
2026-08-20 23:40:15 +09:00

88 lines
3.2 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);
describe("TechLog production serving contract", () => {
it("derives one pattern per registered Public route", () => {
const contract = createTechLogServingContract({ publicRoutePaths });
expect(contract.schemaVersion).toBe(2);
expect(contract.publicSpaPathPatterns).toEqual([
"^/$",
"^/cases/[^/]+$",
"^/explore$",
"^/explore/[^/]+$",
"^/profile$",
"^/projects$",
"^/projects/[^/]+$",
"^/projects/[^/]+/activity$",
"^/projects/[^/]+/decisions$",
"^/projects/[^/]+/records$",
"^/questions/[^/]+$",
"^/references/[^/]+$",
"^/releases$",
"^/releases/[^/]+$",
"^/search$",
"^/topics/[^/]+$",
]);
expect(contract.studioPathPrefix).toBe("/studio");
expect(contract.studioSpaPathPatterns).toEqual([
"^/studio$",
"^/studio/assets$",
"^/studio/taxonomy$",
"^/studio/documents$",
"^/studio/documents/new$",
"^/studio/documents/[^/]+/(edit|validation|preview|publish)$",
"^/studio/publications$",
"^/studio/publications/[^/]+/preview$",
]);
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 });
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 });
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: ["/", "*"],
});
expect(publicSpaPathPatterns).toEqual(["^/$"]);
});
});