| 1 | |
| 2 | |
| 3 | import assert from 'node:assert/strict'; |
| 4 | import fs from 'node:fs'; |
| 5 | import path from 'node:path'; |
| 6 | import { fileURLToPath } from 'node:url'; |
| 7 | const root = fileURLToPath(new URL('../../', import.meta.url)); |
| 8 | const readme = fs.readFileSync(path.join(root,'README.md'),'utf8'); |
| 9 | const menu = readme.split('\n').find(line => line.includes('(README.md)') && line.includes('(README.')); |
| 10 | assert.ok(menu, 'README language navigation is missing'); |
| 11 | const codes = [...menu.matchAll(/\]\(README(?:\.([\w-]+))?\.md\)/g)].map(m => m[1] || 'zh'); |
| 12 | |
| 13 | assert.equal(codes[0], 'zh'); |
| 14 | assert.ok(!codes.includes('en')); |
| 15 | const dist = path.join(root,'www/dist'); |
| 16 | const published = JSON.parse(fs.readFileSync(path.join(root, 'www/src/data/release.json'), 'utf8')); |
| 17 | for (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 | } |
| 56 | assert.ok(!fs.existsSync(path.join(dist,'en/index.html')), 'Old English page still present'); |
| 57 | console.log(`Verified ${codes.length} README languages, dropdowns, directions and local assets.`); |
| 58 | |
| 59 | |
| 60 | const guideDir = path.join(dist, 'docs'); |
| 61 | const guideFiles = fs.readdirSync(guideDir, { recursive: true }).filter(file => file.endsWith('index.html')); |
| 62 | assert.ok(guideFiles.length >= 12, 'User guide chapters are missing'); |
| 63 | const guideSourceFiles = fs.readdirSync(path.join(root, 'docs/guide')).filter(file => file.endsWith('.md')); |
| 64 | assert.equal(guideFiles.length, guideSourceFiles.length, 'Guide source and routes have drifted'); |
| 65 | for (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('&', '&'); |
| 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 | } |
| 89 | for (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 | } |
| 93 | console.log(`Verified ${guideFiles.length} user guide pages, local links, anchors, search and homepage entries.`); |
| 94 | |
| 95 | const agentGuide = fs.readFileSync(path.join(dist, 'agent.md'), 'utf8'); |
| 96 | assert.equal(agentGuide, fs.readFileSync(path.join(dist, 'llms-full.txt'), 'utf8'), 'Agent text copies must share the same source'); |
| 97 | assert.ok(agentGuide.includes('agent capabilities') && agentGuide.includes('job_not_found'), 'Agent guide lacks discovery or recovery contract'); |
| 98 | assert.ok(!agentGuide.includes('title: 让 Agent'), 'Agent Markdown must omit frontmatter'); |
| 99 | for (const name of ['llms.txt', 'agent-bootstrap.mjs', 'cage-install.sh']) assert.ok(fs.existsSync(path.join(dist, name)), `Missing Agent entry ${name}`); |
| 100 | assert.ok(fs.readFileSync(path.join(dist, 'docs/agent/index.html'), 'utf8').includes('JSON 结果和异步任务'), 'Rendered Agent guide missing'); |
| 101 | console.log('Verified Agent Markdown, discovery, download helper and rendered guide.'); |
| 102 | |
| 103 | const screenshotManifest = JSON.parse(fs.readFileSync(path.join(root, 'www/public/docs/screenshots/manifest.json'), 'utf8')); |
| 104 | for (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 | } |
| 112 | console.log(`Verified ${screenshotManifest.length} screenshots, original dimensions and version captions.`); |