| 1 | import { existsSync, readFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { FACTS } from "./facts.generated"; |
| 4 | import { RELEASE_CONTRIBUTORS, RELEASE_HELPERS } from "./release-credits"; |
| 5 | import { EN_CHROME, EN_DOCS_SHELL, EN_HOME, getChrome } from "./i18n/dictionaries"; |
| 6 | |
| 7 | function pageSource(path: string): string { |
| 8 | return readFileSync(new URL(`../app/[locale]/${path}`, import.meta.url), "utf8"); |
| 9 | } |
| 10 | |
| 11 | describe("public website copy contracts", () => { |
| 12 | it("keeps the docs hub on the compact ocean portal instead of the old almanac treatment", () => { |
| 13 | const layout = pageSource("docs/layout.tsx"); |
| 14 | const search = readFileSync(new URL("../components/docs-search.tsx", import.meta.url), "utf8"); |
| 15 | |
| 16 | expect(layout).not.toContain("portal-mark"); |
| 17 | // The hero copy is dictionary-driven now (#5337), so assert it where the |
| 18 | // string actually lives rather than in the TSX. |
| 19 | expect(EN_DOCS_SHELL.heroTitle).toBe("Install and use Codewhale"); |
| 20 | expect(layout).not.toContain("Section 02"); |
| 21 | expect(layout).not.toContain("How Codewhale works: ego"); |
| 22 | expect(layout).not.toContain("<Seal"); |
| 23 | expect(layout.indexOf('<article className="docs-content')).toBeLessThan( |
| 24 | layout.indexOf("<DocsSidebar"), |
| 25 | ); |
| 26 | expect(search).toContain("docs-topic-row"); |
| 27 | expect(search).not.toContain("40+ Markdown documents"); |
| 28 | }); |
| 29 | |
| 30 | it("keeps unreleased managed-product surfaces out of public copy", () => { |
| 31 | const footer = readFileSync(new URL("../components/footer.tsx", import.meta.url), "utf8"); |
| 32 | |
| 33 | expect(footer).not.toContain("App preview"); |
| 34 | expect(footer).not.toContain("app.codewhale.net"); |
| 35 | |
| 36 | // Account entry is a real, working flow (sign-in and registration), so |
| 37 | // the chrome may name it. It must never call the app a "preview" or bake |
| 38 | // the app host into copy — the links own the destination. |
| 39 | for (const locale of [ |
| 40 | "en", "zh", "ja", "vi", "ko", "ru", "uk", "es", "pt-BR", "id", |
| 41 | "fr", "de", "ca", "hi", "tr", "it", "pl", "ar", |
| 42 | ]) { |
| 43 | const values = Object.values(getChrome(locale)).join("\n"); |
| 44 | expect(values, `${locale} chrome`).not.toContain("app.codewhale.net"); |
| 45 | expect(values, `${locale} chrome`).not.toMatch(/App preview/); |
| 46 | } |
| 47 | expect(EN_CHROME.footerLicense).toBe("MIT license"); |
| 48 | }); |
| 49 | |
| 50 | it("describes ACP and the VS Code extension at their implemented capability level", () => { |
| 51 | const runtime = readFileSync(new URL("./content/runtime-integrations.ts", import.meta.url), "utf8"); |
| 52 | const sourceDocTargets = [ |
| 53 | ...new Set( |
| 54 | [...runtime.matchAll(/REPO_BLOB_BASE}\/([^`]+)`/g)].map((match) => match[1]), |
| 55 | ), |
| 56 | ]; |
| 57 | |
| 58 | expect(runtime).toContain("ACP (Agent Client Protocol)"); |
| 59 | expect(runtime).toContain("ACP stdio connects compatible editors to the existing Engine"); |
| 60 | expect(runtime).toContain("Early companion for the local runtime"); |
| 61 | expect(runtime).not.toContain("Agent Communication Protocol"); |
| 62 | expect(runtime).not.toContain("IETF-standard"); |
| 63 | expect(runtime).not.toContain("embeds Codewhale as a side-panel agent"); |
| 64 | expect(runtime).not.toMatch(/\/(?:en|zh)\/docs#(?:runtime-api|acp|mcp)/); |
| 65 | expect(runtime).toContain("docs/RUNTIME_API.md"); |
| 66 | expect(runtime).toContain("docs/MCP.md"); |
| 67 | expect(sourceDocTargets).toEqual(["docs/RUNTIME_API.md", "docs/MCP.md"]); |
| 68 | for (const target of sourceDocTargets) { |
| 69 | expect(existsSync(new URL(`../../${target}`, import.meta.url)), target).toBe(true); |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | it("keeps source-candidate facts separate from published install facts", () => { |
| 74 | const homepage = pageSource("page.tsx"); |
| 75 | const install = pageSource("install/page.tsx"); |
| 76 | |
| 77 | expect(homepage).toContain("facts.latestPublishedRelease"); |
| 78 | // The home names only the published release; the source version never |
| 79 | // reaches it. |
| 80 | expect(homepage).toContain("fill(d.installNote, { version: release.version })"); |
| 81 | expect(homepage).not.toContain("facts.version"); |
| 82 | expect(EN_HOME.installNote).toBe("Version {version} is released, and it needs no account."); |
| 83 | expect(readFileSync(new URL("../components/release-updates.tsx", import.meta.url), "utf8")).toContain("href={release.url}"); |
| 84 | // A development-source route count is not a released-provider total. |
| 85 | expect(homepage).not.toContain("<span>{providerRoutes}</span>"); |
| 86 | expect(homepage).not.toContain("releases/tag/v${version}"); |
| 87 | expect(homepage).not.toMatch(/Codewhale v0\.9\.1|\"v0\.9\.1 \u00b7/); |
| 88 | expect(install).toContain("facts.latestPublishedRelease"); |
| 89 | expect(install).not.toContain("facts.version"); |
| 90 | expect(install).not.toContain('"v0.8.x"'); |
| 91 | expect(install).not.toContain("cnbInstall(facts.version"); |
| 92 | }); |
| 93 | |
| 94 | it("presents providers as peers", () => { |
| 95 | const providerCopy = `${pageSource("models/page.tsx")}\n${pageSource("faq/page.tsx")}`; |
| 96 | |
| 97 | expect(providerCopy).not.toMatch(/first-class|一级支持|一级模型/); |
| 98 | }); |
| 99 | |
| 100 | it("keeps current-release website credits in exact changelog parity", () => { |
| 101 | expect(FACTS.version).toBeTruthy(); |
| 102 | const changelog = readFileSync(new URL("../../CHANGELOG.md", import.meta.url), "utf8"); |
| 103 | const release = changelog |
| 104 | .split(`## [${FACTS.version}]`)[1] |
| 105 | ?.split("\n## ")[0]; |
| 106 | const contributorSection = release |
| 107 | ?.split("### Contributors")[1] |
| 108 | ?.split("\n### ")[0]; |
| 109 | expect(contributorSection, `missing ${FACTS.version} contributor ledger`).toBeTruthy(); |
| 110 | |
| 111 | const changelogHandles = [ |
| 112 | ...new Set(contributorSection?.match(/@[A-Za-z0-9_-]+/g) ?? []), |
| 113 | ].sort(); |
| 114 | const websiteHandles = [...RELEASE_CONTRIBUTORS, ...RELEASE_HELPERS]; |
| 115 | const contributorDoc = readFileSync( |
| 116 | new URL("../../docs/CONTRIBUTORS.md", import.meta.url), |
| 117 | "utf8", |
| 118 | ); |
| 119 | const currentDocBand = contributorDoc |
| 120 | .split(`<summary><strong>v${FACTS.version} `)[1] |
| 121 | ?.split("</details>")[0]; |
| 122 | expect(currentDocBand, `missing ${FACTS.version} contributor-doc band`).toBeTruthy(); |
| 123 | const docHandles = [ |
| 124 | ...new Set( |
| 125 | [...(currentDocBand?.matchAll(/github\.com\/([A-Za-z0-9_-]+)\)/g) ?? [])].map( |
| 126 | (match) => `@${match[1]}`, |
| 127 | ), |
| 128 | ), |
| 129 | ].sort(); |
| 130 | |
| 131 | expect(new Set(websiteHandles).size, "credit arrays must not overlap or repeat").toBe( |
| 132 | websiteHandles.length, |
| 133 | ); |
| 134 | expect([...websiteHandles].sort()).toEqual(changelogHandles); |
| 135 | expect(docHandles).toEqual(changelogHandles); |
| 136 | }); |
| 137 | }); |
| 138 |