返回 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_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("Find the guidance you need.");
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("Phase 0 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 expect(install).toContain("publishedRelease.tag");
102 expect(install).not.toContain('"v0.8.x"');
103 expect(install).not.toContain("cnbInstall(facts.version");
104 expect(community).toContain("credit (unreleased)");
105 });
106
107 it("presents providers as peers and puts contributor actions near the top", () => {
108 const providerCopy = `${pageSource("models/page.tsx")}\n${pageSource("faq/page.tsx")}`;
109 const community = pageSource("community/page.tsx");
110
111 expect(providerCopy).not.toMatch(/first-class|一级支持|一级模型/);
112 expect(community).toContain("International open-source community");
113 expect(community).toContain("issues/new/choose");
114 expect(community).toContain("docs/LOCALIZATION.md");
115 expect(community).toContain("Hmbown/CodeWhale/pulls");
116 expect(community).toContain("keeps the weekly archive of repository activity");
117 expect(community).not.toContain("latest one sits near the top");
118 expect(community).not.toContain("<Ticker");
119 expect(community).not.toContain("<StatGrid");
120 expect(community).not.toContain("Today's dispatch");
121 });
122
123 it("keeps current-release website credits in exact changelog parity", () => {
124 expect(FACTS.version).toBeTruthy();
125 const changelog = readFileSync(new URL("../../CHANGELOG.md", import.meta.url), "utf8");
126 const release = changelog
127 .split(`## [${FACTS.version}]`)[1]
128 ?.split("\n## ")[0];
129 const contributorSection = release
130 ?.split("### Contributors")[1]
131 ?.split("\n### ")[0];
132 expect(contributorSection, `missing ${FACTS.version} contributor ledger`).toBeTruthy();
133
134 const changelogHandles = [
135 ...new Set(contributorSection?.match(/@[A-Za-z0-9_-]+/g) ?? []),
136 ].sort();
137 const websiteHandles = [...RELEASE_CONTRIBUTORS, ...RELEASE_HELPERS];
138 const contributorDoc = readFileSync(
139 new URL("../../docs/CONTRIBUTORS.md", import.meta.url),
140 "utf8",
141 );
142 const currentDocBand = contributorDoc
143 .split(`<summary><strong>v${FACTS.version} `)[1]
144 ?.split("</details>")[0];
145 expect(currentDocBand, `missing ${FACTS.version} contributor-doc band`).toBeTruthy();
146 const docHandles = [
147 ...new Set(
148 [...(currentDocBand?.matchAll(/github\.com\/([A-Za-z0-9_-]+)\)/g) ?? [])].map(
149 (match) => `@${match[1]}`,
150 ),
151 ),
152 ].sort();
153
154 expect(new Set(websiteHandles).size, "credit arrays must not overlap or repeat").toBe(
155 websiteHandles.length,
156 );
157 expect([...websiteHandles].sort()).toEqual(changelogHandles);
158 expect(docHandles).toEqual(changelogHandles);
159 });
160 });
161
161 lines TYPESCRIPT