// Owner rule: no hand-written SVG. Charts come from visx, icons from lucide, the journey diagram from Mermaid, the // fixture art from tools/fixture-art.ts. This guard fails on inline SVG drawing in the desktop webview and the site. // Allowed: the brand mark (apps/desktop/src/ui/brand.tsx, the site's and site/favicon.svg: brand // assets, owner decision), the root a visx chart renders into (files that import @visx/*), lucide's own files in // site/img/icons (byte-equal to lucide-static) and the Mermaid output (docs/img, site/img journey*.svg). import { describe, expect, test } from 'bun:test'; import { readdirSync, readFileSync, statSync } from 'node:fs'; import { join, relative } from 'node:path'; import { checkSiteIcons } from '../tools/site-icons'; const ROOT = join(import.meta.dir, '..'); const walk = (dir: string, keep: (f: string) => boolean): string[] => readdirSync(join(ROOT, dir)).flatMap(n => { const rel = join(dir, n); if (n === 'node_modules' || n === 'dist') return []; return statSync(join(ROOT, rel)).isDirectory() ? walk(rel, keep) : keep(n) ? [rel] : []; }); const read = (f: string) => readFileSync(join(ROOT, f), 'utf8'); /** SVG drawing elements and inline SVG images. */ const SHAPES = /<(path|circle|rect|ellipse|line|polyline|polygon)[\s/>]|data:image\/svg\+xml|]/g; const BRAND_FILES = ['apps/desktop/src/ui/brand.tsx']; const SITE_MARK = ''; /** Every hand-drawn hit in a source text: "file:line { test('desktop webview: charts through visx, icons through lucide, no inline SVG outside the brand mark', () => { const files = walk('apps/desktop/src', n => /\.(tsx?|css|html)$/.test(n)); expect(files.length).toBeGreaterThan(30); const hits = files.filter(f => !BRAND_FILES.includes(f)).flatMap(f => { const s = read(f); return svgHits(f, s, { visxRoot: /from '@visx\//.test(s) }); }); expect(hits).toEqual([]); }); test('the guard itself catches a drawn icon and an inline SVG image', () => { expect(svgHits('x.tsx', 'const a = ;')).toHaveLength(2); expect(svgHits('x.ts', "const u = 'data:image/svg+xml;base64,AAAA';")).toHaveLength(1); expect(svgHits('x.tsx', '', { visxRoot: true })).toEqual([]); expect(svgHits('x.tsx', '', { visxRoot: true })).toHaveLength(1); }); test('site pages: icons are lucide files in site/img/icons; only the brand mark is inline', () => { const pages = walk('site', n => n.endsWith('.html')); expect(pages.length).toBeGreaterThanOrEqual(2); const hits = pages.flatMap(f => svgHits(f, read(f).split(SITE_MARK).join(''))); expect(hits).toEqual([]); expect(checkSiteIcons()).toEqual([]); for (const f of ['site/style.css', 'site/main.js']) expect(svgHits(f, read(f)), f).toEqual([]); }); test('SVG files: brand favicon, vendored lucide icons and Mermaid diagrams only', () => { const svgs = [...walk('site', n => n.endsWith('.svg')), ...walk('docs', n => n.endsWith('.svg'))].map(f => relative(ROOT, join(ROOT, f))); for (const f of svgs) { if (f === 'site/favicon.svg' || f.startsWith('site/img/icons/')) continue; expect(f, `${f}: not a known asset`).toMatch(/^(docs|site)\/img\/journey(-tall)?\.svg$/); expect(read(f), `${f}: render it with bun tools/diagrams.ts`).toContain('aria-roledescription="flowchart-v2"'); } }); });