返回 CodeWhale
public-copy.test.ts
根目录 / web / lib / public-copy.test.ts
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_COMMUNITY, 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).toContain("docs-portal-band");
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("Get something done with 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 roadmap = pageSource("roadmap/page.tsx");
32 const footer = readFileSync(new URL("../components/footer.tsx", import.meta.url), "utf8");
33
34 expect(roadmap).toContain("Required account for the local runtime");
35 expect(roadmap).not.toContain("Managed app preview");
36 expect(roadmap).not.toContain("Hosted SaaS dashboard");
37 expect(roadmap).not.toContain("Required login / accounts");
38 expect(footer).not.toContain("App preview");
39 expect(footer).not.toContain("app.codewhale.net");
40
41 // Account entry is a real, working flow (sign-in and registration), so
42 // the chrome may name it. It must never call the app a "preview" or bake
43 // the app host into copy — the links own the destination.
44 for (const locale of [
45 "en", "zh", "ja", "vi", "ko", "ru", "uk", "es", "pt-BR", "id",
46 "fr", "de", "ca", "hi", "tr", "it", "pl", "ar",
47 ]) {
48 const values = Object.values(getChrome(locale)).join("\n");
49 expect(values, `${locale} chrome`).not.toContain("app.codewhale.net");
50 expect(values, `${locale} chrome`).not.toMatch(/App preview/);
51 }
52 expect(EN_CHROME.footerLicense).toBe("MIT license");
53 });
54
55 it("describes ACP and the VS Code extension at their implemented capability level", () => {
56 const runtime = pageSource("runtime/page.tsx");
57 const sourceDocTargets = [
58 ...new Set(
59 [...runtime.matchAll(/REPO_BLOB_BASE}\/([^`]+)`/g)].map((match) => match[1]),
60 ),
61 ];
62
63 expect(runtime).toContain("ACP (Agent Client Protocol)");
64 expect(runtime).toContain("Baseline JSON-RPC adapter over stdio");
65 expect(runtime).toContain("Early companion for the local runtime");
66 expect(runtime).not.toContain("Agent Communication Protocol");
67 expect(runtime).not.toContain("IETF-standard");
68 expect(runtime).not.toContain("embeds Codewhale as a side-panel agent");
69 expect(runtime).not.toMatch(/\/(?:en|zh)\/docs#(?:runtime-api|acp|mcp)/);
70 expect(runtime).toContain("docs/RUNTIME_API.md");
71 expect(runtime).toContain("docs/MCP.md");
72 expect(sourceDocTargets).toEqual(["docs/RUNTIME_API.md", "docs/MCP.md"]);
73 for (const target of sourceDocTargets) {
74 expect(existsSync(new URL(`../../${target}`, import.meta.url)), target).toBe(true);
75 }
76 });
77
78 it("keeps source-candidate facts separate from published install facts", () => {
79 const homepage = pageSource("page.tsx");
80 const install = pageSource("install/page.tsx");
81 const community = pageSource("community/page.tsx");
82
83 expect(homepage).toContain("facts.latestPublishedRelease");
84 // The machine-readable source-state attribute stays a literal.
85 expect(homepage).toContain('data-source-state={sourceIsPublished ? "published release" : "source candidate"}');
86 expect(homepage).toContain("publishedRelease.url");
87 // The visible wording moved into the dictionary layer (#4934). Assert the
88 // rendered contract — the EN reference value plus the page's use of it —
89 // instead of a raw TSX string, and hold every locale to a real value.
90 expect(homepage).toContain("d.sourceCandidate");
91 expect(homepage).toContain("d.currentSource");
92 // Plain words on the marketing surface (docs/design/WEB_VOICE.md): the
93 // reader sees "Unreleased v0.9.x" next to "Latest release v0.9.y", not
94 // the internal "source candidate" / "provider routes" vocabulary.
95 expect(EN_HOME.sourceCandidate).toBe("Unreleased");
96 expect(EN_HOME.currentSource).toBe("Source");
97 // A development-source route count is not a released-provider total.
98 expect(homepage).not.toContain("<span>{providerRoutes}</span>");
99 expect(homepage).not.toContain("releases/tag/v${version}");
100 expect(homepage).not.toMatch(/Codewhale v0\.9\.1|\"v0\.9\.1 \u00b7/);
101 // Installation examples come from the verified guide, never the candidate version.
102 expect(install).toContain("INSTALL_GUIDE.chunks");
103 expect(install).not.toContain("facts.version");
104 expect(install).not.toContain('"v0.8.x"');
105 expect(install).not.toContain("cnbInstall(facts.version");
106 // The community credit wording moved into its dictionary (#5337) the same
107 // way: the page picks the unreleased label, and the EN reference says so.
108 expect(community).toContain("t.creditLabelUnreleased");
109 expect(EN_COMMUNITY.creditLabelUnreleased).toBe("v{version} credit (unreleased)");
110 });
111
112 it("presents providers as peers and puts contributor actions near the top", () => {
113 const providerCopy = `${pageSource("models/page.tsx")}\n${pageSource("faq/page.tsx")}`;
114 const community = pageSource("community/page.tsx");
115 // The page's own wording lives in its dictionary (#5337); the paths and
116 // links stay in the page.
117 const communityCopy = `${community}\n${Object.values(EN_COMMUNITY).join("\n")}`;
118
119 expect(providerCopy).not.toMatch(/first-class|一级支持|一级模型/);
120 expect(community).toContain("t.kicker");
121 expect(EN_COMMUNITY.kicker).toBe("International open-source community");
122 expect(community).toContain("issues/new/choose");
123 expect(community).toContain("docs/LOCALIZATION.md");
124 expect(community).toContain("codewhale-hq/CodeWhale/pulls");
125 expect(community).toContain("t.recordScope");
126 expect(EN_COMMUNITY.recordScope).toContain("keeps the weekly archive of repository activity");
127 expect(communityCopy).not.toContain("latest one sits near the top");
128 expect(community).not.toContain("<Ticker");
129 expect(community).not.toContain("<StatGrid");
130 expect(communityCopy).not.toContain("Today's dispatch");
131 });
132
133 it("keeps current-release website credits in exact changelog parity", () => {
134 expect(FACTS.version).toBeTruthy();
135 const changelog = readFileSync(new URL("../../CHANGELOG.md", import.meta.url), "utf8");
136 const release = changelog
137 .split(`## [${FACTS.version}]`)[1]
138 ?.split("\n## ")[0];
139 const contributorSection = release
140 ?.split("### Contributors")[1]
141 ?.split("\n### ")[0];
142 expect(contributorSection, `missing ${FACTS.version} contributor ledger`).toBeTruthy();
143
144 const changelogHandles = [
145 ...new Set(contributorSection?.match(/@[A-Za-z0-9_-]+/g) ?? []),
146 ].sort();
147 const websiteHandles = [...RELEASE_CONTRIBUTORS, ...RELEASE_HELPERS];
148 const contributorDoc = readFileSync(
149 new URL("../../docs/CONTRIBUTORS.md", import.meta.url),
150 "utf8",
151 );
152 const currentDocBand = contributorDoc
153 .split(`<summary><strong>v${FACTS.version} `)[1]
154 ?.split("</details>")[0];
155 expect(currentDocBand, `missing ${FACTS.version} contributor-doc band`).toBeTruthy();
156 const docHandles = [
157 ...new Set(
158 [...(currentDocBand?.matchAll(/github\.com\/([A-Za-z0-9_-]+)\)/g) ?? [])].map(
159 (match) => `@${match[1]}`,
160 ),
161 ),
162 ].sort();
163
164 expect(new Set(websiteHandles).size, "credit arrays must not overlap or repeat").toBe(
165 websiteHandles.length,
166 );
167 expect([...websiteHandles].sort()).toEqual(changelogHandles);
168 expect(docHandles).toEqual(changelogHandles);
169 });
170 });
171
171 lines TYPESCRIPT