import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { test } from "vitest"; import { knowledgeListItemToRecord } from "../../../src/features/tech-log/adapters/http/public-content-mapping.ts"; /** * 지식 목록이 계약이 보내는 종류를 하나도 버리지 않는지 본다. * *

매퍼가 CASE 와 REFERENCE 만 알던 동안 개념은 `null` 로 버려졌다. 서버는 개념을 보내고 * 탐색 필터에는 「동작 원리」가 있는데 결과는 0건이었다 — 독자에게는 기록이 없는 것으로 * 보였고, 필터에 있는데 결과가 없으니 오해가 남았다. * *

기대 목록을 손으로 적지 않고 계약에서 읽는다. 종류가 늘면 여기서 먼저 멈춘다. */ const CONTRACT = readFileSync( "src/features/tech-log/contracts/public/public-api.openapi.yaml", "utf8", ); function contractKnowledgeKinds(): string[] { const block = /\n {4}KnowledgeListItem:[\s\S]*?(?=\n {4}[A-Z]\w+:)/u.exec(CONTRACT)?.[0] ?? ""; const typeBlock = /\n {8}type:\n {10}type: string\n {10}enum:\n((?: {10}- \w+\n)+)/u.exec(block); return [...(typeBlock?.[1] ?? "").matchAll(/- (\w+)/gu)].map((match) => match[1]!); } test("계약이 보내는 지식 종류를 매퍼가 하나도 버리지 않는다", () => { const kinds = contractKnowledgeKinds(); assert.deepEqual( [...kinds].sort(), ["CASE", "CONCEPT", "REFERENCE", "SETUP"], "계약이 보내는 종류가 바뀌었다 — 매퍼의 표도 함께 봐야 한다", ); for (const type of kinds) { const record = knowledgeListItemToRecord({ type, title: "제목", path: `/x/${type.toLowerCase()}`, primarySummary: "요약", publishedAt: "2026-01-01T00:00:00Z", primaryTopic: { name: "주제", slug: "topic" }, primaryProject: { name: "프로젝트", slug: "project" }, }); assert.ok(record, `${type} 이 목록에서 버려진다`); assert.equal(record.kind, type, `${type} 이 다른 종류로 읽힌다`); // 맥락 줄이 이 두 값을 읽는다. 비면 「· 프로젝트」처럼 앞이 잘린 줄이 남는다. assert.equal(record.topic, "주제"); assert.equal(record.projectTitle, "프로젝트"); } });