| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { RELEASE_BASELINE, type CapabilityContext } from "./capabilities"; |
| 3 | import { toolRowsFor } from "./content/tools"; |
| 4 | import { controlTermsFor } from "./content/vocabulary"; |
| 5 | import { getDocsAccount } from "./content/docs-account"; |
| 6 | import { resolveDocsPage } from "./docs-release"; |
| 7 | import { FEATURE_CATALOGUE, type Feature } from "./features"; |
| 8 | import { |
| 9 | getDocsAuth, getDocsClaudeCode, getDocsConfiguration, getDocsFleet, getDocsHooks, getDocsMcp, getDocsModes, getDocsPet, |
| 10 | getDocsReview, getDocsRuntimeApi, getDocsSandbox, getDocsSkills, getDocsSubagents, getDocsTroubleshooting, getDocsTrust, |
| 11 | getDocsWeb, getDocsWork, getDocsFirstTime, |
| 12 | } from "./i18n/dictionaries"; |
| 13 | import type { DocsBlock, DocsPageDict } from "./i18n/dictionaries/types"; |
| 14 | import { DOC_TOPICS } from "./docs-map"; |
| 15 | |
| 16 | if (!RELEASE_BASELINE) throw new Error("release baseline missing"); |
| 17 | const baseline = RELEASE_BASELINE; |
| 18 | |
| 19 | const published: CapabilityContext = { release: { tag: baseline.tag, version: baseline.version }, baseline }; |
| 20 | |
| 21 | const DIAL_ROWS = ["modes", "permission-postures"]; |
| 22 | const beforeTheDial: CapabilityContext = { |
| 23 | release: published.release, |
| 24 | baseline: { |
| 25 | ...baseline, |
| 26 | features: baseline.features.map((row) => (DIAL_ROWS.includes(row.id) ? { ...row, summary: "The row as an earlier release described it." } : row)), |
| 27 | }, |
| 28 | }; |
| 29 | |
| 30 | const atTheDial: CapabilityContext = { |
| 31 | release: published.release, |
| 32 | baseline: { |
| 33 | ...baseline, |
| 34 | features: [ |
| 35 | ...baseline.features.filter((row) => !DIAL_ROWS.includes(row.id)), |
| 36 | ...FEATURE_CATALOGUE.features |
| 37 | .filter((row) => DIAL_ROWS.includes(row.id)) |
| 38 | .map((row) => ({ id: row.id, name: row.name, summary: row.summary, status: row.status, since: row.since })), |
| 39 | ], |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | const presentUnreleased = FEATURE_CATALOGUE.features.map((row) => (row.id === "present-handoff" ? { ...row, since: "unreleased" } : row)); |
| 44 | |
| 45 | const raisedFeatures = FEATURE_CATALOGUE.features.map((row) => (row.since === "unreleased" ? { ...row, since: "99.0.0" } : row)); |
| 46 | |
| 47 | const raised: CapabilityContext = { |
| 48 | release: { tag: "v99.0.0", version: "99.0.0" }, |
| 49 | baseline: { |
| 50 | ...baseline, |
| 51 | tag: "v99.0.0", |
| 52 | version: "99.0.0", |
| 53 | features: raisedFeatures.map((row) => ({ id: row.id, name: row.name, summary: row.summary, status: row.status, since: row.since })), |
| 54 | }, |
| 55 | }; |
| 56 | |
| 57 | function blockText(block: DocsBlock): string { |
| 58 | if ("p" in block) return block.p; |
| 59 | if ("code" in block) return block.code; |
| 60 | if ("rows" in block) return block.rows.flat().join(" "); |
| 61 | if ("steps" in block) return block.steps.join(" "); |
| 62 | if ("list" in block) return block.list.join(" "); |
| 63 | return block.note; |
| 64 | } |
| 65 | |
| 66 | const bodyText = (page: DocsPageDict, context: CapabilityContext, features: readonly Feature[] = FEATURE_CATALOGUE.features) => |
| 67 | resolveDocsPage(page, context, features).sections.map((section) => `${section.title} ${section.blocks.map(blockText).join(" ")}`).join(" "); |
| 68 | |
| 69 | const sourceText = (page: DocsPageDict, context: CapabilityContext, features: readonly Feature[] = FEATURE_CATALOGUE.features) => |
| 70 | resolveDocsPage(page, context, features).sourceSections.map((section) => `${section.title} ${section.blocks.map(blockText).join(" ")}`).join(" "); |
| 71 | |
| 72 | const PAGES: Record<string, (locale: string) => DocsPageDict> = { |
| 73 | account: getDocsAccount, auth: getDocsAuth, "claude-code": getDocsClaudeCode, configuration: getDocsConfiguration, |
| 74 | fleet: getDocsFleet, hooks: getDocsHooks, mcp: getDocsMcp, modes: getDocsModes, pet: getDocsPet, review: getDocsReview, |
| 75 | "runtime-api": getDocsRuntimeApi, sandbox: getDocsSandbox, skills: getDocsSkills, subagents: getDocsSubagents, |
| 76 | troubleshooting: getDocsTroubleshooting, trust: getDocsTrust, web: getDocsWeb, work: getDocsWork, |
| 77 | "first-time": getDocsFirstTime, |
| 78 | }; |
| 79 | |
| 80 | describe("docs describe the published release first", () => { |
| 81 | it("keeps the permission dial and Accept Edits out of every docs body for a release whose tagged rows predate them", () => { |
| 82 | for (const [slug, getPage] of Object.entries(PAGES)) { |
| 83 | for (const locale of ["en", "zh"]) { |
| 84 | const text = bodyText(getPage(locale), beforeTheDial); |
| 85 | expect(text, `${locale}/${slug}`).not.toMatch(/Accept Edits/); |
| 86 | expect(text, `${locale}/${slug}`).not.toMatch(/Ask → Accept Edits/); |
| 87 | } |
| 88 | } |
| 89 | const vocabulary = controlTermsFor(beforeTheDial).body.map((row) => row.term); |
| 90 | expect(vocabulary).toEqual(["Plan", "Work", "Operate", "Ask", "Auto-Review", "Full Access"]); |
| 91 | }); |
| 92 | |
| 93 | it("shows the in-source modes and dial only in the labelled section, and moves them into the body when a release carries them", () => { |
| 94 | const modes = getDocsModes("en"); |
| 95 | expect(sourceText(modes, beforeTheDial)).toMatch(/Accept Edits/); |
| 96 | expect(bodyText(modes, beforeTheDial)).toMatch(/Plan → Work → Operate/); |
| 97 | expect(bodyText(modes, beforeTheDial)).toMatch(/Ask → Auto-Review → Full Access/); |
| 98 | |
| 99 | expect(sourceText(modes, atTheDial)).toBe(""); |
| 100 | expect(bodyText(modes, atTheDial)).toMatch(/Accept Edits/); |
| 101 | |
| 102 | expect(sourceText(modes, raised, raisedFeatures)).toBe(""); |
| 103 | expect(bodyText(modes, raised, raisedFeatures)).toMatch(/Ask → Accept Edits → Plan → Auto-Review → Full Access/); |
| 104 | expect(bodyText(modes, raised, raisedFeatures)).not.toMatch(/Plan → Work → Operate/); |
| 105 | |
| 106 | const vocabulary = controlTermsFor(raised, raisedFeatures); |
| 107 | expect(vocabulary.source).toEqual([]); |
| 108 | expect(vocabulary.body.map((row) => row.term)).toEqual(["Plan", "Work", "Ask", "Accept Edits", "Auto-Review", "Full Access"]); |
| 109 | }); |
| 110 | |
| 111 | it("lists source-only tools in the labelled set and moves them into the list when released", () => { |
| 112 | const current = toolRowsFor(published, presentUnreleased); |
| 113 | expect(current.body.map((row) => row.name)).not.toContain("present"); |
| 114 | expect(current.source.map((row) => row.name)).toEqual(expect.arrayContaining(["present", "grep_files"])); |
| 115 | const next = toolRowsFor(raised, raisedFeatures); |
| 116 | expect(next.source).toEqual([]); |
| 117 | expect(next.body.map((row) => row.name)).toEqual(expect.arrayContaining(["present", "grep_files"])); |
| 118 | expect(next.body.map((row) => row.name)).not.toContain("workflow"); |
| 119 | }); |
| 120 | |
| 121 | it("shows no source section with no published release", () => { |
| 122 | const none: CapabilityContext = { release: null, baseline }; |
| 123 | expect(resolveDocsPage(getDocsModes("en"), none).sourceSections).toEqual([]); |
| 124 | }); |
| 125 | |
| 126 | it("names no other product in the claude-code page title, description, headings or topic label", () => { |
| 127 | const other = /claude|codex|cursor|copilot|gemini|kimi|antigravity|alternative/i; |
| 128 | for (const locale of ["en", "zh"]) { |
| 129 | const page = getDocsClaudeCode(locale); |
| 130 | expect(page.metaTitle).not.toMatch(other); |
| 131 | expect(page.metaDescription).not.toMatch(other); |
| 132 | expect(page.title).not.toMatch(other); |
| 133 | for (const section of page.sections) expect(section.title).not.toMatch(other); |
| 134 | } |
| 135 | const topic = DOC_TOPICS.find((entry) => entry.slug === "claude-code"); |
| 136 | expect(topic?.label.en).not.toMatch(other); |
| 137 | expect(topic?.description.en).not.toMatch(other); |
| 138 | }); |
| 139 | }); |
| 140 |