Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix(website): publish standalone case discovery metadata
tt-a1ifaf4baa4a4c4
diff --git a/website/scripts/indexnow.mjs b/website/scripts/indexnow.mjsindex ab4c57e7..0b1f40de 100644--- a/website/scripts/indexnow.mjs+++ b/website/scripts/indexnow.mjs@@ -2,6 +2,7 @@ import fs from 'node:fs';import { pathToFileURL } from 'node:url';import { canonicalOrigin, canonicalUrl, sitePages } from '../src/data/site-urls.mjs';import { CASES } from '../src/data/gallery-presentation.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';export const key = '0e4ac4a253b420619eb3de08ba664736';export const keyLocation = `${canonicalOrigin}/${key}.txt`;@@ -10,6 +11,7 @@ export const endpoint = 'https://api.indexnow.org/indexnow';const allowedUrls = new Set([...sitePages.flatMap(page => ['en', 'zh'].map(lang => canonicalUrl(page, lang))),...CASES.map(entry => `${canonicalOrigin}/gallery/artifacts/${entry.output.replace(/\.html$/, '')}`),+ ...PUBLISHED_CASES.map(entry => `${canonicalOrigin}/${entry.artifact.replace(/\.html$/, '')}`),]);const requireValue = (ok, message) => { if (!ok) throw new Error(message); };@@ -33,7 +35,7 @@ export function parseSitemap(xml) {entries.push(value);body = body.slice(item[0].length);}- requireValue(entries.length === allowedUrls.size, 'Sitemap must contain all main pages and selected gallery artifacts');+ requireValue(entries.length === allowedUrls.size, 'Sitemap must contain all main pages, selected gallery artifacts and published cases');return entries;}diff --git a/website/scripts/publish-seo.mjs b/website/scripts/publish-seo.mjsindex ffd57193..ee1c14fd 100644--- a/website/scripts/publish-seo.mjs+++ b/website/scripts/publish-seo.mjs@@ -4,6 +4,7 @@ import path from 'node:path';import { createHash } from 'node:crypto';import { canonicalOrigin, canonicalUrl, canonicalPath, sitePages } from '../src/data/site-urls.mjs';import { CASES } from '../src/data/gallery-presentation.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';export const CANONICAL_ORIGIN = canonicalOrigin;export const SEO_BLOCK_START = '<!-- archify:published-artifact-metadata:start -->';@@ -17,15 +18,24 @@ export function stripPublishedArtifactMetadata(html) {return html.replace(/<!-- archify:published-artifact-metadata:start -->\n[\s\S]*?<!-- archify:published-artifact-metadata:end -->\n/g, '');}-export function artifactMetadata(entry, presentation) {+function publicationMetadata(entry, { title, description, language, twitter = false }) {const url = `${CANONICAL_ORIGIN}/${entry.artifact.replace(/\.html$/, '')}`;const source = `${CANONICAL_ORIGIN}/${entry.input}`;const data = {'@context': 'https://schema.org', '@type': 'CreativeWork',- name: presentation.titleEn, description: presentation.descriptionEn,- url, isBasedOn: source, inLanguage: 'en',+ name: title, description,+ url, isBasedOn: source, inLanguage: language,};- return `${SEO_BLOCK_START}\n<link rel="canonical" href="${escape(url)}">\n<meta name="description" content="${escape(presentation.descriptionEn)}">\n<meta property="og:type" content="article">\n<meta property="og:title" content="${escape(presentation.titleEn)}">\n<meta property="og:description" content="${escape(presentation.descriptionEn)}">\n<meta property="og:url" content="${escape(url)}">\n<script type="application/ld+json">${JSON.stringify(data).replaceAll('<', '\\u003c')}</script>\n${SEO_BLOCK_END}\n`;+ const twitterMetadata = twitter ? `<meta name="twitter:card" content="summary">\n<meta name="twitter:title" content="${escape(title)}">\n<meta name="twitter:description" content="${escape(description)}">\n` : '';+ return `${SEO_BLOCK_START}\n<link rel="canonical" href="${escape(url)}">\n<meta name="description" content="${escape(description)}">\n<meta property="og:type" content="article">\n<meta property="og:title" content="${escape(title)}">\n<meta property="og:description" content="${escape(description)}">\n<meta property="og:url" content="${escape(url)}">\n${twitterMetadata}<script type="application/ld+json">${JSON.stringify(data).replaceAll('<', '\\u003c')}</script>\n${SEO_BLOCK_END}\n`;+}++export function artifactMetadata(entry, presentation) {+ return publicationMetadata(entry, { title: presentation.titleEn, description: presentation.descriptionEn, language: 'en' });+}++export function caseMetadata(entry) {+ return publicationMetadata(entry, { ...entry, twitter: true });}// Only gallery entries with passing artifact checks and unchanged proof hashes@@ -52,15 +62,29 @@ export function publishSeo(root, target) {assert.ok(fs.existsSync(path.join(root, file)), `Missing indexable page: ${file}`);}const selected = selectedArtifacts(root);- for (const { entry, presentation } of selected) {+ // Check the explicit case inventory before writing any publication metadata.+ // These are existing authored examples, not new generation or proof receipts.+ for (const entry of PUBLISHED_CASES) {+ for (const file of [entry.artifact, entry.input]) {+ assert.ok(fs.existsSync(path.join(root, file)), `Missing published case: ${file}`);+ }+ }+ const publications = [+ ...selected.map(({ entry, presentation }) => ({ entry, metadata: artifactMetadata(entry, presentation) })),+ ...PUBLISHED_CASES.map(entry => ({ entry, metadata: caseMetadata(entry) })),+ ];+ for (const { entry, metadata } of publications) {const file = path.join(root, entry.artifact);const original = stripPublishedArtifactMetadata(fs.readFileSync(file, 'utf8'));- assert.match(original, /<\/head>/i, `Artifact missing head: ${entry.id}`);- fs.writeFileSync(file, original.replace(/<\/head>/i, `${artifactMetadata(entry, presentation)}</head>`));+ assert.match(original, /<\/head>/i, `Artifact missing head: ${entry.artifact}`);+ // Callback insertion keeps authored $ replacement tokens literal (#826),+ // and retains the original closing tag bytes, including its letter case.+ fs.writeFileSync(file, original.replace(/<\/head>/i, closingTag => `${metadata}${closingTag}`));}const urls = [...sitePages.flatMap(page => ['en', 'zh'].map(lang => canonicalUrl(page, lang))),...selected.map(({ entry }) => `${CANONICAL_ORIGIN}/${entry.artifact.replace(/\.html$/, '')}`),+ ...PUBLISHED_CASES.map(entry => `${CANONICAL_ORIGIN}/${entry.artifact.replace(/\.html$/, '')}`),];fs.writeFileSync(path.join(root, 'sitemap.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.map(url => ` <url><loc>${escape(url)}</loc></url>`).join('\n')}\n</urlset>\n`);fs.writeFileSync(path.join(root, 'robots.txt'), `User-agent: *\nAllow: /\n\nSitemap: ${CANONICAL_ORIGIN}/sitemap.xml\n`);diff --git a/website/src/data/published-cases.mjs b/website/src/data/published-cases.mjsnew file mode 100644index 00000000..d1c989bf--- /dev/null+++ b/website/src/data/published-cases.mjs@@ -0,0 +1,39 @@+// Website discovery copy for existing standalone cases. This inventory does not+// regenerate diagrams or assert renderer validation; source artifacts own that.+export const PUBLISHED_CASES = [+ {+ artifact: 'cases/life/leave-plan.workflow.html',+ input: 'cases/life/leave-plan.workflow.json',+ title: '一年的年假怎么排',+ description: '查看一份中文年假安排流程图:休假节点、剩余额度和规则提醒相互对应。此为示例计划,不代表真实日历或公司的休假政策。',+ language: 'zh-CN',+ },+ {+ artifact: 'cases/life/job-search.lifecycle.html',+ input: 'cases/life/job-search.lifecycle.json',+ title: 'Where Each Job Application Stands',+ description: 'Explore an example job-application lifecycle, from saved roles and submitted applications through interviews, waiting states, and final outcomes.',+ language: 'en',+ },+ {+ artifact: 'cases/life/monthly-money.dataflow.html',+ input: 'cases/life/monthly-money.dataflow.json',+ title: 'Where a Paycheck Goes Each Month',+ description: 'Follow an example monthly paycheck through checking, bills, emergency savings and retirement transfers in an interactive data-flow diagram. Amounts are illustrative.',+ language: 'en',+ },+ {+ artifact: 'cases/life/renting.sequence.html',+ input: 'cases/life/renting.sequence.json',+ title: '租一套房,一来一回都在这里',+ description: '用中文时序图查看租客、中介和房东之间的看房、议价、签约、付款与交接步骤。金额和流程仅为示例。',+ language: 'zh-CN',+ },+ {+ artifact: 'cases/mco-runtime.architecture.html',+ input: 'cases/mco-runtime.architecture.json',+ title: 'MCO Runtime Architecture',+ description: 'Explore the MCO runtime architecture at pinned revision 9f1a1cf: entry points, provider invocation, streamed answers and artifacts. This is an authored source-backed diagram, not an execution trace.',+ language: 'en',+ },+];diff --git a/website/test/agent-diagrams.test.mjs b/website/test/agent-diagrams.test.mjsindex a9486d33..2a9d4780 100644--- a/website/test/agent-diagrams.test.mjs+++ b/website/test/agent-diagrams.test.mjs@@ -1,6 +1,7 @@import { test } from 'node:test';import assert from 'node:assert/strict';import fs from 'node:fs';+import { stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';import { parse } from 'parse5';import { parseSitemap } from '../scripts/indexnow.mjs';@@ -109,6 +110,8 @@ test('description workflow exposes pinned evidence, honest limits and localized}for (const extension of ['json', 'html']) {const file = `cases/life/leave-plan.workflow.${extension}`;- assert.deepEqual(fs.readFileSync(new URL(file, output)), fs.readFileSync(new URL(`../../docs/${file}`, import.meta.url)), 'existing artifact bytes remain unchanged');+ const published = fs.readFileSync(new URL(file, output));+ const original = extension === 'html' ? Buffer.from(stripPublishedArtifactMetadata(published.toString('utf8'))) : published;+ assert.deepEqual(original, fs.readFileSync(new URL(`../../docs/${file}`, import.meta.url)), 'existing artifact bytes remain unchanged outside the publication metadata block');}});diff --git a/website/test/deployment-target.test.mjs b/website/test/deployment-target.test.mjsindex 6274c0d3..bdd1b242 100644--- a/website/test/deployment-target.test.mjs+++ b/website/test/deployment-target.test.mjs@@ -3,8 +3,9 @@ import { test } from 'node:test';import assert from 'node:assert/strict';import fs from 'node:fs';import { parse, parseFragment } from 'parse5';-import { SEO_BLOCK_START, SEO_BLOCK_END, stripPublishedArtifactMetadata, artifactMetadata } from '../scripts/publish-seo.mjs';+import { SEO_BLOCK_START, SEO_BLOCK_END, stripPublishedArtifactMetadata, artifactMetadata, caseMetadata } from '../scripts/publish-seo.mjs';import { CASES } from '../src/data/gallery-presentation.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';const cloudflare = process.env.ARCHIFY_SITE_TARGET === 'cloudflare';const output = new URL(cloudflare ? '../dist-cloudflare/' : '../dist/', import.meta.url);@@ -12,6 +13,22 @@ const nodes = node => [node, ...(node.childNodes || []).flatMap(nodes)];const attr = (node, name) => node?.attrs?.find(item => item.name === name)?.value;const pages = sitePages;+test('deployment publishes only the declared case metadata while retaining every original artifact and source byte', () => {+ for (const entry of PUBLISHED_CASES) {+ const html = fs.readFileSync(new URL(entry.artifact, output), 'utf8');+ assert.equal(html.split(SEO_BLOCK_START).length, 2);+ assert.equal(html.split(SEO_BLOCK_END).length, 2);+ const start = html.indexOf(SEO_BLOCK_START), end = html.indexOf(SEO_BLOCK_END) + SEO_BLOCK_END.length;+ assert.ok(start > html.indexOf('<head>') && end < html.indexOf('</head>'));+ assert.equal(html.slice(start, end) + '\n', caseMetadata(entry), entry.artifact);+ const all = nodes(parse(html));+ assert.equal(all.filter(node => attr(node, 'rel') === 'canonical').length, 1);+ assert.equal(attr(all.find(node => node.tagName === 'html'), 'lang'), entry.language);+ assert.deepEqual(Buffer.from(stripPublishedArtifactMetadata(html)), fs.readFileSync(new URL(`../../docs/${entry.artifact}`, import.meta.url)));+ assert.deepEqual(fs.readFileSync(new URL(entry.input, output)), fs.readFileSync(new URL(`../../docs/${entry.input}`, import.meta.url)));+ }+});+test('built deployment uses host-compatible generated assets and canonical metadata in both languages', () => {for (const lang of ['en', 'zh']) for (const page of pages) {const file = page === 'index' ? `${lang === 'zh' ? 'zh' : 'index'}.html` : `${lang === 'zh' ? 'zh/' : ''}${page}.html`;diff --git a/website/test/helpers/community-fixture.mjs b/website/test/helpers/community-fixture.mjsindex 212c094f..937de4f6 100644--- a/website/test/helpers/community-fixture.mjs+++ b/website/test/helpers/community-fixture.mjs@@ -3,6 +3,7 @@ import fs from 'node:fs';import os from 'node:os';import path from 'node:path';import { fileURLToPath } from 'node:url';+import { PUBLISHED_CASES } from '../../src/data/published-cases.mjs';export const websiteRoot = fileURLToPath(new URL('../../', import.meta.url));const repoRoot = path.resolve(websiteRoot, '..');@@ -26,7 +27,7 @@ export function createCommunityFixture() {'website/src/', 'website/public/', 'website/astro.config.mjs', 'website/scripts/', 'website/package.json','archify/package.json', 'archify/skill-release.json', 'archify/recipes/','scripts/site-copy.mjs', 'scripts/check-community-packages.mjs',- 'docs/gallery/', 'docs/assets/', 'docs/cases/life/'], { cwd: repoRoot, encoding: 'utf8' })+ 'docs/gallery/', 'docs/assets/', ...PUBLISHED_CASES.flatMap(entry => [`docs/${entry.artifact}`, `docs/${entry.input}`])], { cwd: repoRoot, encoding: 'utf8' }).split('\0').filter(Boolean);for (const relative of tracked) copy(relative);fs.symlinkSync(path.join(websiteRoot, 'node_modules'), path.join(root, 'website/node_modules'), process.platform === 'win32' ? 'junction' : 'dir');diff --git a/website/test/indexnow.test.mjs b/website/test/indexnow.test.mjsindex da9b8409..59764863 100644--- a/website/test/indexnow.test.mjs+++ b/website/test/indexnow.test.mjs@@ -3,9 +3,10 @@ import assert from 'node:assert/strict';import fs from 'node:fs';import { canonicalUrl, sitePages, canonicalOrigin } from '../src/data/site-urls.mjs';import { CASES } from '../src/data/gallery-presentation.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';import { notifyIndexNow, parseSitemap, endpoint, key, keyLocation, sitemapLocation } from '../scripts/indexnow.mjs';-const urls = [...sitePages.flatMap(page => ['en', 'zh'].map(lang => canonicalUrl(page, lang))), ...CASES.map(entry => `${canonicalOrigin}/gallery/artifacts/${entry.output.replace(/\.html$/, '')}`)];+const urls = [...sitePages.flatMap(page => ['en', 'zh'].map(lang => canonicalUrl(page, lang))), ...CASES.map(entry => `${canonicalOrigin}/gallery/artifacts/${entry.output.replace(/\.html$/, '')}`), ...PUBLISHED_CASES.map(entry => `${canonicalOrigin}/${entry.artifact.replace(/\.html$/, '')}`)];const xml = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.map(url => `<url><loc>${url}</loc></url>`).join('')}</urlset>`;function mock({ sitemap = xml, hostedKey = key, getStatus = 200, postStatus = 200 } = {}) {const calls = [];@@ -55,7 +56,15 @@ test('public preflight requires HTTP 200 and matching deployed key before POST',test('sitemap XML parser rejects foreign, query, source, duplicate, incomplete and malformed inventories', () => {assert.deepEqual(parseSitemap(xml), urls);+ assert.equal(urls.length, 31);for (const sitemap of [xml.replace('https://archify.si/', 'http://archify.si/'), xml.replace('https://archify.si/', 'https://other.example/'), xml.replace(urls[0], `${urls[0]}?preview=1`), xml.replace(urls[0], `${canonicalOrigin}/gallery/manifest.json`), xml.replace(urls[0], urls[1]), xml.replace(/<url>[\s\S]*?<\/url>/, ''), xml.replace('<loc>', '<wrong>'), '<!DOCTYPE foo>' + xml]) {assert.throws(() => parseSitemap(sitemap));}+ for (const entry of PUBLISHED_CASES) {+ const url = `${canonicalOrigin}/${entry.artifact.replace(/\.html$/, '')}`;+ for (const replacement of [url + '.html', url + '?lang=zh', `${canonicalOrigin}/${entry.input}`, `${canonicalOrigin}/zh/${entry.artifact.replace(/\.html$/, '')}`, `${canonicalOrigin}/cases/unlisted-example`]) {+ assert.throws(() => parseSitemap(xml.replace(url, replacement)), /outside the published|Noncanonical/);+ }+ assert.throws(() => parseSitemap(xml.replace(`<url><loc>${url}</loc></url>`, '')), /must contain all/);+ }});diff --git a/website/test/mco-source-case.test.mjs b/website/test/mco-source-case.test.mjsindex 6926d65f..26a940a6 100644--- a/website/test/mco-source-case.test.mjs+++ b/website/test/mco-source-case.test.mjs@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';import fs from 'node:fs';import { parse } from 'parse5';import { parseSitemap } from '../scripts/indexnow.mjs';+import { stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';const cloudflare = process.env.ARCHIFY_SITE_TARGET === 'cloudflare';const output = new URL(cloudflare ? '../dist-cloudflare/' : '../dist/', import.meta.url);const origin = cloudflare ? 'https://archify.si/' : 'https://tt-a1i.github.io/archify/';@@ -57,8 +58,11 @@ test('MCO case exposes pinned source, honest limits, stable sections and nestedtest('MCO case inventory includes both wrappers and preserves original artifact and typed source bytes', () => {const urls = parseSitemap(fs.readFileSync(new URL('sitemap.xml', output), 'utf8'));for (const prefix of ['', 'zh/']) assert.ok(urls.includes(`https://archify.si/${prefix}cases/mco-runtime`));+ assert.ok(urls.includes('https://archify.si/cases/mco-runtime.architecture'), 'the standalone artifact is distinct from the explanatory article');for (const extension of ['html', 'json']) {const file = `cases/mco-runtime.architecture.${extension}`;- assert.deepEqual(fs.readFileSync(new URL(file, output)), fs.readFileSync(new URL(`../../docs/${file}`, import.meta.url)), file);+ const published = fs.readFileSync(new URL(file, output));+ const original = extension === 'html' ? Buffer.from(stripPublishedArtifactMetadata(published.toString('utf8'))) : published;+ assert.deepEqual(original, fs.readFileSync(new URL(`../../docs/${file}`, import.meta.url)), file);}});diff --git a/website/test/migration.test.mjs b/website/test/migration.test.mjsindex c52a54d8..649dba1f 100644--- a/website/test/migration.test.mjs+++ b/website/test/migration.test.mjs@@ -5,7 +5,8 @@ import path from 'node:path';import { fileURLToPath } from 'node:url';import { parse, parseFragment } from 'parse5';import { CASES } from '../src/data/gallery-presentation.mjs';-import { artifactMetadata, SEO_BLOCK_START, SEO_BLOCK_END, stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';+import { artifactMetadata, caseMetadata, SEO_BLOCK_START, SEO_BLOCK_END, stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';const root = fileURLToPath(new URL('../', import.meta.url));const docs = path.resolve(root, '../docs');@@ -122,8 +123,9 @@ test('all existing non-page public URLs retain exact bytes outside the declaredconst selected = new Map(CASES.map(presentation => {const entry = manifest.entries.find(item => item.id === presentation.id);assert.ok(entry, presentation.id);- return [entry.artifact, { entry, presentation }];+ return [entry.artifact, { entry, metadata: artifactMetadata(entry, presentation), isCase: false }];}));+ for (const entry of PUBLISHED_CASES) selected.set(entry.artifact, { entry, metadata: caseMetadata(entry), isCase: true });function publishedBytes(file) {const bytes = fs.readFileSync(path.join(dist, file));const proof = selected.get(file.replaceAll(path.sep, '/'));@@ -134,9 +136,9 @@ test('all existing non-page public URLs retain exact bytes outside the declaredconst start = html.indexOf(SEO_BLOCK_START), end = html.indexOf(SEO_BLOCK_END) + SEO_BLOCK_END.length;assert.ok(start > html.indexOf('<head>') && end < html.indexOf('</head>'), `${file}: metadata belongs only in head`);const block = html.slice(start, end) + '\n';- assert.equal(block, artifactMetadata(proof.entry, proof.presentation), `${file}: exact publication metadata`);+ assert.equal(block, proof.metadata, `${file}: exact publication metadata`);const metadataNodes = (parseFragment(block).childNodes || []).filter(node => node.tagName);- assert.deepEqual(metadataNodes.map(node => node.tagName), ['link', 'meta', 'meta', 'meta', 'meta', 'meta', 'script']);+ assert.deepEqual(metadataNodes.map(node => node.tagName), ['link', 'meta', 'meta', 'meta', 'meta', 'meta', ...(proof.isCase ? ['meta', 'meta', 'meta'] : []), 'script']);const structured = metadataNodes.at(-1);assert.equal(attr(structured, 'type'), 'application/ld+json', `${file}: no executable script permitted`);assert.equal(structured.attrs.length, 1);diff --git a/website/test/publish-seo.test.mjs b/website/test/publish-seo.test.mjsindex 805a2dd9..ee479049 100644--- a/website/test/publish-seo.test.mjs+++ b/website/test/publish-seo.test.mjs@@ -4,14 +4,17 @@ import fs from 'node:fs';import os from 'node:os';import path from 'node:path';import { fileURLToPath } from 'node:url';+import { parse, parseFragment } from 'parse5';import { CASES } from '../src/data/gallery-presentation.mjs';+import { PUBLISHED_CASES } from '../src/data/published-cases.mjs';import { canonicalPath, canonicalUrl, sitePages } from '../src/data/site-urls.mjs';-import { publishSeo, selectedArtifacts, stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';+import { publishSeo, selectedArtifacts, caseMetadata, SEO_BLOCK_START, SEO_BLOCK_END, stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';const docs = fileURLToPath(new URL('../../docs/', import.meta.url));function fixture() {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-search-'));fs.cpSync(path.join(docs, 'gallery'), path.join(root, 'gallery'), { recursive: true });+ fs.cpSync(path.join(docs, 'cases'), path.join(root, 'cases'), { recursive: true });for (const page of sitePages) for (const lang of ['en', 'zh']) {const route = canonicalPath(page, lang).slice(1);const file = !route || route.endsWith('/') ? `${route}index.html` : `${route}.html`;@@ -25,7 +28,8 @@ for (const name of ['cloudflare', 'github']) test(`${name}: published discoveryconst root = fixture();try {const urls = publishSeo(root, { name });- assert.equal(urls.length, sitePages.length * 2 + CASES.length);+ assert.equal(urls.length, sitePages.length * 2 + CASES.length + PUBLISHED_CASES.length);+ assert.equal(urls.length, 31, '14 localized pages, 12 gallery artifacts and 5 standalone cases');assert.equal(new Set(urls).size, urls.length);for (const page of sitePages) for (const lang of ['en', 'zh']) assert.ok(urls.includes(canonicalUrl(page, lang)));const sitemap = fs.readFileSync(path.join(root, 'sitemap.xml'), 'utf8');@@ -42,15 +46,105 @@ for (const name of ['cloudflare', 'github']) test(`${name}: published discoveryassert.equal(structured.isBasedOn, `https://archify.si/${entry.input}`);assert.deepEqual(fs.readFileSync(path.join(root, entry.input)), fs.readFileSync(path.join(docs, entry.input)));}+ for (const entry of PUBLISHED_CASES) {+ const original = fs.readFileSync(path.join(docs, entry.artifact));+ const published = fs.readFileSync(path.join(root, entry.artifact), 'utf8');+ assert.deepEqual(Buffer.from(stripPublishedArtifactMetadata(published)), original, `${entry.artifact}: exact original bytes outside the metadata block`);+ assert.deepEqual(fs.readFileSync(path.join(root, entry.input)), fs.readFileSync(path.join(docs, entry.input)), `${entry.input}: unchanged source bytes`);+ const source = JSON.parse(fs.readFileSync(path.join(docs, entry.input), 'utf8'));+ assert.equal(entry.title, source.meta.title);+ assert.equal(entry.language, source.meta.locale || 'en');+ assertCaseMetadata(published, entry);+ assert.ok(urls.includes(`https://archify.si/${entry.artifact.replace(/\.html$/, '')}`));+ }+ const casesOnce = PUBLISHED_CASES.map(entry => fs.readFileSync(path.join(root, entry.artifact)));const once = fs.readFileSync(path.join(root, `gallery/artifacts/${CASES[0].output}`), 'utf8');publishSeo(root, { name });assert.equal(fs.readFileSync(path.join(root, `gallery/artifacts/${CASES[0].output}`), 'utf8'), once, 'repeat build is idempotent');+ for (const [index, entry] of PUBLISHED_CASES.entries()) assert.deepEqual(fs.readFileSync(path.join(root, entry.artifact)), casesOnce[index], `${entry.artifact}: repeat publication is idempotent`);assert.equal(fs.readFileSync(path.join(root, 'robots.txt'), 'utf8'), 'User-agent: *\nAllow: /\n\nSitemap: https://archify.si/sitemap.xml\n');assert.equal(fs.existsSync(path.join(root, '_headers')), name === 'cloudflare');if (name === 'cloudflare') assert.equal(fs.readFileSync(path.join(root, '_headers'), 'utf8'), '/*.json\n X-Robots-Tag: noindex\n');} finally { fs.rmSync(root, { recursive: true, force: true }); }});+const nodes = node => [node, ...(node.childNodes || []).flatMap(nodes)];+const attr = (node, name) => node?.attrs?.find(item => item.name === name)?.value;+const text = node => (node.childNodes || []).map(child => child.value || '').join('');++function assertCaseMetadata(html, entry) {+ const all = nodes(parse(html));+ const head = nodes(all.find(node => node.tagName === 'head'));+ const url = `https://archify.si/${entry.artifact.replace(/\.html$/, '')}`;+ const canonical = all.filter(node => node.tagName === 'link' && attr(node, 'rel') === 'canonical');+ assert.equal(canonical.length, 1);+ assert.ok(head.includes(canonical[0]));+ assert.equal(attr(canonical[0], 'href'), url);+ assert.equal(attr(all.find(node => node.tagName === 'html'), 'lang'), entry.language);+ const original = nodes(parse(fs.readFileSync(path.join(docs, entry.artifact), 'utf8')));+ assert.equal(text(head.find(node => node.tagName === 'title')), text(original.find(node => node.tagName === 'title')), 'original document title is preserved');+ assert.equal(html.split(SEO_BLOCK_START).length, 2);+ assert.equal(html.split(SEO_BLOCK_END).length, 2);+ const start = html.indexOf(SEO_BLOCK_START), end = html.indexOf(SEO_BLOCK_END) + SEO_BLOCK_END.length;+ assert.ok(start > html.indexOf('<head>') && end < html.indexOf('</head>'));+ const block = html.slice(start, end) + '\n';+ assert.equal(block, caseMetadata(entry));+ const metadata = nodes(parseFragment(block)).filter(node => node.tagName);+ assert.deepEqual(metadata.map(node => node.tagName), ['link', 'meta', 'meta', 'meta', 'meta', 'meta', 'meta', 'meta', 'meta', 'script']);+ assert.deepEqual(metadata.at(-1).attrs, [{ name: 'type', value: 'application/ld+json' }], 'the only inserted script is non-executable structured data');+ const meta = key => metadata.find(node => attr(node, 'name') === key || attr(node, 'property') === key);+ for (const key of ['description', 'og:description', 'twitter:description']) assert.equal(attr(meta(key), 'content'), entry.description);+ for (const key of ['og:title', 'twitter:title']) assert.equal(attr(meta(key), 'content'), entry.title);+ assert.equal(attr(meta('og:type'), 'content'), 'article');+ assert.equal(attr(meta('og:url'), 'content'), url);+ assert.equal(attr(meta('twitter:card'), 'content'), 'summary');+ assert.deepEqual(JSON.parse(text(metadata.at(-1))), {+ '@context': 'https://schema.org', '@type': 'CreativeWork', name: entry.title, description: entry.description,+ url, isBasedOn: `https://archify.si/${entry.input}`, inLanguage: entry.language,+ });+ assert.doesNotMatch(block, /hreflang|og:image|twitter:image|archify-social-preview/, 'no invented translation or stale preview image');+}++test('case discovery copy keeps the source-backed and illustrative boundaries explicit', () => {+ const byPath = file => PUBLISHED_CASES.find(entry => entry.artifact === file);+ assert.match(byPath('cases/life/leave-plan.workflow.html').description, /示例计划.*不代表真实日历或公司的休假政策/);+ assert.match(byPath('cases/life/renting.sequence.html').description, /金额和流程仅为示例/);+ assert.match(byPath('cases/life/monthly-money.dataflow.html').description, /Amounts are illustrative/);+ const mco = byPath('cases/mco-runtime.architecture.html');+ const source = JSON.parse(fs.readFileSync(path.join(docs, mco.input), 'utf8'));+ assert.ok(mco.description.includes(source.meta.repository.revision.slice(0, 7)));+ assert.match(mco.description, /authored source-backed diagram, not an execution trace/);+});++test('case metadata escapes HTML and JSON while retaining literal replacement tokens', () => {+ const root = fixture();+ const entry = PUBLISHED_CASES[0];+ const original = { title: entry.title, description: entry.description };+ try {+ entry.title = 'Price $& with $` and $\' and $$ <offer> "quoted"';+ entry.description = 'Text </script><script>alert("not executable")</script> & <meta name="extra">';+ publishSeo(root, { name: 'github' });+ assertCaseMetadata(fs.readFileSync(path.join(root, entry.artifact), 'utf8'), entry);+ } finally {+ Object.assign(entry, original);+ fs.rmSync(root, { recursive: true, force: true });+ }+});++test('publication rejects every missing selected case HTML or JSON before writing metadata', () => {+ const root = fixture();+ try {+ const gallery = path.join(root, `gallery/artifacts/${CASES[0].output}`);+ const original = fs.readFileSync(gallery);+ for (const entry of PUBLISHED_CASES) for (const file of [entry.artifact, entry.input]) {+ fs.rmSync(path.join(root, file));+ assert.throws(() => publishSeo(root, { name: 'cloudflare' }), /Missing published case/);+ assert.deepEqual(fs.readFileSync(gallery), original, 'missing inventory must not partially publish gallery metadata');+ fs.copyFileSync(path.join(docs, file), path.join(root, file));+ }+ } finally { fs.rmSync(root, { recursive: true, force: true }); }+});+test('publication fails closed for missing localized pages or changed proof artifacts/sources', () => {const root = fixture();try {diff --git a/website/test/seo-dollar-copy.test.mjs b/website/test/seo-dollar-copy.test.mjsnew file mode 100644index 00000000..bae69e28--- /dev/null+++ b/website/test/seo-dollar-copy.test.mjs@@ -0,0 +1,46 @@+import assert from 'node:assert/strict';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import test from 'node:test';+import { createHash } from 'node:crypto';+import { publishSeo, stripPublishedArtifactMetadata } from '../scripts/publish-seo.mjs';+import { CASES } from '../src/data/gallery-presentation.mjs';+import { canonicalPath, sitePages } from '../src/data/site-urls.mjs';++const digest = value => createHash('sha256').update(value).digest('hex');++// Regression ported from #826, with the selected case fixture added and exact+// original closing-tag bytes checked alongside literal replacement tokens.+test('SEO insertion preserves replacement tokens in authored gallery copy', t => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-seo-dollar-'));+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));+ fs.cpSync(new URL('../../docs/cases/', import.meta.url), path.join(root, 'cases'), { recursive: true });+ for (const page of sitePages) for (const lang of ['en', 'zh']) {+ const route = canonicalPath(page, lang).slice(1);+ const file = path.join(root, route === '' ? 'index.html' : `${route}.html`);+ fs.mkdirSync(path.dirname(file), { recursive: true });+ fs.writeFileSync(file, '<html></html>');+ }+ const html = '<html><head></HEAD><body>Diagram</body></html>';+ const entries = CASES.map(item => {+ const artifact = `gallery/artifacts/${item.output}`, input = `gallery/sources/${item.input}`;+ const source = '{}';+ for (const [name, content] of [[artifact, html], [input, source]]) {+ const file = path.join(root, name);+ fs.mkdirSync(path.dirname(file), { recursive: true });+ fs.writeFileSync(file, content);+ }+ return { id: item.id, artifact, input, checks: [{ ok: true }], artifactSha256: digest(html), sourceSha256: digest(source) };+ });+ fs.writeFileSync(path.join(root, 'gallery/manifest.json'), JSON.stringify({ entries }));+ const original = CASES[0].titleEn;+ t.after(() => { CASES[0].titleEn = original; });+ CASES[0].titleEn = 'Price $& with $` and $\' and $$';+ publishSeo(root, { name: 'github' });+ const published = fs.readFileSync(path.join(root, entries[0].artifact), 'utf8');+ const json = /<script type="application\/ld\+json">([\s\S]*?)<\/script>/.exec(published)[1];+ assert.equal(JSON.parse(json).name, CASES[0].titleEn);+ assert.equal((published.match(/<\/head>/gi) || []).length, 1);+ assert.equal(stripPublishedArtifactMetadata(published), html);+});