From e8409356ba40c2737a10b36beedcedaa6da9aaa0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 19:43:29 +0000 Subject: [PATCH] Coded verify diagnostics (#201, verify half) verify returns diagnostics in validate's shape: the contract's codes, then one per rendered problem with its engine, subject {slide, el, id} or {slide, master, id}, evidence and fixes. PARITY_CODES reads the problem strings the browser pass already writes, so the in-page measuring code is unchanged; a static test pins every problems.push string to a code. verify --json prints them, results.json carries them and is now written after the aggregate errors, and the finalize receipt carries them on the verify stage. Closes #201 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CiXonXtVxd5FHk4XqMzY8f --- CHANGELOG.md | 1 + bin/finalize.mjs | 2 +- bin/verify.mjs | 47 ++++++++++++++++++++++-- docs/verify.md | 5 ++- llms.txt | 2 +- test/verify-codes.test.mjs | 75 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 test/verify-codes.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd0d86..3136781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- **Coded verify diagnostics (#201, verify half).** `verify` now returns `diagnostics` in the shape `validate` has: the contract's codes first, then one per rendered problem with its `engine`, a `subject` of `{slide, el, id}` (or `{slide, master, id}`), evidence and fixes. Eleven `parity/` codes cover overflow (`{need, have}`, `w: `), nowrap lines, line count, ink through text, a straddled container, text over text, an arrow in a fill, the canvas edge, occlusion and the counter's margin and drift, plus `parity/page-error`, `parity/crowding` (a warning), `ae/over-threshold` and `deck/network`. The codes are read from the problem strings the browser pass already writes, so the in-page measuring code is unchanged. `verify --json` prints them, `results.json` carries them (and is now written after the aggregate errors, so it holds those too), and the `finalize` receipt carries them on the verify stage. Gate: test/verify-codes.test.mjs (a static check that every problem string verify can push has a code, each code's subject and evidence, crowding, page errors, AE and the network, the receipt, and a live overflow read back through the API, `results.json` and `--json`). - **Two windows no longer lose an edit in the store.** When window B was typing as window A saved, B saved its words on top of A's model, but A's older save could reach localStorage after B's. Both windows looked right and the store held A's model without B's words, so a reload lost them. A CI probe caught this on Firefox in 12 of 180 runs under load and 0 of 60 alone. A window now watches the `storage` event: when the store holds a model it already built on, it writes its newer model back, and it writes the log back when entries are missing. This was the Firefox two-window failure on `main`. - **`validate --suggest`: the layouts and templates that fit a slide's content (#207).** `node bin/validate.mjs --suggest "three or four numbers with movement"` prints the top five of the 32 library layouts and 115 templates with kind, density and slot or fill keys. `lib/suggest.mjs` scores each by idf-weighted word overlap with its name, its `use` or `note`, and the SKILL.md routing table, which it reads at run time so the two cannot disagree. SKILL.md START HERE names it. Gate: test/suggest.test.mjs (every routing-table row finds its layout in the top three, a template is found by its note, unknown words still answer five, the CLI prints the ranking). - **JSON Schema for model.json and style.json (#203).** `schemas/model.schema.json` and `schemas/style.schema.json` (draft 2020-12) carry the structure and every enum the engine checks: formats, pages, densities, the 115 template ids, anims, arrows, heads, connector styles, plates, chart marks and the eight roles. `node schemas/build.mjs` writes both from the constants in code (`lib/chart.mjs` now exports `MARKS`), so an enum cannot drift. `bin/new.mjs` writes `$schema` as the model's first key, relative to the model, so editors complete and flag props; `create` strips it before hashing or embedding, so no local path reaches a deck and the deck id is unchanged. `validate` still owns fit, air, density and coverage. The package ships `schemas/`. Gate: test/schema.test.mjs (committed files equal the build output, every enum equals its constant, every example model and style kit passes, the `new.mjs` round trip, the package list). diff --git a/bin/finalize.mjs b/bin/finalize.mjs index 96d1583..9953008 100755 --- a/bin/finalize.mjs +++ b/bin/finalize.mjs @@ -57,7 +57,7 @@ export async function finalize(modelFile, {style = null, out, format, space, tit stage('verify', async () => { const r = await verifyFn(out, {out: verifyOut, strict: true, webkit, log: () => {}}); const noRender = (r.skipped || []).some(s => s.startsWith('layout parity')); - return {status: !r.ok ? 'fail' : noRender ? 'skipped' : 'pass', errors: r.errors, warnings: r.warnings, skipped: r.skipped}; + return {status: !r.ok ? 'fail' : noRender ? 'skipped' : 'pass', errors: r.errors, warnings: r.warnings, diagnostics: r.diagnostics, skipped: r.skipped}; }), ]; for (const run of stages) if (!await run()) break; diff --git a/bin/verify.mjs b/bin/verify.mjs index 08e35ec..2d908d5 100644 --- a/bin/verify.mjs +++ b/bin/verify.mjs @@ -7,7 +7,7 @@ // later-painted opaque row (occlusion — sampled with elementFromPoint; fails like every other parity shape), and the page // counter's box is the same on every slide that shows the footer (the corner is the counter's; a `hide` of the footer is exempt) // 3. AE pixel diff vs reference PNGs (ImageMagick `magick`/`compare`) only when --refs is given -// usage: node bin/verify.mjs deck.html [--refs dir] [--out dir] [--threshold 0.5] [--fuzz 2%] [--report model.report.json] [--fonts ] [--strict] [--webkit | --no-webkit] [--slides id,n,…] +// usage: node bin/verify.mjs deck.html [--refs dir] [--out dir] [--threshold 0.5] [--fuzz 2%] [--report model.report.json] [--fonts ] [--strict] [--webkit | --no-webkit] [--slides id,n,…] [--json] // parity runs in Chromium and, when installed, WebKit on every OS (per-engine results; --no-webkit skips it, --webkit is the // same as the default). WebKit shots go to /webkit/ // --report: the importer's drift report (default: model.report.json beside the deck) — masks where the mockup drew its chrome @@ -34,6 +34,43 @@ export const fontWarnings = deck => Object.entries(deck?.styles?.roles || {}).fl export const scopeOf = (deck, slides) => slides.map(u => { const n = slideNo(deck, '#' + String(u).trim()); if (!n) throw new Error(`no slide "${u}" — slides are 1-${deck.slides.length} or ${deck.slides.map((s, k) => s.id || `s${k + 1}`).join(', ')}`); return n; }).sort((a, b) => a - b).filter((n, k, a) => n !== a[k - 1]); +const num = (m, k) => +m[k]; +export const PARITY_CODES = [ + {re: /^overflows its box \((\d+)>(\d+)\)/, code: 'parity/overflow', evidence: m => ({need: num(m, 1), have: num(m, 2)}), fixes: ev => [`w: ${ev.need}`, "w: 'auto'", 'shorten the text']}, + {re: /^nowrap row renders (\d+) lines/, code: 'parity/nowrap-lines', evidence: m => ({lines: num(m, 1)}), fixes: () => ["w: 'auto'", 'widen w', 'shorten the text']}, + {re: /^source had (\d+) line\(s\), renders (\d+)/, code: 'parity/line-count', evidence: m => ({source: num(m, 1), rendered: num(m, 2)}), fixes: () => ['widen w', 'shorten the text']}, + {re: /^overlapped by (.+)/, code: 'parity/ink-through-text', evidence: m => ({by: m[1].split(',')}), fixes: () => ['move the stroke off the text', 'over: 1 for a deliberate overlay']}, + {re: /^straddles (.+)/, code: 'parity/straddles-container', evidence: m => ({by: m[1].split(',')}), fixes: () => ['move the text inside the box or clear of it']}, + {re: /^overlaps text (.+)/, code: 'parity/text-over-text', evidence: m => ({by: m[1].split(',')}), fixes: () => ['move one row styles.gap clear of the other']}, + {re: /^arrow lands inside ([^ ]+)/, code: 'parity/arrow-in-fill', evidence: m => ({on: m[1].split(',')}), fixes: () => ["to: '' so the engine stops the stroke on the box edge"]}, + {re: /^outside the canvas/, code: 'parity/outside-canvas', fixes: () => ['move the row inside the canvas', 'narrow w']}, + {re: /^under row (\S+) \((\w+)\)/, code: 'parity/occlusion', evidence: m => ({under: m[1], kind: m[2]}), fixes: () => ['reorder els so paint comes first', 'move the box']}, + {re: /^counter right edge/, code: 'parity/counter-margin', fixes: () => ['anchor the footer with right:, or drop its own y']}, + {re: /^counter box/, code: 'parity/counter-drift', fixes: () => ['drop the slide-local footer override']}, +]; +const subjectOfRow = (deck, slide, n) => { + const s = {slide}, m = /^m:(\d+)$/.exec(String(n)); + if (m) { const id = deck.master?.[+m[1]]?.id; return {...s, master: +m[1], ...(id ? {id} : {})}; } + if (!/^\d+$/.test(String(n))) return s; + const id = deck.slides?.[slide - 1]?.els?.[+n]?.id; return {...s, el: +n, ...(id ? {id} : {})}; +}; +export function diagnosticsOf(res, deck) { + const out = [...(res.contract?.diagnostics || [])]; + for (const e of res.errors) { + if (e === 'deck references the network') out.push({code: 'deck/network', severity: 'error', message: e, subject: {}, fixes: ['embed every image as a data: URI; use installed or system fonts']}); + else if (e.startsWith('page errors: ')) out.push({code: 'parity/page-error', severity: 'error', message: e, subject: {}, fixes: []}); + } + for (const [engine, list] of Object.entries(res.engines || {})) for (const q of list) { + for (const [rows, severity] of [[q.rows || [], 'error'], [q.crowding || [], 'warning']]) for (const o of rows) for (const p of o.problems) { + const c = severity === 'warning' ? {code: 'parity/crowding', fixes: () => []} : PARITY_CODES.find(x => x.re.test(p)) || {code: 'parity/unclassified', fixes: () => []}; + const evidence = c.evidence ? c.evidence(c.re.exec(p)) : undefined; + out.push({code: c.code, severity, engine, message: `slide ${q.slide} row ${o.n}: ${p}`, subject: subjectOfRow(deck, q.slide, o.n), ...(evidence ? {evidence} : {}), fixes: c.fixes(evidence || {})}); + } + } + for (const a of res.ae || []) if (a.pass === false) out.push({code: 'ae/over-threshold', severity: 'error', message: `slide ${a.slide} differs from its reference by ${a.pctNoChromeNoConflict ?? a.pct}%`, subject: {slide: a.slide}, evidence: {pct: a.pctNoChromeNoConflict ?? a.pct}, fixes: ['fix the layout, or replace the reference if the change is intended']}); + return out; +} + export async function verify(file, {refs = null, out = null, threshold = 0.5, fuzz = '2%', strict = false, report = null, fonts = null, webkit = 'auto', slides = null, log = console.log} = {}) { const html = fs.readFileSync(file, 'utf8'); const res = {file, contract: null, parity: [], engines: {}, ae: [], errors: [], warnings: [], skipped: []}; @@ -243,20 +280,22 @@ export async function verify(file, {refs = null, out = null, threshold = 0.5, fu q.rows.push({n: 'counter', text: `${q.slide} / ${N}`, problems: [`counter box (right ${q.counter.right}, top ${q.counter.top}, h ${q.counter.h}) differs from slide ${ref.slide} (right ${ref.counter.right}, top ${ref.counter.top}, h ${ref.counter.h}) — the corner is the counter's on every slide`]}); q.pass = false; } } if (pageErrors.length) res.errors.push('page errors: ' + pageErrors.join(' | ')); - fs.writeFileSync(path.join(out, 'results.json'), JSON.stringify(res, null, 1)); } if (res.parity.some(r => !r.pass)) res.errors.push('layout parity failed on ' + res.parity.filter(r => !r.pass).map(r => r.slide).join(',')); for (const [eng, q] of Object.entries(res.engines)) if (eng !== 'chromium' && q.some(r => !r.pass)) res.errors.push(`layout parity failed in ${eng} on ` + q.filter(r => !r.pass).map(r => r.slide).join(',')); if (res.ae.some(r => r.pass === false)) res.errors.push('AE over threshold on ' + res.ae.filter(r => r.pass === false).map(r => `${r.slide} (${r.pctNoChromeNoConflict ?? r.pct}% after masks)`).join(',')); res.ok = !res.errors.length; + res.diagnostics = diagnosticsOf(res, deck); + if (pw) fs.writeFileSync(path.join(out, 'results.json'), JSON.stringify(res, null, 1)); return res; } if (isMain(import.meta.url)) { const a = process.argv.slice(2), o = {}; let file = null; for (let k = 0; k < a.length; k++) if (a[k].startsWith('--')) o[a[k].slice(2)] = a[k + 1] && !a[k + 1].startsWith('--') ? a[++k] : true; else file = a[k]; - if (!file) { console.error('usage: node bin/verify.mjs deck.html [--refs dir] [--out dir] [--threshold 0.5] [--fuzz 2%] [--report model.report.json] [--fonts ] [--strict] [--webkit | --no-webkit] [--slides id,n,…]'); process.exit(2); } - const r = await verify(file, {slides: typeof o.slides === 'string' ? o.slides.split(',') : null, refs: o.refs, out: o.out, threshold: o.threshold ? +o.threshold : 0.5, fuzz: o.fuzz || '2%', strict: !!o.strict, report: o.report || null, fonts: o.fonts || null, webkit: o['no-webkit'] ? false : o.webkit ? true : 'auto'}).catch(e => { if (/^no slide /.test(e.message)) { console.error(e.message); process.exit(2); } throw e; }); + if (!file) { console.error('usage: node bin/verify.mjs deck.html [--refs dir] [--out dir] [--threshold 0.5] [--fuzz 2%] [--report model.report.json] [--fonts ] [--strict] [--webkit | --no-webkit] [--slides id,n,…] [--json]'); process.exit(2); } + const r = await verify(file, {slides: typeof o.slides === 'string' ? o.slides.split(',') : null, refs: o.refs, out: o.out, threshold: o.threshold ? +o.threshold : 0.5, fuzz: o.fuzz || '2%', strict: !!o.strict, report: o.report || null, fonts: o.fonts || null, webkit: o['no-webkit'] ? false : o.webkit ? true : 'auto', ...(o.json ? {log: () => {}} : {})}).catch(e => { if (/^no slide /.test(e.message)) { console.error(e.message); process.exit(2); } throw e; }); + if (o.json) { console.log(JSON.stringify({file, ok: r.ok, diagnostics: r.diagnostics}, null, 1)); process.exit(r.ok ? 0 : 1); } if (r.scope) console.log(`scope slides ${r.scope.join(',')} of ${r.contract ? modelOf(fs.readFileSync(file, 'utf8')).slides.length : '?'} — a repair pass; hand off on a full run`); for (const m of r.contract.errors) console.error('ERROR contract: ' + m); for (const m of r.contract.warnings) console.error('warning contract: ' + m); diff --git a/docs/verify.md b/docs/verify.md index 3bdf653..c1132e7 100644 --- a/docs/verify.md +++ b/docs/verify.md @@ -51,8 +51,11 @@ Every `validate` finding also lands in `diagnostics`, one per line of `errors` a | `logo/` | logo row props | `logo/plate` | | `assets/` | `deck.assets`, image sources, monograms, placeholders | `assets/monogram-known` | | `entity/` | `deck.entities` and the logo each named company needs | `entity/named-without-logo` | +| `deck/` (verify) | the deck reaches the network | `deck/network` | +| `parity/` (verify) | what rendered: overflow, nowrap lines, line count, ink through text, a straddled container, text over text, an arrow in a fill, the canvas edge, occlusion, the counter, page errors, crowding (a warning) | `parity/overflow` (evidence `{need, have}`) | +| `ae/` (verify) | the pixel diff against a reference | `ae/over-threshold` (evidence `{pct}`) | -`fixes` lists the usual repairs for the common codes (`fit/nowrap-width` gives `w: `, `w: 'auto'` and a shorter text) and is empty elsewhere. A code never changes once shipped; a new check takes a new code. +`fixes` lists the usual repairs for the common codes (`fit/nowrap-width` gives `w: `, `w: 'auto'` and a shorter text) and is empty elsewhere. `verify` returns the same shape as `diagnostics` and writes it into `results.json`: the contract's codes first, then one per rendered problem, each with its `engine` (`chromium` or `webkit`) and `subject` `{slide, el, id}` or `{slide, master, id}`. `node bin/verify.mjs deck.html --json` prints them, and the `finalize` receipt carries them on the verify stage. A code never changes once shipped; a new check takes a new code. `node bin/finalize.mjs --check deck.html` exits 0 only when the deck's receipt passed and its `deck.sha256` still matches the file; otherwise it prints `receipt is for …, file is …: rerun finalize` and exits 1. `verify` writes the same identity into `results.json` as `deck: {sha256, id, rev}`, so a rebuilt deck never inherits an older pass. `create` and `finalize` write the deck through a temp file and a rename, so a crash never leaves half a deck. ## One slide at a time diff --git a/llms.txt b/llms.txt index b84085b..2b2834f 100644 --- a/llms.txt +++ b/llms.txt @@ -35,7 +35,7 @@ PDF: the ⤓ button writes a true slide-sized PDF inside the file (foreignObject - bin/validate.mjs: pure-Node model contract validator (exit 1 on errors; --strict for warnings; --json prints coded diagnostics {code, severity, message, subject, evidence, fixes}, families in docs/verify.md); includes the gap gate — declared boxes owe neighbours styles.gap (4px), estimates warn with ~ - bin/create.mjs: model (+style) -> deck.html with format presets - bin/finalize.mjs: validate --strict (with the style) -> create (same style) -> verify --strict, stopping at the first failing stage; writes .finalize.json {engine, model, style, deck (path + sha256), stages [{stage, status pass|fail|skipped|not-run, errors, warnings, ms}], ok}; exit 0 only when every stage passed; --check deck.html exits 0 only when that receipt passed and still matches the file's sha256 -- bin/verify.mjs (--slides id,n scopes parity and AE to the named slides between repairs): self-containment + contract + layout parity (always) + AE vs refs (optional); writes results.json +- bin/verify.mjs (--slides id,n scopes parity and AE to the named slides between repairs; --json prints coded diagnostics, parity/ ae/ deck/ families, also in results.json): self-containment + contract + layout parity (always) + AE vs refs (optional); writes results.json - bin/pdf.mjs: deck.html -> vector PDF via Chromium print engine + px @page (one slide per page, text stays text, hrefs are /Link annotations, HUD hidden by the deck's @media print); gates pages/ratio/HUD/links, exit 1 on failure. The ONLY way an agent makes a PDF — never screenshots stitched by ImageMagick - bin/edits.mjs: prints the human edit log a deck file carries (read before revising) - bin/assets.mjs: decklet-assets CLI; lib/assets.mjs holds its pure half (slug, SVG bbox fit, plate detection, PNG decode, ranking, manifest) diff --git a/test/verify-codes.test.mjs b/test/verify-codes.test.mjs new file mode 100644 index 0000000..f2d22a0 --- /dev/null +++ b/test/verify-codes.test.mjs @@ -0,0 +1,75 @@ +import {test} from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import {spawnSync} from 'node:child_process'; +import {fileURLToPath} from 'node:url'; +import {diagnosticsOf, PARITY_CODES, verify} from '../bin/verify.mjs'; +import {create} from '../bin/create.mjs'; +import {finalize} from '../bin/finalize.mjs'; +import {raceOrExit} from './helpers/browser.mjs'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const src = fs.readFileSync(path.join(root, 'bin/verify.mjs'), 'utf8'); +let pw = null; try { pw = await import('playwright'); } catch {} +const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'decklet-vcodes-')); +const deck = {slides: [{id: 's1', els: [{id: 'hero'}, {id: 'card'}]}, {id: 's2', els: []}], master: [{id: 'foot'}]}; +const base = (over = {}) => ({errors: [], warnings: [], skipped: [], parity: [], engines: {}, ae: [], contract: {diagnostics: []}, ...over}); + +test('verify codes: every problem string verify.mjs can push matches a parity code (#201)', () => { + const sites = [...src.matchAll(/problems(?:\.push\(|: \[)\s*[`']([^`'$]{6,})/g)].map(m => m[1]); + assert.ok(sites.length >= 10, `found ${sites.length} problem strings`); + const lead = s => s.split(' ').slice(0, 2).join(' '); + for (const s of sites) assert.ok(PARITY_CODES.some(c => c.re.source.replace(/\\/g, '').startsWith('^' + lead(s))), `no code matches "${s}"`); +}); + +test('verify codes: each parity problem becomes one coded diagnostic with slide, row, id, engine and evidence (#201)', () => { + const row = (n, ...problems) => ({n, text: 'Revenue grew', problems}); + const q = {slide: 1, name: 'cover', pass: false, crowding: [], rows: [ + row('0', 'overflows its box (412>388)', 'nowrap row renders 2 lines'), + row('1', 'overlapped by 3', 'straddles 4', 'overlaps text 0', 'under row 5 (img)'), + row('m:0', 'outside the canvas'), + row('counter', 'counter right edge 880 is not on the margin (900 = w − styles.margin)'), + ]}; + const d = diagnosticsOf(base({parity: [q], engines: {chromium: [q], webkit: [{...q, rows: [row('0', 'arrow lands inside 2 — terminate it with to:/from:')]}]}}), deck); + const codes = d.map(x => `${x.engine}:${x.code}`); + assert.deepEqual(codes, ['chromium:parity/overflow', 'chromium:parity/nowrap-lines', 'chromium:parity/ink-through-text', 'chromium:parity/straddles-container', + 'chromium:parity/text-over-text', 'chromium:parity/occlusion', 'chromium:parity/outside-canvas', 'chromium:parity/counter-margin', 'webkit:parity/arrow-in-fill']); + assert.deepEqual(d[0].subject, {slide: 1, el: 0, id: 'hero'}); + assert.deepEqual(d[0].evidence, {need: 412, have: 388}); + assert.deepEqual(d[0].fixes, ['w: 412', "w: 'auto'", 'shorten the text']); + assert.deepEqual(d[6].subject, {slide: 1, master: 0, id: 'foot'}); + assert.deepEqual(d[7].subject, {slide: 1}); + assert.ok(d.every(x => x.severity === 'error')); +}); + +test('verify codes: crowding warns, page errors, AE and the network fail, and the contract carries validate\'s codes (#201)', () => { + const q = {slide: 2, name: 'x', pass: true, rows: [], crowding: [{n: '0', text: 't', snapped: 1, problems: ['source had 3 line(s), renders 2']}]}; + const d = diagnosticsOf(base({parity: [q], engines: {chromium: [q]}, ae: [{slide: 2, name: 'x', pass: false, pctNoChromeNoConflict: 1.2}], + errors: ['deck references the network', 'page errors: boom'], contract: {diagnostics: [{code: 'fit/nowrap-width', severity: 'warning', message: 'm', subject: {slide: 1}, fixes: []}]}}), deck); + assert.deepEqual(d.map(x => [x.code, x.severity]), [['fit/nowrap-width', 'warning'], ['deck/network', 'error'], ['parity/page-error', 'error'], ['parity/crowding', 'warning'], ['ae/over-threshold', 'error']]); + assert.deepEqual(d[4].evidence, {pct: 1.2}); +}); + +test('live: a real overflow comes back as parity/overflow on its row, in the API, results.json and verify --json (#201)', {skip: !pw && 'Playwright not installed'}, async () => { + const f = path.join(tmp, 'overflow.html'), out = path.join(tmp, 'v'); + const model = {format: 'slides', density: 'speaker', title: 'codes', slides: [{textOnly: true, els: [{id: 'tight', x: 60, y: 200, w: 90, h: 24, role: 'Body', nowrap: 1, css: 'overflow:hidden', text: 'A sentence far too long for ninety pixels'}]}]}; + fs.writeFileSync(f, create(model, {}).html); + const r = await raceOrExit(verify(f, {out, webkit: false, log: () => {}}), 60000, 'verify codes'); + const hit = r.diagnostics.find(x => x.code === 'parity/overflow' || x.code === 'parity/nowrap-lines'); + assert.ok(hit, JSON.stringify(r.diagnostics.map(x => x.code))); + assert.equal(hit.subject.id, 'tight'); + assert.deepEqual(JSON.parse(fs.readFileSync(path.join(out, 'results.json'), 'utf8')).diagnostics, r.diagnostics); + const cli = spawnSync(process.execPath, [path.join(root, 'bin/verify.mjs'), f, '--no-webkit', '--out', path.join(tmp, 'v2'), '--json'], {encoding: 'utf8'}); + assert.equal(cli.status, 1); + assert.ok(JSON.parse(cli.stdout).diagnostics.some(x => x.subject.id === 'tight')); +}); + +test('verify codes: the finalize receipt carries verify\'s diagnostics on the verify stage (#201)', async () => { + const m = path.join(tmp, 'fin.json'); + fs.writeFileSync(m, JSON.stringify({format: 'slides', density: 'speaker', title: 'fin', slides: [{textOnly: true, els: [{x: 60, y: 200, w: 600, role: 'H1', text: 'Fine'}]}]})); + const coded = {code: 'parity/overflow', severity: 'error', message: 'x', subject: {slide: 1, el: 0}, fixes: []}; + const r = await finalize(m, {out: path.join(tmp, 'fin.html'), verifyFn: async () => ({ok: false, errors: ['layout parity failed on 1'], warnings: [], skipped: [], parity: [], diagnostics: [coded]}), log: () => {}}); + assert.deepEqual(r.stages[2].diagnostics, [coded]); +});