返回 CodeWhale
public-surface-contract.test.ts
根目录 / web / lib / public-surface-contract.test.ts
1 import {
2 chmodSync,
3 existsSync,
4 mkdtempSync,
5 readFileSync,
6 rmSync,
7 statSync,
8 writeFileSync,
9 } from "node:fs";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { spawnSync } from "node:child_process";
13 import { describe, expect, it } from "vitest";
14 import { FACTS } from "./facts.generated";
15 import { SNIPPETS, VERIFY } from "./install-binary-snippets";
16 import { INSTALL_GUIDE } from "./install-guide.generated";
17 import { getChrome } from "./i18n/dictionaries";
18 import { footerProjectLinks } from "./i18n/links";
19 import { TERMINAL_SCREENSHOT } from "./media-manifest";
20 import { PRODUCT_COPY } from "./content/product";
21
22 const root = new URL("../../", import.meta.url);
23
24 type PublicSurfaceMatrix = {
25 schemaVersion: number;
26 product: {
27 name: string;
28 description: string;
29 license: string;
30 terminology: Record<string, string>;
31 };
32 sourceCandidate: {
33 version: string;
34 providerCount: number;
35 toolCount: number;
36 sandboxBackends: string[];
37 };
38 latestPublishedRelease: {
39 tag: string;
40 version: string;
41 publishedAt: string;
42 url: string;
43 };
44 install: {
45 recommended: string;
46 binaries: string[];
47 channels: Record<string, string>;
48 androidTermux: {
49 status: string;
50 npm: string;
51 requiresMatchingPublishedAssets: boolean;
52 sourceBuild: boolean;
53 };
54 };
55 control: {
56 scope: string;
57 modes: string[];
58 permissionPostures: string[];
59 permissionDial: string[];
60 defaultPermissionPosture: string;
61 retiredModeAliases: Record<string, string>;
62 shortcuts: {
63 completion: { chord: string; when: string };
64 permissionDial: { chord: string; when: string };
65 };
66 };
67 toolSurface: {
68 defaultActive: string[];
69 schemas: Record<string, string[]>;
70 deferred: Record<string, string[]>;
71 compatibility: {
72 legacyAliases: string;
73 modelVisible: boolean;
74 toolSearchDiscoverable: boolean;
75 };
76 activationCache: {
77 maximumNames: number;
78 maximumSchemaBytes: number;
79 limitKind: string;
80 pinnedCeilingMultiplier: number;
81 scope: string;
82 };
83 agentConcurrency: {
84 defaultConfigured: number;
85 maximumConfigured: number;
86 maximumAdmitted: number;
87 };
88 };
89 surfaces: { availableInSourceCandidate: string[] };
90 trust: Record<string, string>;
91 repository: {
92 canonical: string;
93 mirrors: string[];
94 creditSources: string[];
95 requiredCandidateCredits: string[];
96 };
97 screenshot: {
98 readme: string;
99 website: string;
100 sourceVersion: string | null;
101 sourceCommit: string | null;
102 model: string;
103 terminal: string;
104 capture: string;
105 sources: string[];
106 };
107 [key: string]: unknown;
108 };
109
110 const matrix = JSON.parse(text("docs/public-surface-facts.json")) as PublicSurfaceMatrix;
111
112 function text(path: string): string {
113 return readFileSync(new URL(path, root), "utf8");
114 }
115
116 function bytes(path: string): Buffer {
117 return readFileSync(new URL(path, root));
118 }
119
120 function pngDimensions(image: Buffer): [number, number] {
121 expect(image.subarray(1, 4).toString("ascii")).toBe("PNG");
122 return [image.readUInt32BE(16), image.readUInt32BE(20)];
123 }
124
125 /**
126 * Dimensions of the canonical product screenshot. It is a lossless VP8L WebP,
127 * so the size lives in the 14-bit-packed VP8L header rather than a PNG IHDR;
128 * PNG is still accepted so this keeps working if the asset is ever swapped back.
129 */
130 function imageDimensions(image: Buffer): [number, number] {
131 if (image.subarray(1, 4).toString("ascii") === "PNG") return pngDimensions(image);
132 expect(image.subarray(0, 4).toString("ascii")).toBe("RIFF");
133 expect(image.subarray(8, 12).toString("ascii")).toBe("WEBP");
134 const chunk = image.subarray(12, 16).toString("ascii");
135 expect(chunk, "expected a lossless VP8L screenshot").toBe("VP8L");
136 // VP8L: 1 signature byte, then width-1 and height-1 as 14-bit LE fields.
137 const bits = image.readUInt32LE(21);
138 return [(bits & 0x3fff) + 1, ((bits >> 14) & 0x3fff) + 1];
139 }
140
141 function comparableVersion(value: string): number {
142 const [major = 0, minor = 0, patch = 0] = value.split(".").map((n) => Number.parseInt(n, 10) || 0);
143 return major * 1_000_000 + minor * 1_000 + patch;
144 }
145
146 describe("public surface contracts", () => {
147 it("keeps source-candidate and published-release facts distinct and aligned", () => {
148 expect(matrix.schemaVersion).toBe(2);
149 expect(matrix.sourceCandidate.version).toBe(FACTS.version);
150 expect(matrix.sourceCandidate.providerCount).toBe(FACTS.providers.length);
151 expect(matrix.sourceCandidate.toolCount).toBe(FACTS.toolCount);
152 expect(matrix.sourceCandidate.sandboxBackends).toEqual(FACTS.sandboxBackends);
153 expect({
154 tag: matrix.latestPublishedRelease.tag,
155 version: matrix.latestPublishedRelease.version,
156 publishedAt: matrix.latestPublishedRelease.publishedAt,
157 url: matrix.latestPublishedRelease.url,
158 }).toEqual({
159 tag: FACTS.latestPublishedRelease?.tag,
160 version: FACTS.latestPublishedRelease?.version,
161 publishedAt: FACTS.latestPublishedRelease?.publishedAt,
162 url: FACTS.latestPublishedRelease?.url,
163 });
164 // The published release may equal the source candidate: that is the normal
165 // state in the window between shipping vX.Y.Z and opening the next lane.
166 // What must never happen is the site advertising a version that is not
167 // published yet, so assert published <= source candidate rather than
168 // asserting they differ.
169 expect(comparableVersion(matrix.latestPublishedRelease.version)).toBeLessThanOrEqual(
170 comparableVersion(matrix.sourceCandidate.version),
171 );
172 expect(matrix.latestPublishedRelease).not.toHaveProperty("providerCount");
173 expect(matrix.latestPublishedRelease).not.toHaveProperty("toolCount");
174 expect(matrix.surfaces).not.toHaveProperty("stable");
175 expect(matrix.surfaces.availableInSourceCandidate).toContain("Web client");
176 // A capture may identify an exact build or explicitly remain an unversioned
177 // current session. Never infer release provenance from pixels alone.
178 const screenshotSourceVersion = matrix.screenshot.sourceVersion;
179 if (screenshotSourceVersion !== null) {
180 expect(comparableVersion(screenshotSourceVersion)).toBeLessThanOrEqual(
181 comparableVersion(matrix.sourceCandidate.version),
182 );
183 expect(matrix.screenshot.sourceCommit).toMatch(/^[0-9a-f]{40}$/);
184 } else {
185 expect(matrix.screenshot.sourceCommit).toBeNull();
186 expect(matrix.screenshot.capture).toContain("no published-release or exact-candidate claim");
187 }
188 });
189
190 it("backs product and install claims with package and documentation content", () => {
191 const readme = text("README.md");
192 const npmReadme = text("npm/codewhale/README.md");
193 const install = text("docs/INSTALL.md");
194 const changelog = text("CHANGELOG.md");
195 const license = text("LICENSE");
196 const npmArtifacts = text("npm/codewhale/scripts/artifacts.js");
197 const npmPackage = JSON.parse(text("npm/codewhale/package.json")) as {
198 description: string;
199 bin: Record<string, string>;
200 };
201
202 expect(matrix.product.name).toBe("Codewhale");
203 expect(matrix.product.license).toBe("MIT");
204 expect(matrix.product.description).toBe(npmPackage.description);
205 expect(license).toContain("MIT License");
206 expect(matrix.install.recommended).toBe("curl -fsSL https://codewhale.net/install.sh | sh");
207 expect(readme).toContain(matrix.install.recommended);
208 expect(Object.keys(npmPackage.bin)).toEqual(matrix.install.binaries);
209 expect(matrix.install.channels).toEqual({
210 npm: "published releases only",
211 cargo: "published crates only",
212 prebuiltArchives: "published GitHub Releases only",
213 cnbMirror: "documented targets only",
214 });
215 expect(matrix.install.androidTermux).toEqual({
216 status: "preview",
217 npm: "preview",
218 requiresMatchingPublishedAssets: true,
219 sourceBuild: true,
220 });
221 // Pinned to FACTS.version, not a literal: these assertions used to carry
222 // the version number by hand, so every release bump broke them and the
223 // failure looked like a copy defect rather than a stale test.
224 expect(install).toContain(`v${FACTS.version} source candidate`);
225 expect(install).toContain("unpublished source candidate");
226 const androidRow = install.split("\n").find((line) => line.startsWith("| Android / Termux |"));
227 expect(androidRow).toContain("arm64 (aarch64)");
228 expect(androidRow).toContain("`codewhale-android-arm64.tar.gz`");
229 expect(androidRow).toContain("⚠️⁴ preview");
230 expect(install).not.toContain(`wrapper is published at\nv${FACTS.version}`);
231 expect(npmReadme).toMatch(/^- Android arm64 \/ Termux \(preview;/m);
232 expect(npmReadme).toContain("requires matching Android assets");
233 expect(npmArtifacts).toContain("android: {");
234 for (const binary of ["codewhale-android-arm64", "codew-android-arm64"]) {
235 expect(npmArtifacts).toContain(binary);
236 }
237 // Matched by string prefix rather than by building a RegExp from
238 // FACTS.version: escaping only `.` left backslashes unescaped, which
239 // CodeQL flagged as incomplete escaping. The version needs no regex.
240 const heading = `## [${FACTS.version}] - `;
241 const headingLine = changelog
242 .split("\n")
243 .find((line) => line.startsWith(heading));
244 expect(headingLine, `missing "${heading}" changelog heading`).toBeTruthy();
245 const headingSuffix = headingLine?.slice(heading.length) ?? "";
246 expect(headingSuffix).toMatch(/^(?:Unreleased candidate|\d{4}-\d{2}-\d{2})$/);
247 if (headingSuffix === "Unreleased candidate") {
248 // Pre-tag candidate: notes still call it a source candidate, and the
249 // version compare link must not claim a tagged endpoint yet.
250 expect(changelog).toContain(`v${FACTS.version} source candidate`);
251 expect(changelog).not.toContain(`compare/v${FACTS.version}...HEAD`);
252 } else {
253 // Dated release: intro names the version, and the version's compare
254 // link points at a tag range (Unreleased may still use ...HEAD).
255 expect(changelog).toContain(`Codewhale v${FACTS.version}`);
256 const versionCompare = changelog
257 .split("\n")
258 .find((line) => line.startsWith(`[${FACTS.version}]: `));
259 expect(versionCompare, `missing [${FACTS.version}] compare link`).toBeTruthy();
260 expect(versionCompare).toContain(`...v${FACTS.version}`);
261 expect(versionCompare).not.toContain("...HEAD");
262 }
263 });
264
265 it("keeps one runtime and channel-specific command names exact", () => {
266 const installDoc = text("docs/INSTALL.md");
267 const installPage = text("web/app/[locale]/install/page.tsx");
268 const npmReadme = text("npm/codewhale/README.md");
269 const cliCargo = text("crates/cli/Cargo.toml");
270 const cargoBinaryNames = Array.from(
271 cliCargo.matchAll(/\[\[bin\]\]\s+name = "([^"]+)"/g),
272 (match) => match[1],
273 );
274
275 expect(matrix.install.binaries).toEqual(["codewhale", "codew"]);
276 expect(cargoBinaryNames).toEqual(["codewhale"]);
277 expect(installDoc).toContain("One Cargo package is required");
278 expect(installDoc).toContain("`codewhale-cli` installs the `codewhale` command");
279 expect(installDoc).toContain("Cargo does\nnot create that alias");
280 expect(INSTALL_GUIDE.chunks.some((chunk) => chunk.kind === "code" && chunk.text.includes("cargo install --path crates/cli --locked"))).toBe(true);
281 expect(installPage).not.toContain("codewhale-tui");
282 expect(npmReadme).toContain("installs `codewhale` plus the `codew` convenience name");
283 expect(npmReadme).not.toContain("codewhale-tui");
284 for (const platform of [
285 "macos-arm64",
286 "macos-x64",
287 "linux-arm64",
288 "linux-x64",
289 ] as const) {
290 expect(SNIPPETS[platform], platform).toContain(`codew-${platform}`);
291 expect(SNIPPETS[platform], platform).toContain(
292 `sudo mv codew-${platform} /usr/local/bin/codew`,
293 );
294 expect(SNIPPETS[platform], platform).not.toContain("codewhale-tui");
295 expect(VERIFY[platform], platform).not.toContain("codewhale-tui");
296 }
297 for (const arch of ["x64", "arm64"] as const) {
298 expect(SNIPPETS[`windows-${arch}`], arch).toContain(`codew-windows-${arch}.exe`);
299 expect(SNIPPETS[`windows-${arch}`], arch).toContain(
300 'Get-FileHash "$dest\\codew.exe"',
301 );
302 expect(SNIPPETS[`windows-${arch}`], arch).not.toContain("codewhale-tui");
303 expect(VERIFY[`windows-${arch}`], arch).not.toContain("codewhale-tui");
304 }
305 });
306
307 it("checks Unix release assets under their manifest filenames before renaming", () => {
308 const scratch = mkdtempSync(join(tmpdir(), "codewhale-install-checksum-"));
309 const mockBin = join(scratch, "bin");
310 const curlPath = join(mockBin, "curl");
311 const checksumPath = join(mockBin, "checksum");
312
313 try {
314 const mkdir = spawnSync("/bin/mkdir", ["-p", mockBin]);
315 expect(mkdir.status, mkdir.stderr.toString()).toBe(0);
316
317 writeFileSync(
318 curlPath,
319 `#!/bin/sh
320 output=""
321 url=""
322 while [ "$#" -gt 0 ]; do
323 case "$1" in
324 -o) shift; output="$1" ;;
325 http*) url="$1" ;;
326 esac
327 shift
328 done
329 [ -n "$output" ] || output=$(basename "$url")
330 if [ "$output" = codewhale-artifacts-sha256.txt ]; then
331 for platform in macos-arm64 macos-x64 linux-arm64 linux-x64; do
332 for binary in codewhale codew; do
333 printf 'fixture-hash %s-%s\\n' "$binary" "$platform"
334 done
335 done > "$output"
336 else
337 printf 'fixture payload for %s\\n' "$output" > "$output"
338 fi
339 `,
340 );
341 writeFileSync(
342 checksumPath,
343 `#!/bin/sh
344 while [ "$#" -gt 0 ]; do shift; done
345 while read -r _hash filename; do
346 if [ ! -f "$filename" ]; then
347 echo "manifest target missing: $filename" >&2
348 exit 1
349 fi
350 done
351 `,
352 );
353 chmodSync(curlPath, 0o755);
354 chmodSync(checksumPath, 0o755);
355 for (const command of ["shasum", "sha256sum"]) {
356 const link = spawnSync("/bin/ln", ["-s", checksumPath, join(mockBin, command)]);
357 expect(link.status, link.stderr.toString()).toBe(0);
358 }
359
360 for (const platform of [
361 "macos-arm64",
362 "macos-x64",
363 "linux-arm64",
364 "linux-x64",
365 ] as const) {
366 const lines = SNIPPETS[platform].split("\n");
367 const checksumLine = lines.findIndex((line) => line.includes(" -c -"));
368 expect(checksumLine, platform).toBeGreaterThan(-1);
369 const result = spawnSync(
370 "/bin/bash",
371 ["-o", "pipefail", "-eu", "-c", lines.slice(0, checksumLine + 1).join("\n")],
372 {
373 cwd: scratch,
374 env: { ...process.env, PATH: `${mockBin}:${process.env.PATH ?? ""}` },
375 },
376 );
377 expect(result.status, `${platform}: ${result.stderr.toString()}`).toBe(0);
378 }
379 } finally {
380 rmSync(scratch, { recursive: true, force: true });
381 }
382 });
383
384 it("qualifies the resolved audit path and best-effort persistence", () => {
385 const installPage = text("web/app/[locale]/install/page.tsx");
386
387 expect(matrix.trust.audit).toContain("best-effort");
388 expect(matrix.trust.audit).toContain("$CODEWHALE_HOME");
389 expect(installPage).not.toContain(
390 "audit.log credential / approval / elevation audit trail",
391 );
392 });
393
394 it("keeps source-candidate modes and permission controls aligned with runtime authority", () => {
395 const modes = text("docs/MODES.md");
396 const keys = text("docs/KEYBINDINGS.md");
397 const appModes = text("crates/config/src/app_mode.rs");
398 const approvals = text("crates/execpolicy/src/approval_mode.rs");
399 const app = text("crates/tui/src/tui/app.rs");
400 const init = text("crates/tui/src/tui/app/init.rs");
401
402 expect(matrix.control.scope).toContain(`${FACTS.version} source candidate`);
403 expect(matrix.control.modes).toEqual(["Plan", "Work"]);
404 expect(appModes).toMatch(/pub enum AppMode\s*\{\s*Agent,\s*Plan,\s*\}/);
405 expect(matrix.control.permissionPostures).toEqual(["Ask", "Accept Edits", "Auto-Review", "Full Access"]);
406 expect(approvals).toMatch(/PERMISSION_CYCLE:[\s\S]*?Self::Suggest, Self::AcceptEdits, Self::Auto, Self::Bypass/);
407 expect(matrix.control.permissionDial).toEqual(["Ask", "Accept Edits", "Plan", "Auto-Review", "Full Access"]);
408 expect(app).toContain("ApprovalMode::AcceptEdits => (AppMode::Plan, ApprovalMode::AcceptEdits)");
409 expect(matrix.control.defaultPermissionPosture).toBe("Accept Edits");
410 expect(init).toMatch(/explicit_approval_mode\s*\.or\(saved_permission_posture\)/);
411 expect(init).toMatch(/unwrap_or\(if approval_policy_locked \{\s*ApprovalMode::Suggest\s*\} else \{\s*ApprovalMode::AcceptEdits/);
412 expect(matrix.control.retiredModeAliases).toEqual({ Operate: "Work" });
413 expect(appModes).toContain("Self::is_retired_operate_alias(other) => Some(Self::Agent)");
414 expect(matrix.control.shortcuts).toEqual({
415 completion: { chord: "Tab", when: "composer completion only" },
416 permissionDial: {
417 chord: "Shift+Tab",
418 when: "always (suppressed only under a non-Config modal)",
419 },
420 });
421 for (const label of [...matrix.control.modes, ...matrix.control.permissionPostures]) {
422 expect(modes).toContain(label);
423 }
424 expect(PRODUCT_COPY.modes.map(({ title }) => title.en)).toEqual(matrix.control.modes);
425 expect(PRODUCT_COPY.permissions.map(({ title }) => title.en)).toEqual(matrix.control.permissionPostures);
426 expect(modes).toContain("it never changes the mode");
427 expect(modes).toContain("Operate is retired");
428 expect(keys).toContain("Tab never changes the mode");
429 expect(keys).toContain("Ask → Accept Edits → Plan → Auto-Review → Full Access → Ask");
430 });
431
432 it("keeps public tool facts aligned with the native core and discovery boundaries", () => {
433 const toolDoc = text("docs/TOOL_SURFACE.md");
434 const toolsPage = text("web/app/[locale]/docs/tools/page.tsx") + text("web/lib/content/tools.ts");
435 const registry = text("crates/engine/src/tools/registry.rs");
436 const limits = text("crates/runtime/src/config/subagent_limits.rs");
437 const catalog = text("crates/engine/src/core/engine/tool_catalog.rs");
438 const nativeCore = catalog.match(/const DEFAULT_ACTIVE_NATIVE_TOOLS: &[\s\S]*?= &\[([\s\S]*?)\];/);
439 expect(nativeCore, "native core declaration must be found").not.toBeNull();
440 const nativeNames = [...nativeCore![1].matchAll(/"([^"\n]+)"/g)].map((match) => match[1]);
441 expect(nativeNames.length).toBeGreaterThan(0);
442 expect(matrix.toolSurface.defaultActive).toEqual(nativeNames);
443 expect(matrix.toolSurface.schemas).toEqual({
444 read: ["path", "offset?", "limit?"],
445 write: ["path", "content"],
446 edit: ["path", "edits"],
447 bash: ["command", "timeout?"],
448 });
449 expect(matrix.toolSurface.deferred).toEqual({ Web: ["search", "fetch", "wait"] });
450 expect(matrix.toolSurface.compatibility).toEqual({
451 legacyAliases: "hidden-exact",
452 modelVisible: false,
453 toolSearchDiscoverable: false,
454 });
455 expect(matrix.toolSurface.activationCache).toEqual({
456 maximumNames: 16,
457 maximumSchemaBytes: 32_768,
458 limitKind: "soft eviction targets",
459 pinnedCeilingMultiplier: 2,
460 scope: "per conversation; each subagent owns an independent policy-filtered cache",
461 });
462 expect(matrix.toolSurface.agentConcurrency).toEqual({
463 defaultConfigured: 64,
464 maximumConfigured: 128,
465 maximumAdmitted: 1024,
466 });
467 expect(limits).toContain("DEFAULT_MAX_SUBAGENTS: usize = 64");
468 expect(limits).toContain("MAX_SUBAGENTS: usize = 128");
469 expect(limits).toContain("MAX_SUBAGENT_ADMISSION: usize = 1024");
470 for (const deferred of ["workflow", "context_archive_search"]) {
471 expect(nativeNames).not.toContain(deferred);
472 expect(catalog).toContain(deferred);
473 expect(toolDoc).toContain(deferred);
474 }
475 for (const name of matrix.toolSurface.defaultActive) {
476 expect(toolDoc, name).toContain(`\`${name}\``);
477 expect(toolsPage, name).toContain(name);
478 }
479 expect(toolDoc).toContain("`Web` is conditional and deferred");
480 expect(toolDoc).toContain("Each subagent gets its own policy-filtered deferred catalog");
481 expect(toolDoc).toContain("Unknown or retired names fail closed");
482 expect(registry).toContain("Arc::new(ReadTool)");
483 expect(registry).toContain("Arc::new(WriteTool)");
484 expect(registry).toContain("Arc::new(EditTool)");
485 expect(registry).toContain("Arc::new(LowercaseBashTool)");
486 for (const tool of ["ReadFileTool", "WriteFileTool", "EditFileTool"]) {
487 expect(registry).toContain(`Arc::new(${tool})`);
488 }
489 expect(registry).not.toContain('FileTool::new("File")');
490 expect(registry).not.toContain('BashTool::new("Bash")');
491 const session = text("crates/engine/src/core/session.rs");
492 const cache = matrix.toolSurface.activationCache;
493 expect(session).toContain(`TOOL_ACTIVATION_CACHE_MAX_NAMES: usize = ${cache.maximumNames};`);
494 expect(session).toContain(`TOOL_ACTIVATION_CACHE_MAX_SCHEMA_BYTES: usize = ${cache.maximumSchemaBytes / 1024} * 1024;`);
495 expect(session).toContain(`TOOL_ACTIVATION_CACHE_CEILING_FACTOR: usize = ${cache.pinnedCeilingMultiplier};`);
496 expect(toolDoc).toContain(`${cache.maximumNames} names and ${cache.maximumSchemaBytes / 1024} KiB`);
497 expect(toolsPage).toContain("read_file, write_file and edit_file");
498 expect(toolsPage).toContain("Web search/fetch");
499 expect(toolsPage).not.toContain("docs/TOOL_LIFECYCLE.md");
500 });
501
502 it("states the hosted-provider privacy boundary without a false local-only promise", () => {
503 const faq = text("web/lib/content/faq.tsx");
504 const providers = text("docs/PROVIDERS.md");
505 const runtime = text("docs/RUNTIME_API.md");
506
507 expect(matrix.trust.hostedProviderBoundary).toContain("selected hosted provider");
508 expect(matrix.trust.localInference).toContain("loopback local-model route");
509 // The source candidate counts by default and says so. Disclosure alone
510 // is never acceptance, every opt-out stays authoritative, and the
511 // published release's earlier opt-in behavior is named, not blurred.
512 expect(matrix.trust.telemetry).toContain(`Codewhale ${matrix.sourceCandidate.version} counts anonymous usage by default`);
513 expect(matrix.trust.telemetry).toContain("discloses it at first launch");
514 expect(matrix.trust.telemetry).toContain("policy notice version 6");
515 expect(matrix.trust.telemetry).toContain("Codewhale as the sole first-party collector");
516 expect(matrix.trust.telemetry).not.toMatch(/PostHog/i);
517 expect(matrix.trust.telemetry).toContain("earlier 0.9.11 release asked first");
518 expect(matrix.trust.telemetry).toContain("never records any acceptance");
519 expect(matrix.trust.telemetry).toContain("opt-out recorded under the earlier opt-in policy stays off");
520 expect(matrix.trust.telemetry).not.toContain("requires explicit consent");
521 expect(matrix.trust.telemetry).toContain("does not collect conversations");
522 expect(matrix.trust.telemetry).toContain("per-turn/per-tool timelines");
523 // The destination is now named, and named exactly — a trust claim that says
524 // "an endpoint" without saying which one is not a trust claim.
525 expect(matrix.trust.telemetry).toContain(
526 "https://telemetry.codewhale.net/v1/telemetry",
527 );
528 expect(matrix.trust.telemetry).toContain("no IP, country, or geo column");
529 expect(matrix.trust.telemetry).toContain("three-month retention");
530 // The local dry-run path stays documented, because it is what lets a user
531 // audit the schema against their own traffic.
532 expect(matrix.trust.telemetry).toContain("local dry-run file");
533 expect(matrix.trust.telemetry).toContain("no mandatory hosted relay");
534 expect(faq).toContain("The hosted");
535 expect(faq).toContain("provider you select receives the prompt");
536 expect(faq).toContain("keep model inference local");
537 expect(faq).toContain("你选择的托管 provider 会收到");
538 expect(faq).not.toContain("No telemetry, no cloud processing of your code");
539 expect(faq).not.toContain("不会将你的代码上传到云端处理");
540 expect(providers).toMatch(/Hosted\s+routes/);
541 expect(runtime).toContain("No hosted relay");
542 });
543
544 it("backs product vocabulary, contributor credit, and the exact MIT footer", () => {
545 const fleet = text("docs/FLEET.md");
546 const changelog = text("CHANGELOG.md");
547 const contributors = text("docs/CONTRIBUTORS.md");
548 const releaseCredits = text("web/lib/release-credits.ts");
549 const footer = text("web/components/footer.tsx");
550
551 expect(matrix.product.terminology).toEqual({
552 Fleet: "the user's model inventory: who is in the roster and which member is selected",
553 Workflow: "what order the work follows",
554 Lane: "one running Workflow instance",
555 Runtime: "where, how, and with what authority selected work executes",
556 });
557 for (const [term, definition] of Object.entries(matrix.product.terminology)) {
558 expect(fleet).toContain(`**${term}** = ${definition}`);
559 }
560 expect(matrix.repository.requiredCandidateCredits).not.toHaveLength(0);
561 expect(matrix.repository.mirrors.some((mirror) => mirror.includes("gitee"))).toBe(false);
562 for (const handle of matrix.repository.requiredCandidateCredits) {
563 expect(changelog).toContain(handle);
564 expect(contributors).toContain(`github.com/${handle.slice(1)}`);
565 expect(releaseCredits).toContain(`"${handle}"`);
566 }
567 // The footer link sets are generated from the locale dictionaries
568 // (lib/i18n/links.ts) rather than hardcoded per-locale arrays, so the
569 // exact MIT pairing is asserted on the rendered contract for both the
570 // English and Chinese editions — same guarantee, one source.
571 expect(footerProjectLinks("en", getChrome("en")).at(-1)).toEqual({
572 label: "MIT license",
573 href: "https://github.com/codewhale-hq/CodeWhale/blob/main/LICENSE",
574 });
575 expect(footerProjectLinks("zh", getChrome("zh")).at(-1)).toEqual({
576 label: "MIT 许可证",
577 href: "https://github.com/codewhale-hq/CodeWhale/blob/main/LICENSE",
578 });
579 expect(text("web/lib/i18n/links.ts")).toContain(
580 'export const REPO_RELEASES_URL = `${REPO_URL}/releases`',
581 );
582 expect(text("web/lib/i18n/links.ts")).toContain(
583 'export const REPO_URL = "https://github.com/codewhale-hq/CodeWhale"',
584 );
585 // Mirrors are listed on /install#mirrors, not in the footer.
586 expect(footer).not.toMatch(/gitee|cnb\.cool|npmmirror/i);
587 });
588
589 it("keeps supplied terminal screenshots and website dimensions truthful", () => {
590 // The README image is a frame of the real released-capture set; its build
591 // and model are recorded in the fact matrix and the capture provenance.
592 const readmeImage = bytes(matrix.screenshot.readme);
593 const websiteImage = bytes(matrix.screenshot.website);
594
595 expect(imageDimensions(websiteImage)).toEqual([TERMINAL_SCREENSHOT.width, TERMINAL_SCREENSHOT.height]);
596 expect(readmeImage).toEqual(websiteImage);
597 expect(statSync(new URL(matrix.screenshot.readme, root)).size).toBeLessThan(500_000);
598 expect(matrix.screenshot.terminal).toContain("real PTY capture");
599 expect(matrix.screenshot.capture).toMatch(/published.*release|development build/);
600 expect(matrix.screenshot.model).toBe(TERMINAL_SCREENSHOT.model);
601 expect(matrix.screenshot.sourceCommit).toBe(TERMINAL_SCREENSHOT.sourceCommit);
602 const provenance = JSON.parse(text("web/lib/terminal-captures/released/provenance.json"));
603 expect(provenance.model.scripted).toBe(false);
604 expect(provenance.model.model).toBe(TERMINAL_SCREENSHOT.model);
605
606 const readme = text("README.md");
607 const homePage = text("web/app/[locale]/page.tsx");
608 const guidePage = text("web/app/[locale]/docs/guide/page.tsx");
609 expect(readme).toContain(matrix.screenshot.readme);
610 expect(`web/public${TERMINAL_SCREENSHOT.src}`).toBe(matrix.screenshot.website);
611 expect(homePage).toContain("RELEASED_CAPTURE_FRAMES");
612 expect(guidePage).toContain("RELEASED_CAPTURE_FRAMES");
613 });
614
615 it("keeps the homepage free of fabricated demo panels", () => {
616 const homepage = text("web/app/[locale]/page.tsx");
617
618 expect(homepage).not.toContain("TerminalPlayer");
619 expect(homepage).not.toContain("paper-decides");
620 expect(homepage).not.toContain("product-receipt");
621 });
622
623 it("keeps every fact-matrix source resolvable in the repository", () => {
624 const sources = new Set<string>();
625 const visit = (value: unknown) => {
626 if (Array.isArray(value)) {
627 value.forEach(visit);
628 } else if (value && typeof value === "object") {
629 for (const [key, child] of Object.entries(value)) {
630 if (key === "sources" || key === "creditSources") {
631 (child as string[]).forEach((source) => sources.add(source));
632 } else {
633 visit(child);
634 }
635 }
636 }
637 };
638 visit(matrix);
639
640 for (const source of sources) {
641 expect(existsSync(new URL(source, root)), source).toBe(true);
642 }
643 });
644 });
645
645 lines TYPESCRIPT