跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

check-site.mjs

112 行 · 8.9 KB历史下载
1// Check emitted pages, not just the locale configuration: catch missing routes,
2// broken project subpaths and languages drifting away from the README menu.
3import assert from 'node:assert/strict';
4import fs from 'node:fs';
5import path from 'node:path';
6import { fileURLToPath } from 'node:url';
7const root = fileURLToPath(new URL('../../', import.meta.url));
8const readme = fs.readFileSync(path.join(root,'README.md'),'utf8');
9const menu = readme.split('\n').find(line => line.includes('(README.md)') && line.includes('(README.'));
10assert.ok(menu, 'README language navigation is missing');
11const codes = [...menu.matchAll(/\]\(README(?:\.([\w-]+))?\.md\)/g)].map(m => m[1] || 'zh');
12// README.md has no dot before the base name's extension in the optional group.
13assert.equal(codes[0], 'zh');
14assert.ok(!codes.includes('en'));
15const dist = path.join(root,'www/dist');
16const published = JSON.parse(fs.readFileSync(path.join(root, 'www/src/data/release.json'), 'utf8'));
17for (const code of codes) {
18 const html = fs.readFileSync(path.join(dist,code === 'zh' ? '' : code,'index.html'),'utf8');
19 const picker = html.match(/<details\b[^>]*id="site-language"[^>]*>([\s\S]*?)<\/details>/)?.[1];
20 assert.ok(picker, `${code}: missing language picker`);
21 const options = [...picker.matchAll(/<a\b[^>]*href="([^"]+)"/g)].map(m=>m[1]);
22 assert.equal(options.length,codes.length, `${code}: language dropdown missing options`);
23 assert.deepEqual(options, codes.map(locale => `/Claude-Cage/${locale === 'zh' ? '' : locale + '/'}`), `${code}: incorrect language destinations`);
24 assert.equal([...picker.matchAll(/aria-current="page"/g)].length, 1, `${code}: current language must be marked once`);
25 assert.ok(!html.includes('<select'), `${code}: system popup selector remains`);
26 assert.ok(!options.some(url=>url.endsWith('/en/')), `${code}: unexpected English route`);
27 assert.ok(html.includes('id="site-language"'), `${code}: missing language selector`);
28 assert.ok(html.includes(`dir="${['ar','fa','ps','prs'].includes(code)?'rtl':'ltr'}"`), `${code}: incorrect reading direction`);
29 for (const match of html.matchAll(/(?:src|href)="(\/Claude-Cage\/[^"#]+)"/g)) {
30 const relative = decodeURIComponent(match[1].slice('/Claude-Cage/'.length));
31 const target = path.join(dist,relative.endsWith('/') ? relative+'index.html' : relative);
32 assert.ok(fs.existsSync(target), `${code}: broken local asset or link ${match[1]}`);
33 }
34 assert.ok(!html.includes('/Users/'), `${code}: local developer path leaked`);
35 assert.ok(html.includes(`href="${published.downloadURL}"`), `${code}: macOS download is missing`);
36 const downloadSection = html.match(/<section\b[^>]*id="download"[^>]*>([\s\S]*?)<\/section>/)?.[1];
37 assert.ok(downloadSection?.includes(`CLAUDE CAGE · v${published.version}`), `${code}: download release label must follow published metadata`);
38 assert.ok(!downloadSection?.includes('CLAUDE CAGE · ALPHA'), `${code}: stale release channel label`);
39 assert.equal([...html.matchAll(/<a\b[^>]*\bdata-download-open(?:\s|>)/g)].length, 3, `${code}: all download entries must open the platform chooser`);
40 assert.ok(html.includes('aria-labelledby="platform-title"'), `${code}: platform dialog has no accessible title`);
41 for (const platform of ['macOS', 'Windows', 'Linux', 'Android', 'iOS']) {
42 assert.ok(html.includes(`data-platform="${platform}"`), `${code}: missing ${platform} choice`);
43 }
44 const windowsLinks = [...html.matchAll(/href="([^"]*windows-amd64-setup\.exe)"/g)].map(match => match[1]);
45 assert.deepEqual(windowsLinks, published.windowsDownloadURL ? [published.windowsDownloadURL, published.windowsDownloadURL] : [], `${code}: Windows download must match the verified optional release metadata`);
46 for (const [suffix, url] of [['linux-amd64.deb', published.linuxDownloadURL], ['android-arm64.apk', published.androidDownloadURL], ['windows-amd64-setup-unsigned.exe', published.windowsDownloadURL ? undefined : published.windowsPreview?.downloadURL]]) {
47 const links = [...html.matchAll(/href="([^"]+)"/g)].map(match => match[1]).filter(link => link.endsWith(suffix));
48 assert.deepEqual(links, url ? [url, url] : [], `${code}: ${suffix} must match verified metadata`);
49 }
50 const ios = html.match(/<article\b[^>]*data-platform="iOS"[^>]*>([\s\S]*?)<\/article>/)?.[1];
51 assert.ok(ios?.includes('href="/Claude-Cage/docs/mobile/"'), `${code}: iOS needs its local build guide`);
52 assert.ok(ios?.includes('/Claude-Cage/platforms/apple.svg'), `${code}: iOS platform icon is missing`);
53 const android = html.match(/<article\b[^>]*data-platform="Android"[^>]*>([\s\S]*?)<\/article>/)?.[1];
54 assert.ok(android?.includes('/Claude-Cage/platforms/android.svg'), `${code}: Android platform icon is missing`);
55}
56assert.ok(!fs.existsSync(path.join(dist,'en/index.html')), 'Old English page still present');
57console.log(`Verified ${codes.length} README languages, dropdowns, directions and local assets.`);
58
59// Check actual guide pages and every cross-page anchor, including project bases.
60const guideDir = path.join(dist, 'docs');
61const guideFiles = fs.readdirSync(guideDir, { recursive: true }).filter(file => file.endsWith('index.html'));
62assert.ok(guideFiles.length >= 12, 'User guide chapters are missing');
63const guideSourceFiles = fs.readdirSync(path.join(root, 'docs/guide')).filter(file => file.endsWith('.md'));
64assert.equal(guideFiles.length, guideSourceFiles.length, 'Guide source and routes have drifted');
65for (const relative of guideFiles) {
66 const filename = path.join(guideDir, relative);
67 const html = fs.readFileSync(filename, 'utf8');
68 assert.ok(html.includes('id="guide-search"'), `${relative}: missing search`);
69 assert.ok(html.includes('id="guide-article"'), `${relative}: missing article`);
70 assert.ok(html.includes('aria-label="前后章节"'), `${relative}: missing chapter navigation`);
71 assert.ok(!html.includes('/Users/'), `${relative}: local developer path leaked`);
72 assert.ok(!html.includes('<select'), `${relative}: system popup selector remains`);
73 assert.equal([...html.matchAll(/<h1\b/g)].length, 1, `${relative}: expected one page title`);
74 const current = `/Claude-Cage/docs/${relative.replace(/index\.html$/, '').replaceAll(path.sep, '/')}`;
75 for (const match of html.matchAll(/href="([^\"]+)"/g)) {
76 const href = match[1].replaceAll('&amp;', '&');
77 if (!href.startsWith('/Claude-Cage/') && !href.startsWith('#')) continue;
78 const url = new URL(href, `https://example.test${current}`);
79 const local = decodeURIComponent(url.pathname.slice('/Claude-Cage/'.length));
80 const target = path.join(dist, !local || local.endsWith('/') ? local + 'index.html' : local);
81 assert.ok(fs.existsSync(target), `${relative}: broken guide link ${href}`);
82 if (url.hash) {
83 const targetHTML = fs.readFileSync(target, 'utf8');
84 const id = decodeURIComponent(url.hash.slice(1));
85 assert.ok(targetHTML.includes(`id="${id}"`), `${relative}: missing anchor ${href}`);
86 }
87 }
88}
89for (const code of codes) {
90 const html = fs.readFileSync(path.join(dist, code === 'zh' ? '' : code, 'index.html'), 'utf8');
91 assert.ok(html.includes('href="/Claude-Cage/docs/"'), `${code}: homepage needs a guide entry`);
92}
93console.log(`Verified ${guideFiles.length} user guide pages, local links, anchors, search and homepage entries.`);
94
95const agentGuide = fs.readFileSync(path.join(dist, 'agent.md'), 'utf8');
96assert.equal(agentGuide, fs.readFileSync(path.join(dist, 'llms-full.txt'), 'utf8'), 'Agent text copies must share the same source');
97assert.ok(agentGuide.includes('agent capabilities') && agentGuide.includes('job_not_found'), 'Agent guide lacks discovery or recovery contract');
98assert.ok(!agentGuide.includes('title: 让 Agent'), 'Agent Markdown must omit frontmatter');
99for (const name of ['llms.txt', 'agent-bootstrap.mjs', 'cage-install.sh']) assert.ok(fs.existsSync(path.join(dist, name)), `Missing Agent entry ${name}`);
100assert.ok(fs.readFileSync(path.join(dist, 'docs/agent/index.html'), 'utf8').includes('JSON 结果和异步任务'), 'Rendered Agent guide missing');
101console.log('Verified Agent Markdown, discovery, download helper and rendered guide.');
102
103const screenshotManifest = JSON.parse(fs.readFileSync(path.join(root, 'www/public/docs/screenshots/manifest.json'), 'utf8'));
104for (const shot of screenshotManifest) {
105 assert.ok(shot.version && shot.platform && shot.capturedAt && shot.source, `${shot.id}: screenshot provenance missing`);
106 assert.ok(fs.existsSync(path.join(dist, 'docs/screenshots', shot.file)), `${shot.id}: screenshot was not shipped`);
107 const article = fs.readFileSync(path.join(guideDir, shot.chapter, 'index.html'), 'utf8');
108 assert.ok(article.includes(`src="/Claude-Cage/docs/screenshots/${shot.file}"`), `${shot.id}: broken screenshot URL`);
109 assert.ok(article.includes(shot.version), `${shot.id}: version caption missing`);
110 assert.ok(article.includes(`width="${shot.width}" height="${shot.height}"`), `${shot.id}: original dimensions missing`);
111}
112console.log(`Verified ${screenshotManifest.length} screenshots, original dimensions and version captions.`);