yadflow 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +152 -0
- package/README.md +14 -3
- package/bin/commands.mjs +7 -1
- package/bin/yad.mjs +163 -16
- package/cli/agent-guard-worker.mjs +13 -0
- package/cli/agent-guard.mjs +1053 -57
- package/cli/agent-rules.mjs +59 -3
- package/cli/argv-flags.mjs +2 -2
- package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
- package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
- package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
- package/cli/brain/vendor/graphology-library.min.js +2 -0
- package/cli/brain/vendor/graphology.umd.min.js +2 -0
- package/cli/brain/vendor/sigma.min.js +1369 -0
- package/cli/brain/view/app.js +382 -0
- package/cli/brain/view/index.html +63 -0
- package/cli/brain/view/live.css +228 -0
- package/cli/brain/view/live.html +110 -0
- package/cli/brain/view/live.js +884 -0
- package/cli/brain/view/style.css +141 -0
- package/cli/brain-about.mjs +206 -0
- package/cli/brain-activity.mjs +285 -0
- package/cli/brain-skills.mjs +118 -0
- package/cli/brain-vendor.mjs +71 -0
- package/cli/brain-view.mjs +345 -0
- package/cli/brain.mjs +810 -0
- package/cli/brand-cmd.mjs +326 -0
- package/cli/brand.mjs +327 -0
- package/cli/ci-check.mjs +3 -3
- package/cli/doctor.mjs +145 -14
- package/cli/epic-state.mjs +93 -1
- package/cli/epic.mjs +15 -3
- package/cli/errors.mjs +2 -1
- package/cli/find-product.mjs +69 -15
- package/cli/foundation-publish.mjs +256 -0
- package/cli/gate.mjs +29 -3
- package/cli/git-read.mjs +38 -0
- package/cli/guard-stream.mjs +409 -0
- package/cli/guide.mjs +26 -3
- package/cli/hook.mjs +59 -9
- package/cli/issues-act.mjs +57 -13
- package/cli/issues-write.mjs +19 -6
- package/cli/issues.mjs +69 -24
- package/cli/lib.mjs +37 -2
- package/cli/local-page.mjs +138 -0
- package/cli/local-setup-record.mjs +71 -0
- package/cli/local-setup-steps.mjs +186 -0
- package/cli/local-setup.mjs +611 -0
- package/cli/machine.mjs +1 -1
- package/cli/manifest.mjs +55 -0
- package/cli/map/view/app.js +712 -0
- package/cli/map/view/index.html +50 -0
- package/cli/map/view/style.css +142 -0
- package/cli/map-view.mjs +190 -0
- package/cli/map.mjs +637 -0
- package/cli/members.mjs +9 -15
- package/cli/next.mjs +1 -1
- package/cli/openpr.mjs +2 -2
- package/cli/plain-text.mjs +22 -0
- package/cli/plan.mjs +310 -36
- package/cli/platform.mjs +5 -5
- package/cli/product-index.mjs +1 -1
- package/cli/protection.mjs +32 -0
- package/cli/reconcile.mjs +61 -13
- package/cli/report.mjs +9 -3
- package/cli/reports-dir.mjs +393 -0
- package/cli/reports.mjs +65 -0
- package/cli/run-checks.mjs +5 -2
- package/cli/scan.mjs +4 -6
- package/cli/secret-text.mjs +66 -0
- package/cli/setup.mjs +54 -8
- package/cli/standup.mjs +94 -72
- package/cli/status.mjs +6 -5
- package/cli/test-agents-file.mjs +614 -8
- package/cli/test-brain-activity.mjs +753 -0
- package/cli/test-brain-view.mjs +381 -0
- package/cli/test-brain.mjs +795 -0
- package/cli/test-brand.mjs +558 -0
- package/cli/test-guide.mjs +438 -0
- package/cli/test-local-setup.mjs +1188 -0
- package/cli/test-machine.mjs +59 -0
- package/cli/test-map.mjs +615 -0
- package/cli/test-reports.mjs +382 -0
- package/cli/test-run-checks.mjs +4 -0
- package/cli/test-worktree.mjs +24 -3
- package/cli/toolbox-connect.mjs +21 -6
- package/cli/toolbox.mjs +74 -5
- package/cli/update-commit.mjs +118 -9
- package/cli/usage.mjs +17 -7
- package/cli/workspace.mjs +11 -2
- package/package.json +8 -4
- package/skills/sdlc/module-help.csv +1 -0
- package/skills/yad-architecture/SKILL.md +22 -4
- package/skills/yad-brand/SKILL.md +69 -0
- package/skills/yad-change/SKILL.md +3 -1
- package/skills/yad-change/references/triage.md +2 -0
- package/skills/yad-checks/SKILL.md +2 -0
- package/skills/yad-checks/references/check-gates.md +8 -5
- package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
- package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
- package/skills/yad-checks/templates/github/yad-checks.yml +3 -2
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +3 -2
- package/skills/yad-checks/templates/hooks/local-setup-notice.mjs +96 -0
- package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
- package/skills/yad-connect-repos/SKILL.md +14 -0
- package/skills/yad-discovery/SKILL.md +11 -0
- package/skills/yad-discovery/references/foundation-schema.md +11 -0
- package/skills/yad-docs/templates/app/package-lock.json +18 -10
- package/skills/yad-docs/templates/app/package.json +6 -1
- package/skills/yad-epic/SKILL.md +3 -0
- package/skills/yad-epic/references/state-schema.md +35 -1
- package/skills/yad-guide/SKILL.md +10 -7
- package/skills/yad-implement/SKILL.md +76 -15
- package/skills/yad-issues/SKILL.md +2 -1
- package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +8 -4
- package/skills/yad-spec/SKILL.md +19 -0
- package/skills/yad-stories/SKILL.md +22 -4
- package/skills/yad-stories/references/story-schema.md +1 -1
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
// E184 — the Product's brand on every page yadflow makes. Every brand, name and file here is invented.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
if (process.env.NODE_TEST_CONTEXT) {
|
|
12
|
+
const write = process.stdout.write;
|
|
13
|
+
for (const k of ['log', 'info']) {
|
|
14
|
+
const orig = console[k];
|
|
15
|
+
console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
process.env.YAD_NO_UPDATE_NOTIFIER = '1';
|
|
19
|
+
|
|
20
|
+
const { readBrand, checkBrand, brandCss, brandAssets, brandForPage, contrast, contrastProblems, linearRgb, COLOR_RE, BRAND_FILE, YADFLOW_BRAND, PAGE_MAPS, DATA_IMAGE_RE } = await import('./brand.mjs');
|
|
21
|
+
const { runBrand, readFrontMatter, readRootVars, rolesFrom } = await import('./brand-cmd.mjs');
|
|
22
|
+
const { classify } = await import('./agent-rules.mjs');
|
|
23
|
+
const { endJSON } = await import('./lib.mjs');
|
|
24
|
+
|
|
25
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
const YAD = path.join(HERE, '..', 'bin', 'yad.mjs');
|
|
27
|
+
const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-brand-')));
|
|
28
|
+
const put = (f, d) => { fs.mkdirSync(path.dirname(f), { recursive: true }); fs.writeFileSync(f, typeof d === 'string' || Buffer.isBuffer(d) ? d : JSON.stringify(d, null, 2)); };
|
|
29
|
+
const done = (...d) => d.forEach((x) => fs.rmSync(x, { recursive: true, force: true }));
|
|
30
|
+
const SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><circle cx="5" cy="5" r="4" fill="#2a7"/></svg>';
|
|
31
|
+
async function captured(fn) {
|
|
32
|
+
const out = []; const orig = console.log;
|
|
33
|
+
console.log = (s) => out.push(String(s));
|
|
34
|
+
try { await fn(); } finally { console.log = orig; endJSON(); }
|
|
35
|
+
return out.length ? JSON.parse(out.join('\n')) : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// A Product with a YAML front-matter design system (the shape the Impeccable DESIGN.md spec uses).
|
|
39
|
+
const YAML_DESIGN = `---
|
|
40
|
+
name: Fernleaf (fernleaf.example)
|
|
41
|
+
description: invented
|
|
42
|
+
colors:
|
|
43
|
+
primary: "#2B7358"
|
|
44
|
+
accent: "#E4A036"
|
|
45
|
+
ink: "#101828"
|
|
46
|
+
ink-secondary: "#667085"
|
|
47
|
+
bg: "#F4F6FF"
|
|
48
|
+
surface: "#FFFFFF"
|
|
49
|
+
border: "#D0D5DD"
|
|
50
|
+
dark-bg: "#0D291F"
|
|
51
|
+
dark-surface: "#1A3D2E"
|
|
52
|
+
dark-ink: "#F2F4F7"
|
|
53
|
+
dark-ink-secondary: "#D3DBE9"
|
|
54
|
+
dark-border: "#2B7358"
|
|
55
|
+
dark-primary-strong: "#94CBBA"
|
|
56
|
+
typography:
|
|
57
|
+
display:
|
|
58
|
+
fontFamily: "Fernsans, sans-serif"
|
|
59
|
+
fontSize: "28px"
|
|
60
|
+
body:
|
|
61
|
+
fontFamily: "Fernsans, sans-serif"
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
# Fernleaf design system
|
|
65
|
+
`;
|
|
66
|
+
// A Product with a CSS :root block in OKLCH (the shape a hand-written DESIGN.md often has).
|
|
67
|
+
const CSS_DESIGN = `# Design
|
|
68
|
+
|
|
69
|
+
The visual system for **Quillmark**.
|
|
70
|
+
|
|
71
|
+
\`\`\`css
|
|
72
|
+
:root {
|
|
73
|
+
--bg: oklch(1.000 0.000 0); /* page */
|
|
74
|
+
--surface: oklch(0.975 0.002 75);
|
|
75
|
+
--border: oklch(0.912 0.003 75);
|
|
76
|
+
--ink: oklch(0.205 0.008 70);
|
|
77
|
+
--muted: oklch(0.460 0.006 70);
|
|
78
|
+
--gold: oklch(0.680 0.135 62);
|
|
79
|
+
--action: oklch(0.220 0.010 70);
|
|
80
|
+
}
|
|
81
|
+
\`\`\`
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
function product({ design = null, files = {} } = {}) {
|
|
85
|
+
const ws = tmp();
|
|
86
|
+
const root = path.join(ws, 'product');
|
|
87
|
+
put(path.join(root, '.sdlc', 'product.json'), { name: 'Invented' });
|
|
88
|
+
if (design) put(path.join(root, 'DESIGN.md'), design);
|
|
89
|
+
for (const [rel, data] of Object.entries(files)) put(path.join(root, rel), data);
|
|
90
|
+
return { ws, root };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
test('no brand file: every page wears yadflow\'s look, with its mark, and nothing is said wrong', () => {
|
|
94
|
+
const { ws, root } = product();
|
|
95
|
+
try {
|
|
96
|
+
const r = readBrand(root);
|
|
97
|
+
assert.equal(r.origin, 'yadflow');
|
|
98
|
+
assert.deepEqual(r.problems, []);
|
|
99
|
+
assert.equal(r.brand.colors.light.primary, '#6316db');
|
|
100
|
+
const p = brandForPage(root, 'standup');
|
|
101
|
+
assert.match(p.css, /--brand-primary:#6316db/);
|
|
102
|
+
assert.match(p.css, /--brand-mark:url\("data:image\/svg\+xml;base64,/, 'yadflow\'s mark');
|
|
103
|
+
assert.match(p.css, /body h1::before/);
|
|
104
|
+
} finally { done(ws); }
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a colour must be one yadflow can write safely: nothing can end the CSS it goes into', () => {
|
|
108
|
+
for (const ok of ['#fff', '#A1b2C3', '#11223344', 'oklch(0.68 0.135 62)', 'oklch(68% 0.1 62deg)', 'rgb(1, 2, 3)', 'hsl(210 50% 40% / .5)', 'oklab(0.5 0.1 -0.1)']) assert.ok(COLOR_RE.test(ok), ok);
|
|
109
|
+
for (const bad of ['red', '#ggg', 'url(x)', '#fff;}body{display:none', 'oklch(0.5 0.1 62);x', 'expression(alert(1))', 'rgb(1,2,3)}', 'var(--x)', '"#fff"']) assert.equal(COLOR_RE.test(bad), false, bad);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('the brand file is checked: paths stay inside, types and sizes, families, version', () => {
|
|
113
|
+
const { ws, root } = product({ files: { 'design/mark.svg': SVG, 'design/big.png': Buffer.alloc(600 * 1024), 'design/x.gif': 'gif' } });
|
|
114
|
+
try {
|
|
115
|
+
fs.writeFileSync(path.join(ws, 'outside.svg'), SVG);
|
|
116
|
+
fs.symlinkSync(path.join(ws, 'outside.svg'), path.join(root, 'design', 'link.svg'));
|
|
117
|
+
const base = { version: 1, name: 'Invented', colors: { light: { bg: '#fff', text: '#111' } } };
|
|
118
|
+
assert.deepEqual(checkBrand(root, { ...base, mark: 'design/mark.svg' }).problems, []);
|
|
119
|
+
const bad = (extra) => checkBrand(root, { ...base, ...extra }).problems.join(' | ');
|
|
120
|
+
assert.match(bad({ mark: '../outside.svg' }), /not a file inside the Product/);
|
|
121
|
+
assert.match(bad({ mark: 'design/link.svg' }), /not a file inside the Product/, 'a link out is never followed');
|
|
122
|
+
assert.match(bad({ mark: '/etc/hosts' }), /not a file inside the Product/);
|
|
123
|
+
assert.match(bad({ logo: 'design/x.gif' }), /is not one of/);
|
|
124
|
+
assert.match(bad({ logo: 'design/big.png' }), /at most 512 KB/);
|
|
125
|
+
assert.match(bad({ fonts: { body: { family: 'Evil"; } body{', files: [] } } }), /fonts.body.family must be a font name/);
|
|
126
|
+
assert.match(bad({ version: 2 }), /version 2/);
|
|
127
|
+
assert.match(bad({ colors: { light: { bg: 'red' } } }), /colors.light.bg is not a colour/);
|
|
128
|
+
assert.match(bad({ name: '' }), /"name"/);
|
|
129
|
+
// A broken file never breaks a page: the fallback, with the problem said.
|
|
130
|
+
put(path.join(root, BRAND_FILE), '{ nope');
|
|
131
|
+
const r = readBrand(root);
|
|
132
|
+
assert.equal(r.origin, 'yadflow');
|
|
133
|
+
assert.match(r.problems[0], /cannot be read/);
|
|
134
|
+
} finally { done(ws); }
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('init from YAML front matter: roles by name, dark from dark-*, fonts and their files, the mark found', async () => {
|
|
138
|
+
const { ws, root } = product({ design: YAML_DESIGN, files: { 'design/fonts/Fernsans-Bold.woff2': 'fontbytes', 'design/assets/fernleaf-logo.svg': SVG, 'design/assets/fernleaf-mark.svg': SVG } });
|
|
139
|
+
try {
|
|
140
|
+
const out = await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
141
|
+
assert.equal(out.command, null);
|
|
142
|
+
const b = out.brand;
|
|
143
|
+
assert.equal(b.name, 'Fernleaf');
|
|
144
|
+
assert.deepEqual(b.colors.light, { bg: '#F4F6FF', surface: '#FFFFFF', text: '#101828', muted: '#667085', border: '#D0D5DD', primary: '#2B7358', accent: '#E4A036' });
|
|
145
|
+
assert.equal(b.colors.dark.bg, '#0D291F');
|
|
146
|
+
assert.equal(b.colors.dark.primary, '#94CBBA', 'dark-primary-strong');
|
|
147
|
+
assert.equal(b.fonts.heading.family, 'Fernsans');
|
|
148
|
+
assert.deepEqual(b.fonts.heading.files, ['design/fonts/Fernsans-Bold.woff2']);
|
|
149
|
+
assert.equal(b.logo, 'design/assets/fernleaf-logo.svg');
|
|
150
|
+
assert.equal(b.mark, 'design/assets/fernleaf-mark.svg');
|
|
151
|
+
assert.equal(out.report.how, 'front matter');
|
|
152
|
+
assert.equal(out.report.filled.light.text, 'ink');
|
|
153
|
+
assert.match(b.sourceHash, /^sha256:[0-9a-f]{64}$/);
|
|
154
|
+
assert.equal(readBrand(root).origin, 'product');
|
|
155
|
+
// Not overwritten without --force.
|
|
156
|
+
assert.equal((await captured(() => runBrand(root, { action: 'init', json: true }))).ok, false);
|
|
157
|
+
process.exitCode = 0;
|
|
158
|
+
} finally { done(ws); }
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('init from a :root block in OKLCH: --action is primary, --gold is accent, missing roles are named', async () => {
|
|
162
|
+
const { ws, root } = product({ design: CSS_DESIGN });
|
|
163
|
+
try {
|
|
164
|
+
const out = await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
165
|
+
assert.equal(out.report.how, ':root block');
|
|
166
|
+
assert.equal(out.brand.name, 'Invented', 'the Product\'s own name, when there is no front matter name');
|
|
167
|
+
assert.equal(out.brand.colors.light.primary, 'oklch(0.220 0.010 70)');
|
|
168
|
+
assert.equal(out.brand.colors.light.accent, 'oklch(0.680 0.135 62)');
|
|
169
|
+
assert.equal(out.brand.colors.dark, null, 'no dark block: made from light later');
|
|
170
|
+
assert.deepEqual(out.report.missing, []);
|
|
171
|
+
const r = readBrand(root);
|
|
172
|
+
assert.equal(r.brand.colors.derivedDark, true);
|
|
173
|
+
assert.equal(r.brand.colors.dark.bg, YADFLOW_BRAND.colors.dark.bg, 'a neutral dark …');
|
|
174
|
+
assert.equal(r.brand.colors.dark.primary, 'oklch(0.610 0.010 70)', '… with the brand\'s own primary made lighter, so it reads on the dark');
|
|
175
|
+
} finally { done(ws); }
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('init refuses prose it cannot read, and a logo path outside the Product', async () => {
|
|
179
|
+
const { ws, root } = product({ design: '# Design\n\nOur primary colour is a deep teal.\n' });
|
|
180
|
+
try {
|
|
181
|
+
const prose = await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
182
|
+
assert.equal(prose.ok, false);
|
|
183
|
+
assert.match(prose.error, /no colours yadflow can read/);
|
|
184
|
+
assert.match(prose.hint, /yad-brand skill/);
|
|
185
|
+
const out = await captured(() => runBrand(root, { action: 'init', logo: '../x.svg', json: true }));
|
|
186
|
+
assert.match(out.error, /not a file inside the Product/);
|
|
187
|
+
const missing = await captured(() => runBrand(root, { action: 'init', from: 'design/none.md', json: true }));
|
|
188
|
+
assert.match(missing.error, /no design\/none.md/);
|
|
189
|
+
process.exitCode = 0;
|
|
190
|
+
} finally { done(ws); }
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('the parsers: front matter maps, :root and dark blocks, role names', () => {
|
|
194
|
+
const fm = readFrontMatter('---\na: 1\nb:\n c: "x" # note\n d:\n e: \'y\'\n---\nbody');
|
|
195
|
+
assert.deepEqual(fm, { a: '1', b: { c: 'x', d: { e: 'y' } } });
|
|
196
|
+
assert.equal(readFrontMatter('no front matter'), null);
|
|
197
|
+
const css = readRootVars(':root { --bg: #fff; --ink: #111 }\n@media (prefers-color-scheme: dark) { :root { --bg: #000; --ink: #eee } }');
|
|
198
|
+
assert.deepEqual(css.light, { '--bg': '#fff', '--ink': '#111' });
|
|
199
|
+
assert.deepEqual(css.dark, { '--bg': '#000', '--ink': '#eee' });
|
|
200
|
+
assert.deepEqual(rolesFrom({ 'color-background': '#fff', foreground: '#000', 'not-a-colour': 'blue' }).colors, { bg: '#fff', text: '#000' });
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('check: stale when DESIGN.md moved on; contrast in hex and OKLCH; exit 1 only for an unusable file', async () => {
|
|
204
|
+
const { ws, root } = product({ design: YAML_DESIGN });
|
|
205
|
+
try {
|
|
206
|
+
await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
207
|
+
let c = await captured(() => runBrand(root, { action: 'check', json: true }));
|
|
208
|
+
assert.equal(c.ok, true);
|
|
209
|
+
assert.equal(c.stale, null);
|
|
210
|
+
fs.appendFileSync(path.join(root, 'DESIGN.md'), '\nmore\n');
|
|
211
|
+
c = await captured(() => runBrand(root, { action: 'check', json: true }));
|
|
212
|
+
assert.match(c.stale, /DESIGN.md changed since/);
|
|
213
|
+
assert.equal(c.ok, true, 'stale is a warning, not a failure');
|
|
214
|
+
// Contrast.
|
|
215
|
+
assert.ok(contrast('#000', '#fff') > 20);
|
|
216
|
+
assert.ok(Math.abs(contrast('oklch(1 0 0)', '#ffffff') - 1) < 0.01, 'oklch white is white');
|
|
217
|
+
assert.equal(contrast('hsl(0 0% 0%)', '#fff'), null, 'not read: never guessed');
|
|
218
|
+
assert.ok(linearRgb('oklch(0.205 0.008 70)'));
|
|
219
|
+
const low = { ...YADFLOW_BRAND, colors: { light: { ...YADFLOW_BRAND.colors.light, text: '#eeeeee' }, dark: YADFLOW_BRAND.colors.dark } };
|
|
220
|
+
assert.match(contrastProblems(low)[0], /light: text on bg is .* under 4.5:1/);
|
|
221
|
+
// An unusable file: exit 1 on check.
|
|
222
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'X', colors: { light: { bg: 'nope' } } });
|
|
223
|
+
const bad = await captured(() => runBrand(root, { action: 'check', json: true }));
|
|
224
|
+
assert.equal(bad.ok, false);
|
|
225
|
+
assert.equal(process.exitCode, 1);
|
|
226
|
+
process.exitCode = 0;
|
|
227
|
+
} finally { done(ws); }
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('the CSS: fonts embedded under the cap, both schemes named, status only when set, the mark only as a data image', () => {
|
|
231
|
+
const { ws, root } = product({ files: { 'design/fonts/Fernsans.woff2': 'abc', 'design/mark.svg': SVG } });
|
|
232
|
+
try {
|
|
233
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'Fern', mark: 'design/mark.svg', colors: { light: { bg: '#fff', text: '#111', primary: '#2b7358' } },
|
|
234
|
+
fonts: { body: { family: 'Fernsans', files: ['design/fonts/Fernsans.woff2'] } }, status: { live: '#0055ff' } });
|
|
235
|
+
const r = readBrand(root);
|
|
236
|
+
assert.equal(r.origin, 'product');
|
|
237
|
+
const assets = brandAssets(root, r.brand, r.origin);
|
|
238
|
+
const css = brandCss(r.brand, assets);
|
|
239
|
+
assert.match(css, /@font-face\{font-family:"Fernsans";src:url\(data:font\/woff2;base64,YWJj\) format\("woff2"\)/);
|
|
240
|
+
assert.match(css, /--brand-primary:#2b7358;--brand-dark-primary:#/);
|
|
241
|
+
assert.match(css, /--brand-font-body:"Fernsans", system-ui/);
|
|
242
|
+
assert.match(css, /--brand-status-live:#0055ff/);
|
|
243
|
+
assert.equal(/--brand-status-merged/.test(css), false);
|
|
244
|
+
assert.ok(DATA_IMAGE_RE.test(assets.mark));
|
|
245
|
+
// The map keeps its status colours unless the brand sets them.
|
|
246
|
+
assert.match(PAGE_MAPS.map, /--merged:var\(--brand-status-merged, #d55181\)/);
|
|
247
|
+
assert.match(PAGE_MAPS.map, /--bg:var\(--brand-dark-bg\)/, 'the map is always dark');
|
|
248
|
+
} finally { done(ws); }
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('every page takes the brand: reports and the catalog carry it after their own CSS, with fonts and images allowed', async () => {
|
|
252
|
+
const { ws, root } = product({ design: YAML_DESIGN, files: { 'design/assets/fernleaf-mark.svg': SVG } });
|
|
253
|
+
try {
|
|
254
|
+
await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
255
|
+
const { renderHtml: standupHtml } = await import('./standup.mjs');
|
|
256
|
+
const { renderHtml: issuesHtml } = await import('./issues.mjs');
|
|
257
|
+
const { renderIndex } = await import('./reports-dir.mjs');
|
|
258
|
+
const css = brandForPage(root, 'issues').css;
|
|
259
|
+
const issues = issuesHtml({ items: [], repos: [], notes: [], notRead: [], summary: { total: 0, status: {}, priority: {}, type: {}, unassigned: 0 }, unfiltered: 0 }, undefined, { brandCss: css });
|
|
260
|
+
assert.match(issues, /--brand-primary:#2B7358/);
|
|
261
|
+
assert.ok(issues.indexOf('--brand-primary') > issues.indexOf('--p0:'), 'after the page\'s own colours, so it wins');
|
|
262
|
+
assert.match(issues, /img-src data:; font-src data:/);
|
|
263
|
+
const index = renderIndex([], { brandCss: brandForPage(root, 'catalog').css });
|
|
264
|
+
assert.match(index, /img-src data:; font-src data:/);
|
|
265
|
+
assert.match(index, /body > main > h1::before/);
|
|
266
|
+
assert.equal(typeof standupHtml, 'function');
|
|
267
|
+
} finally { done(ws); }
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('yad brand from the CLI, and its agent classes', () => {
|
|
271
|
+
const { ws, root } = product();
|
|
272
|
+
try {
|
|
273
|
+
const r = spawnSync(process.execPath, [YAD, 'brand', '--json'], { cwd: root, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' } });
|
|
274
|
+
assert.equal(r.status, 0, r.stderr);
|
|
275
|
+
const out = JSON.parse(r.stdout);
|
|
276
|
+
assert.equal(out.command, 'brand show');
|
|
277
|
+
assert.equal(out.origin, 'yadflow');
|
|
278
|
+
assert.equal(classify(['brand']), 'read');
|
|
279
|
+
assert.equal(classify(['brand', 'check']), 'read');
|
|
280
|
+
assert.equal(classify(['brand', 'init']), 'on-request', 'it writes a committed file: only when the person asks');
|
|
281
|
+
} finally { done(ws); }
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// #553: the self-contained map and brain files carry the brand inside the ONE hashed style, so the CSP still
|
|
285
|
+
// allows it; fonts are allowed as data; the map's status colours keep their meaning unless the brand sets them.
|
|
286
|
+
test('#553: the map and brain files carry the brand inside the hashed style; status colours stay', async () => {
|
|
287
|
+
const { ws, root } = product({ design: YAML_DESIGN, files: { 'design/assets/fernleaf-mark.svg': SVG } });
|
|
288
|
+
try {
|
|
289
|
+
await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
290
|
+
const { mapSnapshot } = await import('./map-view.mjs');
|
|
291
|
+
const { snapshotHTML } = await import('./brain-view.mjs');
|
|
292
|
+
const pages = [
|
|
293
|
+
['map', mapSnapshot({ epics: [] }, { brandCss: brandForPage(root, 'map').css })],
|
|
294
|
+
['brain', snapshotHTML({ nodes: [], edges: [] }, { brandCss: brandForPage(root, 'brain').css })],
|
|
295
|
+
['live', snapshotHTML({ nodes: [], edges: [] }, { live: true, brandCss: brandForPage(root, 'live').css })],
|
|
296
|
+
];
|
|
297
|
+
for (const [page, html] of pages) {
|
|
298
|
+
const csp = /<meta http-equiv="Content-Security-Policy" content="([^"]+)">/.exec(html)[1];
|
|
299
|
+
assert.match(csp, /font-src data:/, page);
|
|
300
|
+
const styles = [...html.matchAll(/<style>([\s\S]*?)<\/style>/g)].map((x) => x[1]);
|
|
301
|
+
assert.equal(styles.length, 1, `${page}: one inline style`);
|
|
302
|
+
assert.match(styles[0], /--brand-primary:#2B7358/i, `${page}: the brand is in the style`);
|
|
303
|
+
const hash = createHash('sha256').update(styles[0], 'utf8').digest('base64');
|
|
304
|
+
assert.ok(csp.includes(`'sha256-${hash}'`), `${page}: the CSP allows the style with the brand in it`);
|
|
305
|
+
}
|
|
306
|
+
const mapCss = brandForPage(root, 'map').css;
|
|
307
|
+
for (const [k, v] of [['live', '#3987e5'], ['merged', '#d55181'], ['active', '#c98500'], ['planned', '#93a0bf'], ['idle', '#5b6680']]) {
|
|
308
|
+
assert.ok(mapCss.includes(`--${k}:var(--brand-status-${k}, ${v})`), `${k} keeps its colour`);
|
|
309
|
+
}
|
|
310
|
+
assert.ok(!/--brand-status-live:/.test(mapCss), 'no status colour unless the brand sets one');
|
|
311
|
+
} finally { done(ws); }
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('#553: a standup page carries the brand after its own colours; with no brand file it is yadflow\'s look', async () => {
|
|
315
|
+
const { renderHtml, buildStandup } = await import('./standup.mjs');
|
|
316
|
+
const branded = product();
|
|
317
|
+
try {
|
|
318
|
+
const model = buildStandup(branded.root, { now: Date.now(), fetch: false, env: {}, access: () => 'yes' });
|
|
319
|
+
const page = renderHtml(model, { brandCss: ':root{--brand-primary:#2B7358}' });
|
|
320
|
+
assert.ok(page.indexOf('--brand-primary:#2B7358') > page.indexOf('--bg:'), 'after the page\'s own colours, so it wins');
|
|
321
|
+
assert.equal(page.split('</style>').length, 2, 'still one style block');
|
|
322
|
+
assert.ok(!renderHtml(model).includes('--brand-'), 'no brand CSS asked for, none added');
|
|
323
|
+
} finally { done(branded.ws); }
|
|
324
|
+
const { ws, root } = product();
|
|
325
|
+
try {
|
|
326
|
+
const css = brandForPage(root, 'standup').css;
|
|
327
|
+
assert.match(css, /--brand-primary:#6316db/i, 'yadflow\'s purple');
|
|
328
|
+
assert.match(css, /--brand-accent:#fb2576/i, 'yadflow\'s pink');
|
|
329
|
+
} finally { done(ws); }
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('#553: the doctor row — none is fine, a broken file and a changed DESIGN.md are said', async () => {
|
|
333
|
+
const { brandChecks } = await import('./doctor.mjs');
|
|
334
|
+
const row = (root) => { const checks = []; brandChecks(root, checks); return checks.find((x) => x.id === 'brand'); };
|
|
335
|
+
const none = product();
|
|
336
|
+
const made = product({ design: YAML_DESIGN });
|
|
337
|
+
try {
|
|
338
|
+
assert.equal(row(none.root).status, 'ok');
|
|
339
|
+
assert.match(row(none.root).message, /yadflow's look/);
|
|
340
|
+
put(path.join(none.root, BRAND_FILE), '{ broken');
|
|
341
|
+
assert.equal(row(none.root).status, 'warn');
|
|
342
|
+
await captured(() => runBrand(made.root, { action: 'init', json: true }));
|
|
343
|
+
assert.equal(row(made.root).status, 'ok');
|
|
344
|
+
put(path.join(made.root, 'DESIGN.md'), `${YAML_DESIGN}\nMore words.\n`);
|
|
345
|
+
assert.equal(row(made.root).status, 'warn');
|
|
346
|
+
assert.match(row(made.root).message, /DESIGN\.md changed since/);
|
|
347
|
+
} finally { done(none.ws, made.ws); }
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// ---- review 1 -----------------------------------------------------------------------------------
|
|
351
|
+
|
|
352
|
+
test('#553 review 1: a long or nested dark block and a huge colour are read in linear time', { timeout: 5000 }, async () => {
|
|
353
|
+
const { isColor } = await import('./brand.mjs');
|
|
354
|
+
const dark = `.dark {${Array.from({ length: 40 }, (_, i) => ` --c${i}: #000;`).join('')} .card { color: red; } }`;
|
|
355
|
+
let t = Date.now();
|
|
356
|
+
const r = readRootVars(`:root{--bg:#fff}\n${dark}`);
|
|
357
|
+
assert.ok(Date.now() - t < 1000, `read in ${Date.now() - t} ms`);
|
|
358
|
+
t = Date.now();
|
|
359
|
+
for (const hostile of ['{'.repeat(200000), '/*'.repeat(100000), '"'.repeat(200000), `:root{--a:1}${'.dark{'.repeat(50000)}--bg:#000${'}'.repeat(50000)}`]) readRootVars(hostile);
|
|
360
|
+
assert.ok(Date.now() - t < 2000, `hostile input read in ${Date.now() - t} ms`);
|
|
361
|
+
assert.equal(Object.keys(r.dark).length, 40);
|
|
362
|
+
assert.deepEqual(readRootVars(`:root{--bg:#fff}\n@media (prefers-color-scheme: dark) { :root { --bg: #000; } }`).dark, { '--bg': '#000' });
|
|
363
|
+
t = Date.now();
|
|
364
|
+
assert.equal(isColor(`rgb(${' '.repeat(400000)}x`), false);
|
|
365
|
+
assert.equal(isColor(`rgb(${'1 '.repeat(40)})`), false, 'longer than any colour');
|
|
366
|
+
assert.ok(Date.now() - t < 200, `refused in ${Date.now() - t} ms`);
|
|
367
|
+
assert.equal(isColor(' #2B7358 '), true);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('#553 review 1: init through a linked Product writes a path inside it, never this machine\'s folders', async () => {
|
|
371
|
+
const { ws, root } = product({ design: YAML_DESIGN });
|
|
372
|
+
const link = path.join(ws, 'linked');
|
|
373
|
+
fs.symlinkSync(root, link, 'dir');
|
|
374
|
+
try {
|
|
375
|
+
await captured(() => runBrand(link, { action: 'init', json: true }));
|
|
376
|
+
const rec = JSON.parse(fs.readFileSync(path.join(root, BRAND_FILE), 'utf8'));
|
|
377
|
+
assert.equal(rec.source, 'DESIGN.md');
|
|
378
|
+
const r = await captured(() => runBrand(link, { action: 'check', json: true }));
|
|
379
|
+
assert.equal(r.stale, null, 'staleness still tracked');
|
|
380
|
+
} finally { done(ws); }
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('#553 review 1: a source that is a folder is said, never a crash; a hand-made file says staleness is not tracked', async () => {
|
|
384
|
+
const { ws, root } = product({ files: { 'design/x.txt': 'x' } });
|
|
385
|
+
try {
|
|
386
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'Hand', source: 'design', colors: { light: { primary: '#2B7358' } } });
|
|
387
|
+
// With a fingerprint too: that is the path that once read the folder and threw.
|
|
388
|
+
const withHash = product({ files: { 'design/x.txt': 'x' } });
|
|
389
|
+
try {
|
|
390
|
+
put(path.join(withHash.root, BRAND_FILE), { version: 1, name: 'Hand', source: 'design', sourceHash: 'sha256:00', colors: { light: { primary: '#2B7358' } } });
|
|
391
|
+
assert.match((await captured(() => runBrand(withHash.root, { action: 'check', json: true }))).stale, /cannot be read/);
|
|
392
|
+
} finally { done(withHash.ws); }
|
|
393
|
+
const r = await captured(() => runBrand(root, { action: 'check', json: true }));
|
|
394
|
+
const out = r;
|
|
395
|
+
assert.match(out.stale, /cannot be read/);
|
|
396
|
+
assert.ok(out.warnings.some((w) => /no sourceHash/.test(w)), out.warnings.join(' | '));
|
|
397
|
+
} finally { done(ws); }
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test('#553 review 1: bad status colours, backslash and drive paths are refused', () => {
|
|
401
|
+
const { ws, root } = product({ files: { 'design/m.svg': SVG } });
|
|
402
|
+
try {
|
|
403
|
+
const base = { version: 1, name: 'X', colors: { light: { primary: '#2B7358' } } };
|
|
404
|
+
assert.ok(checkBrand(root, { ...base, status: { live: '#fff;}' } }).problems.some((p) => /status\.live/.test(p)));
|
|
405
|
+
assert.ok(checkBrand(root, { ...base, status: { live: '</style>' } }).problems.some((p) => /status\.live/.test(p)));
|
|
406
|
+
for (const bad of ['..\\design\\m.svg', 'C:design/m.svg', '/etc/passwd', 'design/../../m.svg']) {
|
|
407
|
+
assert.ok(checkBrand(root, { ...base, mark: bad }).problems.some((p) => /not a file inside the Product/.test(p)), bad);
|
|
408
|
+
}
|
|
409
|
+
assert.deepEqual(checkBrand(root, { ...base, mark: 'design/m.svg' }).problems, []);
|
|
410
|
+
} finally { done(ws); }
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test('#553 review 1: contrast reads each channel\'s own unit, and returns nothing for a unit it does not read', () => {
|
|
414
|
+
assert.equal(contrast('rgb(100 100 100 / 50%)', '#fff').toFixed(1), '5.9');
|
|
415
|
+
assert.equal(contrast('rgb(39.2% 39.2% 39.2%)', '#fff').toFixed(1), '5.9');
|
|
416
|
+
assert.equal(contrast('oklch(0.5 0.1 250turn)', '#fff'), null);
|
|
417
|
+
assert.ok(linearRgb('oklch(60% 40% 250)').every((x) => x >= 0 && x <= 1));
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test('#553 review 1: a dark scheme without its primary takes the light one made lighter, not yadflow\'s purple', () => {
|
|
421
|
+
const { ws, root } = product();
|
|
422
|
+
try {
|
|
423
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'X', colors: { light: { primary: '#2B7358', accent: 'hsl(1 2% 3%)' }, dark: { bg: '#0D291F' } } });
|
|
424
|
+
const r = readBrand(root);
|
|
425
|
+
assert.equal(r.origin, 'product');
|
|
426
|
+
assert.notEqual(r.brand.colors.dark.primary, YADFLOW_BRAND.colors.dark.primary);
|
|
427
|
+
assert.match(r.brand.colors.dark.primary, /^#[0-9a-f]{6}$/);
|
|
428
|
+
assert.equal(r.brand.colors.dark.accent, YADFLOW_BRAND.colors.dark.accent, 'one it cannot make lighter is yadflow\'s');
|
|
429
|
+
assert.equal(r.brand.colors.dark.bg, '#0D291F');
|
|
430
|
+
} finally { done(ws); }
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test('#553 review 1: the doctor row never prints escape codes from the file', async () => {
|
|
434
|
+
const { brandChecks } = await import('./doctor.mjs');
|
|
435
|
+
const { ws, root } = product();
|
|
436
|
+
try {
|
|
437
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'Evil\u001b]52;c;aGk=\u0007', colors: { light: { primary: '#2B7358' } } });
|
|
438
|
+
const checks = [];
|
|
439
|
+
brandChecks(root, checks);
|
|
440
|
+
const row = checks.find((x) => x.id === 'brand');
|
|
441
|
+
assert.ok(![...row.message].some((ch) => ch.charCodeAt(0) < 0x20 || ch.charCodeAt(0) === 0x7f), JSON.stringify(row.message));
|
|
442
|
+
} finally { done(ws); }
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test('#553 review 1: the served map and brain style sheets carry the brand; the usage page too; init outside a Product is refused', async () => {
|
|
446
|
+
const http = await import('node:http');
|
|
447
|
+
const { startMapServer } = await import('./map-view.mjs');
|
|
448
|
+
const { startBrainServer } = await import('./brain-view.mjs');
|
|
449
|
+
const { ws, root } = product({ design: YAML_DESIGN });
|
|
450
|
+
try {
|
|
451
|
+
await captured(() => runBrand(root, { action: 'init', json: true }));
|
|
452
|
+
const get = (port, p) => new Promise((resolve, reject) => {
|
|
453
|
+
const req = http.request({ host: '127.0.0.1', port, path: p, headers: { Host: `127.0.0.1:${port}` } }, (res) => { let b = ''; res.on('data', (c) => { b += c; }); res.on('end', () => resolve({ status: res.statusCode, body: b })); });
|
|
454
|
+
req.on('error', reject); req.end();
|
|
455
|
+
});
|
|
456
|
+
for (const start of [() => startMapServer(root, { env: { YAD_REPORTS_DIR: path.join(ws, 'r') } }), () => startBrainServer(root, {})]) {
|
|
457
|
+
const s = await start();
|
|
458
|
+
try {
|
|
459
|
+
const r = await get(s.port, `/style.css?t=${s.token}`);
|
|
460
|
+
assert.equal(r.status, 200);
|
|
461
|
+
assert.match(r.body, /--brand-primary:#2B7358/i);
|
|
462
|
+
} finally { await s.close(); }
|
|
463
|
+
}
|
|
464
|
+
const U = await import('./usage.mjs');
|
|
465
|
+
const page = U.renderHtml(U.analyze([], { since: null, until: null }), '2026-11-15', { brandCss: brandForPage(root, 'usage').css });
|
|
466
|
+
assert.ok(page.includes('--bg') && page.indexOf('--brand-primary') > page.indexOf('--bg'));
|
|
467
|
+
} finally { done(ws); }
|
|
468
|
+
const plain = tmp();
|
|
469
|
+
try {
|
|
470
|
+
put(path.join(plain, 'DESIGN.md'), YAML_DESIGN);
|
|
471
|
+
const r = spawnSync(process.execPath, [YAD, 'brand', 'init'], { cwd: plain, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' } });
|
|
472
|
+
assert.notEqual(r.status, 0);
|
|
473
|
+
assert.equal(fs.existsSync(path.join(plain, BRAND_FILE)), false);
|
|
474
|
+
} finally { done(plain); }
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// ---- review 2 -----------------------------------------------------------------------------------
|
|
478
|
+
|
|
479
|
+
test('#553 review 2: the dark block is read inside itself only, at its own level', () => {
|
|
480
|
+
const dark = (t) => readRootVars(`:root{--bg:#fff}\n${t}`).dark;
|
|
481
|
+
assert.deepEqual(dark('@media (prefers-color-scheme: dark) { :root { --bg:#000; --text:#eee } }'), { '--bg': '#000', '--text': '#eee' });
|
|
482
|
+
assert.deepEqual(dark('[data-theme=dark] { --bg:#000 }'), { '--bg': '#000' });
|
|
483
|
+
assert.deepEqual(dark('.dark{ --bg:#000; .card{ --bg:#222 } --text:#eee }'), { '--bg': '#000', '--text': '#eee' }, 'after a nested rule too, never the nested one');
|
|
484
|
+
assert.deepEqual(dark('.dark{ .card{ color:red } --bg:#000 }'), { '--bg': '#000' });
|
|
485
|
+
assert.equal(dark('@media (prefers-color-scheme: dark){ body{color:red} }\n.btn{ --pad:4px; --bg:#f00 }'), null, 'never a later component\'s');
|
|
486
|
+
// Review 3: a dark media block whose first rule is not :root; an outer @media; comments and quotes; prose.
|
|
487
|
+
assert.deepEqual(dark('@media (prefers-color-scheme: dark) { body{color:red} :root{--bg:#000} }'), { '--bg': '#000' });
|
|
488
|
+
assert.deepEqual(dark('@media screen{.dark{--bg:#000}}'), { '--bg': '#000' });
|
|
489
|
+
assert.deepEqual(dark('.x{}@media{}.dark{--bg:#000}'), { '--bg': '#000' });
|
|
490
|
+
assert.deepEqual(dark('/* use [data-theme="dark"] */ .x{--pad:1px} [data-theme="dark"]{--bg:#000}'), { '--bg': '#000' });
|
|
491
|
+
assert.deepEqual(dark('.dark { /* } */ --bg:#000 }'), { '--bg': '#000' });
|
|
492
|
+
assert.deepEqual(dark('.dark { --icon:"}"; --bg:#000 }'), { '--icon': '"}"', '--bg': '#000' });
|
|
493
|
+
assert.deepEqual(readRootVars('Dark mode follows prefers-color-scheme: dark.\n\n```css\n:root { --bg: #fff; --ink: #111 }\n@media (prefers-color-scheme: dark) { :root { --bg: #000 } }\n```'),
|
|
494
|
+
{ light: { '--bg': '#fff', '--ink': '#111' }, dark: { '--bg': '#000' } }, 'prose before the CSS is never a selector');
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// Review 4: a real DESIGN.md is markdown — an apostrophe in a heading or prose, fences with an info string, a
|
|
498
|
+
// heading right above the dark block, Tailwind's `html.dark` and `:root.dark`.
|
|
499
|
+
test('#553 review 4: a markdown DESIGN.md with apostrophes, fences and html.dark is read in full', () => {
|
|
500
|
+
const md = [
|
|
501
|
+
"# Acme's design system", '', "The team's colours are below. A \"quote\" too.", '',
|
|
502
|
+
'```css', ':root { --primary: #111; --q: "a\\"b"; --bg: #fff }', '```', '',
|
|
503
|
+
"It's dark too:", '### Dark', '```css', '@media (prefers-color-scheme: dark) { :root { --bg: #000; --primary: #eee } }', '```', '',
|
|
504
|
+
].join('\n');
|
|
505
|
+
assert.deepEqual(readRootVars(md), { light: { '--primary': '#111', '--q': '"a\\"b"', '--bg': '#fff' }, dark: { '--bg': '#000', '--primary': '#eee' } });
|
|
506
|
+
assert.deepEqual(readRootVars(':root{--bg:#fff}\nhtml.dark{--bg:#000}').dark, { '--bg': '#000' });
|
|
507
|
+
assert.deepEqual(readRootVars(':root.dark{--bg:#000}\n:root{--bg:#fff}'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } }, ':root.dark is never the light look');
|
|
508
|
+
assert.deepEqual(readRootVars(':root{--bg:#fff}\n.dark-mode{--bg:#000}').dark, { '--bg': '#000' });
|
|
509
|
+
assert.equal(readRootVars(':root{--bg:#fff}\n.darkmode{--bg:#000}').dark, null);
|
|
510
|
+
assert.equal(readRootVars(':root{--bg:#fff}\n.dark-blue{--bg:#000}').dark, null);
|
|
511
|
+
assert.deepEqual(readRootVars(':root{--bg:#fff}\nDark mode:\n@media (prefers-color-scheme: dark){:root{--bg:#000}}').dark, { '--bg': '#000' });
|
|
512
|
+
// Review 5: `:not(.dark)` is the light look; a `/*` in prose is not a comment; a quote inside a value.
|
|
513
|
+
assert.deepEqual(readRootVars(':root:not(.dark){--bg:#fff}\n.dark{--bg:#000}'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
514
|
+
// Review 6: a comment after a brace or inside a selector is still a comment; nested :not() brackets.
|
|
515
|
+
assert.deepEqual(readRootVars('.dark { --bg: #000 } /* end .dark */\n:root { --bg: #fff }'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
516
|
+
assert.deepEqual(readRootVars(':root /* .dark lives below */ { --bg: #fff }\n.dark { --bg: #000 }'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
517
|
+
assert.deepEqual(readRootVars(':root:not(:is(.x), .dark){--bg:#fff}\n.dark{--bg:#000}'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
518
|
+
// Review 7: in a DESIGN.md with fences only their content is CSS, so no prose `/*` (or anything) can hide it.
|
|
519
|
+
const fenced = (prose) => readRootVars(`# Design\n\n${prose}\n\n\`\`\`css\n:root{--bg:#fff} /* light */\n.dark{--bg:#000}\n\`\`\`\n`);
|
|
520
|
+
for (const prose of ['Use the glob /*.css for all.', 'Files: /* everything', 'Run `rm dist /*`.', "It's {all} here: .dark { --bg: #f00 }"]) {
|
|
521
|
+
assert.deepEqual(fenced(prose), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } }, prose);
|
|
522
|
+
}
|
|
523
|
+
const both = { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } };
|
|
524
|
+
// Review 8: each fence is read on its own; a labelled non-CSS fence is never read; CSS outside fences still is.
|
|
525
|
+
assert.deepEqual(readRootVars('```bash\ncp a /* b "x\n```\n\n```css\n:root{--bg:#fff}\n.dark{--bg:#000}\n```'), both, 'a shell fence is never CSS beside a CSS one');
|
|
526
|
+
assert.deepEqual(readRootVars('```bash\ncp src/* dist/\n```\n\n```\n:root{--bg:#fff}\n.dark{--bg:#000}\n```'), both, 'nor beside an unlabelled one');
|
|
527
|
+
assert.deepEqual(readRootVars('Install:\n\n```bash\nnpm i\n```\n\n:root { --bg: #fff }\n.dark { --bg: #000 }\n'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } }, 'CSS outside the fences, beside a shell fence');
|
|
528
|
+
assert.deepEqual(readRootVars('Use ```css``` here.\n\n```css\n:root{--bg:#fff}\n.dark{--bg:#000}\n```'), both, 'a line with a backtick after the run is not a fence');
|
|
529
|
+
assert.deepEqual(readRootVars('````markdown\n```css\n:root{--bg:#123}\n```\n````\n\n```css\n:root{--bg:#fff}\n.dark{--bg:#000}\n```'), both, 'a fence inside a longer fence is its content, never the brand');
|
|
530
|
+
assert.deepEqual(readRootVars(':root { color-scheme: light dark; }\n:root{--bg:#fff}\n.dark{--bg:#000}'), both, 'a :root with no colours before the real one (review 9)');
|
|
531
|
+
assert.deepEqual(readRootVars('```css\r\n:root{--bg:#fff}\r\n.dark{--bg:#000}\r\n```\r\n'), both, 'Windows line ends');
|
|
532
|
+
assert.deepEqual(readRootVars(':root:NOT(.dark){--bg:#fff}\n.dark{--bg:#000}'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } }, ':not is not case-sensitive');
|
|
533
|
+
assert.equal(readRootVars(':root{--bg:#fff}\nhtml:not(.dark){--x:1}').dark, null);
|
|
534
|
+
assert.deepEqual(readRootVars(':root:not([data-theme="dark"]){--bg:#fff}\n[data-theme="dark"]{--bg:#000}'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
535
|
+
assert.deepEqual(readRootVars('Tokens live in `styles/*.css`.\n\n```css\n:root{--bg:#fff} /* x */\n:root.dark{--bg:#000}\n```'), { light: { '--bg': '#fff' }, dark: { '--bg': '#000' } });
|
|
536
|
+
assert.deepEqual(readRootVars("/* the team's tokens */\n:root{--font: 'Inter',\n sans-serif; --bg:#fff}").light, { '--font': "'Inter',\n sans-serif", '--bg': '#fff' });
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test('#553 review 2: primary is checked as link text in yad brand check, never in the doctor row; yadflow\'s own look passes', async () => {
|
|
540
|
+
const { brandChecks } = await import('./doctor.mjs');
|
|
541
|
+
assert.deepEqual(contrastProblems(YADFLOW_BRAND, { links: true }), [], 'yadflow\'s own look reads');
|
|
542
|
+
const { ws, root } = product();
|
|
543
|
+
try {
|
|
544
|
+
put(path.join(root, BRAND_FILE), { version: 1, name: 'Sky', colors: { light: { primary: '#0ea5e9' } } });
|
|
545
|
+
const r = await captured(() => runBrand(root, { action: 'check', json: true }));
|
|
546
|
+
assert.ok(r.contrast.some((x) => /primary \(links\)/.test(x)), r.contrast.join(' | '));
|
|
547
|
+
const checks = [];
|
|
548
|
+
brandChecks(root, checks);
|
|
549
|
+
assert.equal(checks.find((x) => x.id === 'brand').status, 'ok', 'a button colour never warns in doctor');
|
|
550
|
+
} finally { done(ws); }
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
test('#553 review 2: a dark primary is made lighter from rgb() too; one yadflow cannot read is yadflow\'s', async () => {
|
|
554
|
+
const { lighter } = await import('./brand.mjs');
|
|
555
|
+
assert.match(lighter('rgb(20 80 60)'), /^#[0-9a-f]{6}$/);
|
|
556
|
+
assert.equal(lighter('hsl(1 2% 3%)'), null);
|
|
557
|
+
assert.match(lighter('oklch(60% 0.2 250 / 50%)'), /^oklch\(0\.800 0\.2 250 \/ 50%\)$/);
|
|
558
|
+
});
|