From d3b7310cad6980f0b352488af41b93024f980bee Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 13:50:10 -0800 Subject: [PATCH 1/7] Renderer checks: touching, and three craft notes that advise rather than fail touching fails when two boxed values in a unit sit less than 1.5px apart or overlap. repeated-headers, chip-density and mixed-treatments report with a new advice status: projections check warns on them and the workbench shows them apart from failures. Calibrated on every built-in scenario. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- changelog.d/craft-checks.md | 5 + packages/cli/src/check/render.rs | 52 ++++++++-- .../src/fixtures/workbench/checks.tsx | 19 +++- .../renderers/harness/browser/craft.spec.ts | 65 +++++++++++++ packages/renderers/testing/README.md | 24 +++++ packages/renderers/testing/src/checks.ts | 2 +- .../renderers/testing/src/checks/catalog.ts | 15 +++ .../renderers/testing/src/checks/craft.ts | 97 +++++++++++++++++++ .../renderers/testing/src/checks/runner.ts | 7 +- packages/renderers/testing/src/index.ts | 2 +- packages/renderers/testing/src/measure.ts | 1 + .../renderers/testing/src/measure/craft.ts | 46 +++++++++ .../testing/src/measure/craft/boxes.ts | 93 ++++++++++++++++++ .../testing/src/measure/craft/lines.ts | 67 +++++++++++++ .../testing/src/measure/craft/shared.ts | 23 +++++ .../testing/src/measure/craft/tables.ts | 57 +++++++++++ packages/renderers/testing/src/probe.ts | 2 + packages/renderers/testing/src/types.ts | 36 ++++++- .../renderers/testing/test/helpers.test.mjs | 2 +- 19 files changed, 598 insertions(+), 17 deletions(-) create mode 100644 changelog.d/craft-checks.md create mode 100644 packages/renderers/harness/browser/craft.spec.ts create mode 100644 packages/renderers/testing/src/checks/craft.ts create mode 100644 packages/renderers/testing/src/measure/craft.ts create mode 100644 packages/renderers/testing/src/measure/craft/boxes.ts create mode 100644 packages/renderers/testing/src/measure/craft/lines.ts create mode 100644 packages/renderers/testing/src/measure/craft/shared.ts create mode 100644 packages/renderers/testing/src/measure/craft/tables.ts diff --git a/changelog.d/craft-checks.md b/changelog.d/craft-checks.md new file mode 100644 index 000000000..dddff8976 --- /dev/null +++ b/changelog.d/craft-checks.md @@ -0,0 +1,5 @@ +--- +section: renderer-authors +--- + +- **Four craft checks, three of them advisory**. `touching` fails when two boxed values in a unit (chips, pills or tags) sit less than 1.5 px apart or overlap. `repeated-headers`, `chip-density` and `mixed-treatments` report craft notes instead of failures: table cells that repeat both their row and column headings, a unit with more than six boxed values (or one for every 15 characters of text), and a line that adds a decorative color to code or bold. Their findings use the new `advice` status, which `projections check` reports as warnings and the workbench shows separately from failures. Checked across every built-in scenario, `touching` finds nothing and the advisory checks flag only the pills in `agentic-workflows`. See [the renderer checks](packages/renderers/testing/README.md#craft-notes). diff --git a/packages/cli/src/check/render.rs b/packages/cli/src/check/render.rs index 9935af045..13f2e7b3c 100644 --- a/packages/cli/src/check/render.rs +++ b/packages/cli/src/check/render.rs @@ -264,17 +264,42 @@ fn checks_step(titles: &HashMap, rerun: &Rerun<'_>, key: &str, c .map(move |detail| format!("{title}: {}", detail.as_str().unwrap_or_default())) }) .collect(); + // Advisory checks' findings are craft notes: they make the step a warning, never a failure. + let notes: Vec = all + .iter() + .filter(|check| check["status"] == "advice") + .flat_map(|check| { + let title = check["title"].as_str().unwrap_or_default().to_owned(); + check["details"] + .as_array() + .cloned() + .unwrap_or_default() + .into_iter() + .map(move |detail| format!("Craft note, {title}: {}", detail.as_str().unwrap_or_default())) + }) + .collect(); let passed = all.iter().filter(|check| check["status"] == "pass").count(); let skipped = all.iter().filter(|check| check["status"] == "skip").count(); + let advised = all.iter().filter(|check| check["status"] == "advice").count(); let scenario = titles.get(key).map_or("working tree", String::as_str); - let mut value = step( - "render", - &format!("Renderer checks, {scenario}"), - if failures.is_empty() { "pass" } else { "fail" }, - format!("{passed} passed, {} failed, {skipped} skipped", all.len() - passed - skipped), - ); + let status = if !failures.is_empty() { + "fail" + } else if advised > 0 { + "warn" + } else { + "pass" + }; + let failing = all.len() - passed - skipped - advised; + let summary = if advised > 0 { + format!("{passed} passed, {failing} failed, {skipped} skipped, {advised} with craft notes") + } else { + format!("{passed} passed, {failing} failed, {skipped} skipped") + }; + let mut value = step("render", &format!("Renderer checks, {scenario}"), status, summary); + if !failures.is_empty() || !notes.is_empty() { + value["details"] = json!([failures.as_slice(), notes.as_slice()].concat()); + } if !failures.is_empty() { - value["details"] = json!(failures); let failed: Vec<&str> = all .iter() .filter(|check| check["status"] == "fail") @@ -316,6 +341,19 @@ mod tests { ); let passed = checks_step(&HashMap::new(), &rerun, "check/head", json!([{"id": "palette", "status": "pass"}])); assert!(passed.get("rerun").is_none()); + // An advisory check's findings warn, as craft notes, and never fail the step. + let advised = checks_step( + &HashMap::new(), + &rerun, + "check/head", + json!([ + {"id": "palette", "title": "Colors", "status": "pass", "details": []}, + {"id": "chip-density", "title": "Chips used sparingly", "status": "advice", "details": ["dense"]}, + ]), + ); + assert_eq!(advised["status"], "warn"); + assert_eq!(advised["details"], json!(["Craft note, Chips used sparingly: dense"])); + assert!(advised.get("rerun").is_none()); // A scenarios.json scenario --scenario can't name apart reruns every scenario. assert_eq!( rerun.command("cards/head", &["palette"]), diff --git a/packages/host/inspector/src/fixtures/workbench/checks.tsx b/packages/host/inspector/src/fixtures/workbench/checks.tsx index afb3c8b76..4a8fcee5d 100644 --- a/packages/host/inspector/src/fixtures/workbench/checks.tsx +++ b/packages/host/inspector/src/fixtures/workbench/checks.tsx @@ -1,7 +1,7 @@ import {allChecks, checkDescriptions, checkTitles} from '@githubnext/projections-renderer-testing' import type {CheckId, CheckResult} from '@githubnext/projections-renderer-testing' import {cn} from '@githubnext/projections-host/ui/components' -import {CircleCheck, CircleDashed, CircleMinus, CircleX, LoaderCircle} from 'lucide-react' +import {CircleAlert, CircleCheck, CircleDashed, CircleMinus, CircleX, LoaderCircle} from 'lucide-react' /** A scenario's latest check run. */ export interface ScenarioChecks { @@ -24,6 +24,8 @@ export function StatusIcon({status, className}: {status: CheckResult['status'] | return case 'fail': return + case 'advice': + return case 'skip': return case 'running': @@ -54,7 +56,11 @@ export function ChecksList({checks, running}: {checks: ScenarioChecks | undefine {checkTitles[id]} {result && ( - {result.status === 'skip' ? 'skipped' : `${result.durationMs} ms`} + {result.status === 'skip' + ? 'skipped' + : result.status === 'advice' + ? `craft notes, ${result.durationMs} ms` + : `${result.durationMs} ms`} )}

@@ -81,7 +87,14 @@ export function ChecksList({checks, running}: {checks: ScenarioChecks | undefine ) } -const statusLabels = {pass: 'Passed', fail: 'Failed', skip: 'Skipped', running: 'Running', pending: 'Not run'} as const +const statusLabels = { + pass: 'Passed', + fail: 'Failed', + skip: 'Skipped', + advice: 'Craft notes', + running: 'Running', + pending: 'Not run', +} as const /** The Explorer's Checks section: each built-in check's status for the selected scenario. */ export function CheckResults({checks}: {checks: ScenarioChecks | undefined}) { diff --git a/packages/renderers/harness/browser/craft.spec.ts b/packages/renderers/harness/browser/craft.spec.ts new file mode 100644 index 000000000..0b2f828c1 --- /dev/null +++ b/packages/renderers/harness/browser/craft.spec.ts @@ -0,0 +1,65 @@ +import {expect, test} from '@playwright/test' +import {openStage} from '@githubnext/projections-renderer-testing/playwright' +import type {CraftReport} from '@githubnext/projections-renderer-testing' +import {harnessInspector} from '@githubnext/projections-renderer-harness/playwright' + +/** + * The craft probe behind `touching`, `repeated-headers`, `chip-density` and `mixed-treatments`: it counts boxed values + * (not change marks), finds boxes that touch, tables whose cells repeat both headings in their visible text, and lines + * that add a decorative color to another emphasis. + */ +test('the craft probe finds touching boxes, dense chips, repeated headings and mixed emphases, and only those', async ({page}, info) => { + test.skip(info.project.name !== 'chromium-desktop', 'One engine shows the probe works; the checks run in every one.') + const stage = await openStage(page, harnessInspector(), {scenario: 'graph/service-platform', progress: 1, comparisonMode: 'diff'}) + await stage.measure('settle') + const before = await stage.measure('craft') + expect(before.units.flatMap(unit => unit.touching)).toEqual([]) + expect(before.tables).toEqual([]) + await stage.frame.locator('body').evaluate(body => { + const fixture = document.createElement('div') + const pill = (text: string, style = '') => + `${text}` + fixture.innerHTML = ` +
+ ${pill('a', 'margin-right:0')}${pill('b')} + ${pill('c')} +
+
+ ${['one', 'two', 'three', 'four', 'five', 'six', 'seven'].map(text => pill(text, 'margin:4px')).join('')} +
+
+ ${['+a', '+b', '+c', '+d', '+e', '+f', '+g'].map(text => `${text}`).join('')} +
+
+

Build on os for label

+

Steps checkout@v5 and 8 run steps

+
+ + + + + + +
os × compilerTransparentBackground
windowswindows · Transparentwindows · Background
macosmacos · Transparentmacos · Background
+ + + + + + +
os × compilerTransparentBackground
windows●windows · Transparent●windows · Background
macos●macos · Transparent●macos · Background
` + fixture.style.cssText = 'position:absolute;top:0;left:0;z-index:10;background:#fff;font:13px sans-serif' + body.append(fixture) + }) + const report = await stage.measure('craft') + const unit = (name: string) => { + const found = report.units.find(item => item.unit.includes(name)) + if (!found) throw new Error(`No unit ${name}`) + return found + } + expect(unit('touching').touching).toHaveLength(1) + expect(unit('dense').boxes).toBe(7) + expect(unit('changes').boxes).toBe(0) + expect(unit('lines').mixed.map(line => line.line)).toEqual(['Build on os for label']) + expect(report.tables.map(table => table.table)).toEqual(['table.grid']) +}) diff --git a/packages/renderers/testing/README.md b/packages/renderers/testing/README.md index e75f06036..cededd64b 100644 --- a/packages/renderers/testing/README.md +++ b/packages/renderers/testing/README.md @@ -199,6 +199,30 @@ Build the bundle before the tests. The checks: `data-projections-route-crosses`, and this check reports it. Checked in the diff and at the end of the animation; skipped for a renderer that routes no links. +- `touching`: No two boxed values in a unit (chips, pills and tags: a box about + a line tall around text, with an edge on all four sides or a rounded fill) sit + less than 1.5 px apart or overlap. The two pills of a value change and word + highlights in a change hue may touch. Checked at full and phone width in the + diff (or the extraction). + +### Craft notes + +Three checks (`adviceChecks`) advise rather than fail. Their findings have +status `advice`: craft notes to review before showing a renderer to anyone. +`projections check` reports them as warnings, and the workbench shows them +separately from failures. They follow the visual craft rules in the authoring +guide, though a renderer may have good reason to break them. + +- `repeated-headers`: Table cells shouldn't repeat their headings. Reported when + a table has column headings and a heading cell on each row, and more than half + of its cells contain both their row and column heading. +- `chip-density`: Use chips sparingly. Reported when a unit has more than six + boxed values (excluding change marks), or at least four and one for every 15 + characters of its text. A selectable chip counts as half. +- `mixed-treatments`: One emphasis per line. Reported when a line adds a + decorative color (a hue other than a change or category color, such as the + accent) to code or bold, or uses all three. Muted text counts as plain, and + change marks and status words are excluded. The styling checks (`palette`, `type-scale`, `spacing`) measure the diff and, with a progress mode, progress 0.5, at full and phone width (`palette` in light diff --git a/packages/renderers/testing/src/checks.ts b/packages/renderers/testing/src/checks.ts index 6bb86b803..54f75b6fe 100644 --- a/packages/renderers/testing/src/checks.ts +++ b/packages/renderers/testing/src/checks.ts @@ -6,6 +6,6 @@ * panel; `checkScenario` from `@githubnext/projections/testing` * runs them in the same page from a test. */ -export {checkTitles, checkDescriptions, allChecks} from './checks/catalog.js' +export {adviceChecks, checkTitles, checkDescriptions, allChecks} from './checks/catalog.js' export type {CheckDriver, CheckOptions} from './checks/catalog.js' export {declaredModes, runChecks} from './checks/runner.js' diff --git a/packages/renderers/testing/src/checks/catalog.ts b/packages/renderers/testing/src/checks/catalog.ts index 0e75fb34d..4e038e16c 100644 --- a/packages/renderers/testing/src/checks/catalog.ts +++ b/packages/renderers/testing/src/checks/catalog.ts @@ -89,6 +89,10 @@ export const checkTitles: Record = { 'label-centring': 'Labels centred on their capitals', 'centred-pixels': 'Centred on whole pixels', 'link-routes': 'Links routed around cards', + touching: 'Nothing touches', + 'repeated-headers': "Cells don't repeat their headings", + 'chip-density': 'Chips used sparingly', + 'mixed-treatments': 'One emphasis per line', } /** Each built-in check's contract: what a renderer must do to pass it, in a sentence or two. */ @@ -151,7 +155,18 @@ export const checkDescriptions: Record = { "A painted box centred in a bar, chip or button (an icon, a pill, a mark) sits at equal, whole-pixel gaps either side: a half pixel either side, or a pixel more on one side, is drawn unevenly once snapped to device pixels. A box centres on whole pixels in whole, even room: the kit's `pk-label` gives a label a whole line box, and icons are even squares. Measured on every painted HTML box centred in its nearest painted ancestor at most 48px across that way (at equal gaps, or a pixel apart in a table cell), with at most 16px either side; a collapsed table rule counts half to each cell. Checked at full width in the diff (or the extraction).", 'link-routes': 'Every link a renderer routes between cards (marked data-projections-route) goes around the cards in its way. When no route around them exists, the renderer draws the one that overlaps them least and marks it data-projections-route="crossing", naming the cards in data-projections-route-crosses, and this check reports it. Checked at full width in the diff and at the end of the animation; skipped for a renderer that routes no links.', + touching: + "No two boxed values in a unit (chips, pills, tags: a box about a line tall around text, edged on all four sides or a rounded fill) face each other with less than 1.5px between them, or overlap. Keep the kit's spacing between chips. A pair of value-change pills and word highlights in a change's hue may abut. Checked at full width and at phone width in the diff (or the extraction).", + 'repeated-headers': + "Advice: a table's cells say what their headings don't. Reported when more than half of a table's cells (in a table with a row of column headings and a heading cell on each row) contain both their row's and their column's heading, as a matrix cell reading `windows-latest · TransparentCompiler` under and beside those headings does. Show a mark, or only what differs, instead.", + 'chip-density': + "Advice: chips are rare. Reported for a unit with more than six boxed values that aren't change marks, or with at least four and one for every 15 characters of its text; a selectable chip counts half. Show values, settings and versions as text (the kit's `Facts` and `ValueList`) and keep chips for a few items a reader picks out or selects.", + 'mixed-treatments': + "Advice: one emphasis per line. Reported for a line of a unit (text on one baseline in one block) that adds a decorative color (a hue that isn't a change's or a category's, such as the accent) to code or bold, or that uses all three of code, bold and color. Muted text is plain, and change marks and status words are left out. Pick one emphasis, and keep color for changes, focus and categories.", } +/** The checks that advise rather than fail: what they find is a craft note to look at (`CheckResult.status` `advice`). */ +export const adviceChecks: readonly CheckId[] = ['repeated-headers', 'chip-density', 'mixed-treatments'] + /** Every built-in check's ID, in the order `runChecks` runs them by default. */ export const allChecks = Object.keys(checkTitles) as CheckId[] diff --git a/packages/renderers/testing/src/checks/craft.ts b/packages/renderers/testing/src/checks/craft.ts new file mode 100644 index 000000000..56f4907c8 --- /dev/null +++ b/packages/renderers/testing/src/checks/craft.ts @@ -0,0 +1,97 @@ +// The craft checks: what a person sees at a glance (probe call `craft`). `touching` fails; the others advise +// (`adviceChecks`), since a renderer may have reason to break them. +import type {CraftReport, StageSubject} from '../types.js' +import type {CheckDriver} from './catalog.js' +import {limit, primaryMode, type Checks, type Settings} from './support.js' + +const unitName = (unit: string) => unit.replaceAll(/\[data-entity-id="[^"]*"\]/gu, '') + +/** The craft report at full width, and at phone width when asked, in the view a host opens (the diff, if any). */ +async function reports( + driver: CheckDriver, + subject: StageSubject, + {modes, phoneWidth}: Settings, + phone: boolean, +): Promise<{where: string; report: CraftReport}[]> { + const out: {where: string; report: CraftReport}[] = [] + const where = subject.mode === 'comparison' && primaryMode(subject, modes).comparisonMode === 'diff' ? 'In the diff' : 'At progress 1' + for (const width of phone ? [undefined, phoneWidth] : [undefined]) { + await driver.load(subject, {progress: 1, reuse: true, ...primaryMode(subject, modes), ...(width !== undefined ? {width} : {})}) + await driver.measure('settle') + out.push({where: width === undefined ? where : `${where} at ${width}px`, report: await driver.measure('craft')}) + } + return out +} + +/** Lines counted by kind, so one pattern repeated across many units reads once, with how many there were. */ +function lines(found: {key: string; line: string}[]): string[] { + const grouped = new Map() + for (const {key, line} of found) { + const seen = grouped.get(key) + if (seen) seen.count += 1 + else grouped.set(key, {line, count: 1}) + } + const out = [...grouped.values()].map(({line, count}) => (count > 1 ? `${line} (${count} like it)` : line)) + return out.length > limit ? [...out.slice(0, limit), `… and ${out.length - limit} more.`] : out +} + +export const craftChecks: Pick = { + async touching(driver, subject, settings) { + const found: {key: string; line: string}[] = [] + for (const {where, report} of await reports(driver, subject, settings, true)) { + for (const unit of report.units) { + for (const {a, b, gap} of unit.touching) { + const how = gap < 0 ? `overlap by ${-gap}px` : `are ${gap}px apart` + found.push({ + key: `${where}|${unitName(a)}|${unitName(b)}`, + line: `${where}, ${a} and ${b} in ${unit.unit} ${how}: keep at least the space scale's first step between boxed values (the kit's \`Chips\` does), or show them as text`, + }) + } + } + } + return lines(found) + }, + + async 'repeated-headers'(driver, subject, settings) { + const found: {key: string; line: string}[] = [] + for (const {where, report} of await reports(driver, subject, settings, false)) { + for (const {table, repeated, cells, example} of report.tables) { + found.push({ + key: `${where}|${unitName(table)}`, + line: `${where}, ${repeated} of ${cells} cells in ${table} repeat both their row's and their column's heading (such as "${example}"): show a mark, or only what the headings don't say`, + }) + } + } + return lines(found) + }, + + async 'chip-density'(driver, subject, settings) { + const found: {key: string; line: string}[] = [] + for (const {where, report} of await reports(driver, subject, settings, false)) { + for (const unit of report.units) { + const dense = unit.boxes > 6 || (unit.boxes >= 4 && unit.boxes * 15 > unit.text) + if (!dense) continue + found.push({ + key: `${where}|${unitName(unit.unit)}`, + line: `${where}, ${unit.unit} boxes ${unit.boxes} values in ${unit.text} characters of text (such as ${unit.examples.join(', ')}): show values and settings as text (the kit's \`Facts\` and \`ValueList\`), and keep chips for a few items a reader picks out or selects`, + }) + } + } + return lines(found) + }, + + async 'mixed-treatments'(driver, subject, settings) { + const found: {key: string; line: string}[] = [] + for (const {where, report} of await reports(driver, subject, settings, false)) { + for (const unit of report.units) { + for (const {line, treatments} of unit.mixed) { + found.push({ + key: `${where}|${unitName(unit.unit)}|${treatments.length}`, + line: `${where}, a line of ${unit.unit} ("${line}") is emphasized ${treatments.length} ways (${treatments.join(', ')}): give a line one emphasis, and keep color for changes, focus and categories`, + }) + } + } + } + return lines(found) + }, +} diff --git a/packages/renderers/testing/src/checks/runner.ts b/packages/renderers/testing/src/checks/runner.ts index 92e2db19a..3f215c40f 100644 --- a/packages/renderers/testing/src/checks/runner.ts +++ b/packages/renderers/testing/src/checks/runner.ts @@ -1,7 +1,7 @@ // Runs the checks against one subject. import type {ComparisonMode} from '@githubnext/projections-renderer-sdk/protocol' import type {CheckResult, StageState, StageSubject} from '../types.js' -import {checkTitles, allChecks, type CheckDriver, type CheckOptions} from './catalog.js' +import {adviceChecks, checkTitles, allChecks, type CheckDriver, type CheckOptions} from './catalog.js' import {Skip, Passed, progressModes, type Settings, type Checks} from './support.js' import {styleChecks} from './style.js' import {comparisonChecks} from './comparison.js' @@ -11,6 +11,7 @@ import {accentChecks} from './accents.js' import {dashChecks} from './dashes.js' import {edgeChecks} from './edges.js' import {labelChecks} from './labels.js' +import {craftChecks} from './craft.js' /** The comparison modes a renderer declared, in preference order (the SDK's default when it declares none). */ export function declaredModes(state: Pick): readonly ComparisonMode[] { @@ -27,6 +28,7 @@ const run: Checks = { ...dashChecks, ...edgeChecks, ...labelChecks, + ...craftChecks, } /** Runs the checks in order against one subject. A failure to load or measure fails that check, not the run. */ @@ -51,7 +53,8 @@ export async function runChecks(driver: CheckDriver, subject: StageSubject, opti let result: CheckResult try { const failures = await run[id](driver, subject, settings) - result = {id, title: checkTitles[id], status: failures.length ? 'fail' : 'pass', details: failures, durationMs: 0} + const found = adviceChecks.includes(id) ? 'advice' : 'fail' + result = {id, title: checkTitles[id], status: failures.length ? found : 'pass', details: failures, durationMs: 0} } catch (error) { result = error instanceof Passed diff --git a/packages/renderers/testing/src/index.ts b/packages/renderers/testing/src/index.ts index 27fee478d..a0f47e0f1 100644 --- a/packages/renderers/testing/src/index.ts +++ b/packages/renderers/testing/src/index.ts @@ -1,5 +1,5 @@ // Browser-safe entry: types, the built-in checks and the in-document measurements. -export {allChecks, checkDescriptions, checkTitles, declaredModes, runChecks} from './checks.js' +export {adviceChecks, allChecks, checkDescriptions, checkTitles, declaredModes, runChecks} from './checks.js' export type {CheckDriver, CheckOptions} from './checks.js' export { affordanceFailures, diff --git a/packages/renderers/testing/src/measure.ts b/packages/renderers/testing/src/measure.ts index d23e048f7..da346068a 100644 --- a/packages/renderers/testing/src/measure.ts +++ b/packages/renderers/testing/src/measure.ts @@ -23,3 +23,4 @@ export {offCentreLabels} from './measure/labels.js' export {offPixelChildren} from './measure/pixels.js' export {hiddenLines} from './measure/hidden-lines.js' export {linkRoutes} from './measure/routes.js' +export {craft} from './measure/craft.js' diff --git a/packages/renderers/testing/src/measure/craft.ts b/packages/renderers/testing/src/measure/craft.ts new file mode 100644 index 000000000..44b33d73a --- /dev/null +++ b/packages/renderers/testing/src/measure/craft.ts @@ -0,0 +1,46 @@ +// What a person sees at a glance in each unit: boxed values, boxes that touch, tables whose cells repeat their headings, +// and lines with more than one emphasis (probe call `craft`). The craft checks advise from it. +import type {CraftReport} from '../types.js' +import {familyHues} from './accents/hues.js' +import {describe} from './paint.js' +import {boxesIn, touching} from './craft/boxes.js' +import {mixedLines} from './craft/lines.js' +import {repeatedHeadings} from './craft/tables.js' +import {shown} from './craft/shared.js' + +const unitSelector = '[data-projections-unit], [data-entity-id]' + +/** The text a unit shows, outside nested units, `sr-only` text and SVG. */ +function textLength(unit: Element): number { + let length = 0 + const walker = document.createTreeWalker(unit, NodeFilter.SHOW_TEXT) + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const parent = node.parentElement + if (!parent || parent.closest('svg') || !shown(parent)) continue + length += node.textContent?.trim().length ?? 0 + } + return length +} + +/** Each top-level unit's craft measurements, outermost units only, and the document's tables that repeat their headings. */ +export function craft(root: Element = document.body): CraftReport { + const units = [...root.querySelectorAll(unitSelector)].filter(unit => !unit.parentElement?.closest(unitSelector) && shown(unit)) + const hues = familyHues() + return { + units: units.map(unit => { + const boxes = boxesIn(unit, hues) + return { + unit: describe(unit), + text: textLength(unit), + boxes: boxes.filter(box => !box.changed).reduce((sum, box) => sum + (box.selectable ? 0.5 : 1), 0), + examples: boxes + .filter(box => !box.changed) + .slice(0, 3) + .map(box => describe(box.element)), + touching: touching(boxes), + mixed: mixedLines(unit, hues), + } + }), + tables: repeatedHeadings(root), + } +} diff --git a/packages/renderers/testing/src/measure/craft/boxes.ts b/packages/renderers/testing/src/measure/craft/boxes.ts new file mode 100644 index 000000000..15f9fc5df --- /dev/null +++ b/packages/renderers/testing/src/measure/craft/boxes.ts @@ -0,0 +1,93 @@ +// Boxed values in a unit (chips, pills, tags) and the ones that touch (probe call `craft`). +import {familyOf, type familyHues} from '../accents/hues.js' +import {colorAlpha, describe, px} from '../paint.js' +import {changeMark, shown} from './shared.js' + +/** Closer than this, in CSS px, two boxes touch. */ +const touchingGap = 1.5 +/** Box sides must overlap by more than this, in CSS px, to face each other. */ +const facing = 4 +/** What isn't a value box although it may look like one: status words, badges, table cells, controls, icons. */ +const notAValue = '.pk-status-tab, .pk-status-part, .badge, td, th, input, select, textarea, svg, [role="status"]' + +/** Whether a hue family is a change's: not the accent, and not a neutral. */ +const changeHue = (family: string | undefined) => family !== undefined && family !== 'accent' + +/** Whether an element draws a frame of its own around text: an edge on all four sides, or a rounded fill unlike its parent's. */ +function frameOf(element: HTMLElement, style: CSSStyleDeclaration): 'bordered' | 'filled' | undefined { + const sides = ['top', 'right', 'bottom', 'left'] as const + const edged = sides.every( + side => + px(style.getPropertyValue(`border-${side}-width`)) > 0 && + style.getPropertyValue(`border-${side}-style`) !== 'none' && + colorAlpha(style.getPropertyValue(`border-${side}-color`)) > 0.01, + ) + if (edged) return 'bordered' + if (colorAlpha(style.backgroundColor) > 0.01 && px(style.borderTopLeftRadius) > 0) { + const parent = element.parentElement + const behind = parent ? getComputedStyle(parent).backgroundColor : '' + if (style.backgroundColor !== behind) return 'filled' + } + return undefined +} + +export interface Box { + element: HTMLElement + frame: 'bordered' | 'filled' + rect: DOMRect + changed: boolean + selectable: boolean +} + +/** The outermost small boxes around text in a unit: chips, pills, tags. */ +export function boxesIn(unit: Element, hues: ReturnType): Box[] { + const width = unit.getBoundingClientRect().width + const found: Box[] = [] + for (const element of unit.querySelectorAll('*')) { + if (!(element instanceof HTMLElement) || element.closest(notAValue)) continue + if (found.some(box => box.element.contains(element))) continue + if (!element.textContent.trim() || !shown(element)) continue + const style = getComputedStyle(element) + const rect = element.getBoundingClientRect() + // A pill is about a line tall (a line and its padding) and narrower than the unit; a row or a panel is neither. + if (rect.height > px(style.fontSize) * 2.6 || rect.width >= width * 0.9) continue + const frame = frameOf(element, style) + if (!frame) continue + found.push({ + element, + frame, + rect, + // A change mark of its own (a changed chip, a value change's pill, a word highlight), not a box inside a changed card. + changed: + element.matches(changeMark) || + !!element.querySelector(changeMark) || + !!element.parentElement?.closest('.pk-value-change') || + // A word highlight filled in a change's hue, drawn without its attribute. + (frame === 'filled' && changeHue(familyOf(style.backgroundColor, hues))), + selectable: element.matches('button, a, [tabindex]'), + }) + } + return found +} + +/** Pairs of boxes that face each other with less than a hairline between them, or overlap. */ +export function touching(boxes: readonly Box[]): {a: string; b: string; gap: number}[] { + const pairs: {a: string; b: string; gap: number}[] = [] + // A pair of pills inside one value change sits apart by design; filled change marks are word highlights that may abut. + const candidates = boxes.filter(box => box.frame === 'bordered' || !box.changed) + for (const [i, first] of candidates.entries()) { + for (const second of candidates.slice(i + 1)) { + const a = first.rect + const b = second.rect + const across = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top) + const along = Math.min(a.right, b.right) - Math.max(a.left, b.left) + const sideways = Math.max(a.left, b.left) - Math.min(a.right, b.right) + const upright = Math.max(a.top, b.top) - Math.min(a.bottom, b.bottom) + const gap = across > facing ? sideways : along > facing ? upright : Number.POSITIVE_INFINITY + if (gap < touchingGap) { + pairs.push({a: describe(first.element), b: describe(second.element), gap: Math.round(gap * 10) / 10}) + } + } + } + return pairs +} diff --git a/packages/renderers/testing/src/measure/craft/lines.ts b/packages/renderers/testing/src/measure/craft/lines.ts new file mode 100644 index 000000000..6c29260c3 --- /dev/null +++ b/packages/renderers/testing/src/measure/craft/lines.ts @@ -0,0 +1,67 @@ +// Lines that add a decorative color to another emphasis (probe call `craft`). +import {familyOf, type familyHues} from '../accents/hues.js' +import {describe} from '../paint.js' +import {changeMark, shown} from './shared.js' + +/** The nearest ancestor that lays text out in lines of its own: not an inline box. */ +function lineContainer(element: Element): Element { + for (let node: Element | null = element; node; node = node.parentElement) { + const display = getComputedStyle(node).display + if (!display.startsWith('inline') && display !== 'contents') return node + } + return element +} + +const monospace = /mono|menlo|consol|courier/iu + +/** + * Lines in a unit that add a decorative color to another emphasis, or use all three: a line's emphases are code (the + * monospace font), bold, and a color that is a hue but not a change's (an accent, say) or a category's. Muted and subtle + * text are plain: quieter, not emphasized. Lines are text runs on one baseline within one block; change marks within a + * line and status words are left out. + */ +export function mixedLines(unit: Element, hues: ReturnType): {line: string; treatments: string[]}[] { + const lines = new Map}>() + const walker = document.createTreeWalker(unit, NodeFilter.SHOW_TEXT) + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const parent = node.parentElement + const text = node.textContent?.trim() + if (!parent || !text || parent.closest('svg') || parent.closest('.pk-status-part, .pk-status-tab')) continue + if (!shown(parent)) continue + const container = lineContainer(parent) + // A change mark within the line is drawn to stand out; one around the whole line (a changed card, a row) isn't. + const mark = parent.closest(changeMark) + if (mark && mark !== container && container.contains(mark)) continue + const style = getComputedStyle(parent) + const family = familyOf(style.color, hues) + // Text in a change's hue is a change mark drawn without its attribute; a category's color is the palette's. + if (family !== undefined && family !== 'accent') continue + const categorical = !!parent.closest('[data-projections-category]') + const emphases = [ + ...(monospace.test(style.fontFamily) ? ['code'] : []), + ...(Number(style.fontWeight) >= 600 ? ['bold'] : []), + ...(!categorical && (family === 'accent' || huedText(style.color)) ? ['color'] : []), + ] + const range = document.createRange() + range.selectNodeContents(node) + for (const rect of range.getClientRects()) { + if (rect.width <= 0) continue + const key = `${describe(container)}|${Math.round((rect.top + rect.bottom) / 4)}` + const line = lines.get(key) ?? {texts: [], emphases: new Set()} + line.texts.push(text) + for (const emphasis of emphases) line.emphases.add(emphasis) + lines.set(key, line) + } + } + return [...lines.values()] + .filter(line => (line.emphases.has('color') && line.emphases.size >= 2) || line.emphases.size >= 3) + .map(line => ({line: line.texts.join(' ').slice(0, 80), treatments: [...line.emphases]})) +} + +/** Whether a computed color (`rgb()`, or `color(srgb …)` from 0 to 1) is a hue rather than a neutral. */ +function huedText(color: string): boolean { + const scale = color.startsWith('color(') ? 255 : 1 + const values = (color.match(/[\d.]+/gu) ?? []).map(Number).filter(value => !Number.isNaN(value)) + const [r = 0, g = 0, b = 0] = values.map(value => value * scale) + return Math.max(r, g, b) - Math.min(r, g, b) >= 24 +} diff --git a/packages/renderers/testing/src/measure/craft/shared.ts b/packages/renderers/testing/src/measure/craft/shared.ts new file mode 100644 index 000000000..9335ac120 --- /dev/null +++ b/packages/renderers/testing/src/measure/craft/shared.ts @@ -0,0 +1,23 @@ +// What the craft probes share: what counts as shown, and the marks drawn to stand out. +import {effectiveOpacity, visuallyHidden} from '../paint.js' + +/** A change mark: drawn to stand out, so never counted as a box a reader must look past. */ +export const changeMark = '[data-change], [data-change-hue], .pk-value-change' + +export function shown(element: Element): boolean { + const box = element.getBoundingClientRect() + if (box.width <= 0 || box.height <= 0) return false + const style = getComputedStyle(element) + return style.visibility !== 'hidden' && effectiveOpacity(element) > 0.01 && !visuallyHidden(element, style) +} + +/** The text an element shows: not what only assistive technology hears (`sr-only`), nor a `title`. */ +export function textOf(element: Element): string { + let text = '' + const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT) + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const parent = node.parentElement + if (parent && shown(parent)) text += ` ${node.textContent ?? ''}` + } + return text.replaceAll(/\s+/gu, ' ').trim() +} diff --git a/packages/renderers/testing/src/measure/craft/tables.ts b/packages/renderers/testing/src/measure/craft/tables.ts new file mode 100644 index 000000000..51d72bd89 --- /dev/null +++ b/packages/renderers/testing/src/measure/craft/tables.ts @@ -0,0 +1,57 @@ +// Tables whose cells repeat both their headings (probe call `craft`). +import {describe} from '../paint.js' +import {shown, textOf} from './shared.js' + +const cellSelector = 'td, th, [role="cell"], [role="gridcell"], [role="columnheader"], [role="rowheader"]' +const cellsOf = (row: Element) => [...row.children].filter(cell => cell.matches(cellSelector)) +const spans = (cell: Element) => cell instanceof HTMLTableCellElement && (cell.colSpan > 1 || cell.rowSpan > 1) + +/** How many of a row's cells hold text, and how many of those repeat both their row's and their column's heading. */ +function rowRepeats(row: Element, columns: readonly string[]): {cells: number; repeated: number; example: string} { + const result = {cells: 0, repeated: 0, example: ''} + const cells = cellsOf(row) + const heading = cells.find(cell => cell.matches('th, [role="rowheader"]')) + if (!heading) return result + const rowText = textOf(heading) + if (rowText.length < 2) return result + for (const [index, cell] of cells.entries()) { + const text = textOf(cell) + const column = columns[index] ?? '' + if (cell === heading || !text || column.length < 2) continue + result.cells += 1 + if (text.includes(rowText) && text.includes(column)) { + result.repeated += 1 + result.example ||= text + } + } + return result +} + +/** + * Tables in a unit (or the document) whose cells mostly repeat both their row's and their column's heading in the text + * they show: a cell under "TransparentCompiler" beside "windows-latest" reading "windows-latest · TransparentCompiler" + * says nothing its headings don't. + */ +export function repeatedHeadings(root: Element): {table: string; repeated: number; cells: number; example: string}[] { + const found: {table: string; repeated: number; cells: number; example: string}[] = [] + for (const table of root.querySelectorAll('table, [role="grid"], [role="table"]')) { + if (!shown(table)) continue + const rows = [...table.querySelectorAll('tr, [role="row"]')].filter( + row => row.closest('table, [role="grid"], [role="table"]') === table, + ) + if (rows.some(row => cellsOf(row).some(spans))) continue + const header = rows.find(row => cellsOf(row).every(cell => cell.matches('th, [role="columnheader"]'))) + if (!header) continue + const columns = cellsOf(header).map(textOf) + const totals = rows + .filter(row => row !== header) + .map(row => rowRepeats(row, columns)) + .reduce((sum, row) => ({cells: sum.cells + row.cells, repeated: sum.repeated + row.repeated, example: sum.example || row.example}), { + cells: 0, + repeated: 0, + example: '', + }) + if (totals.cells >= 2 && totals.repeated * 2 > totals.cells) found.push({table: describe(table), ...totals}) + } + return found +} diff --git a/packages/renderers/testing/src/probe.ts b/packages/renderers/testing/src/probe.ts index 51f2fd768..2ebc4303d 100644 --- a/packages/renderers/testing/src/probe.ts +++ b/packages/renderers/testing/src/probe.ts @@ -20,6 +20,7 @@ import { entityTexts, identifierFonts, linkRoutes, + craft, entitySamples, hoveredEntities, horizontalOverflow, @@ -70,6 +71,7 @@ const calls: Record unknown> = { pixels: () => offPixelChildren(), lines: () => hiddenLines(), routes: () => linkRoutes(), + craft: () => craft(), } addEventListener('message', event => { diff --git a/packages/renderers/testing/src/types.ts b/packages/renderers/testing/src/types.ts index 0e09fccb9..b8c5de95d 100644 --- a/packages/renderers/testing/src/types.ts +++ b/packages/renderers/testing/src/types.ts @@ -155,6 +155,7 @@ export type ProbeCall = | 'pixels' | 'lines' | 'routes' + | 'craft' | 'viewport' /** An entity element as painted: its box, effective opacity, paint and visible text. */ @@ -411,6 +412,32 @@ export interface OverflowMeasurement { offenders: string[] } +/** How one unit reads at a glance (probe call `craft`), for the craft checks. */ +export interface CraftUnitMeasurement { + /** The unit (`describe`). */ + unit: string + /** How many characters of text it shows. */ + text: number + /** Its small boxes around text (chips, pills, tags) that aren't change marks; a selectable one counts half. */ + boxes: number + /** The first few of those boxes (`describe`). */ + examples: string[] + /** Pairs of its boxes that face each other with less than a hairline between them, with the gap in CSS px. */ + touching: {a: string; b: string; gap: number}[] + /** + * Its lines that add a decorative color (a hue that isn't a change's or a category's) to code or bold, or use all + * three, with the emphases each uses (`code`, `bold`, `color`); change marks are left out. + */ + mixed: {line: string; treatments: string[]}[] +} + +/** The craft measurements of a renderer document (probe call `craft`). */ +export interface CraftReport { + units: CraftUnitMeasurement[] + /** Tables whose cells mostly repeat both their row's and their column's heading. */ + tables: {table: string; repeated: number; cells: number; example: string}[] +} + /** A built-in renderer check, by ID; `checkTitles` and `checkDescriptions` describe each. */ export type CheckId = | 'neutral-endpoints' @@ -443,15 +470,20 @@ export type CheckId = | 'label-centring' | 'centred-pixels' | 'link-routes' + | 'touching' + | 'repeated-headers' + | 'chip-density' + | 'mixed-treatments' /** * One check's outcome (`runChecks`): `skip` when it doesn't apply to the subject or renderer, `fail` when it found a - * violation or couldn't load or measure, and how long it took in ms. + * violation or couldn't load or measure, `advice` when an advisory check (`adviceChecks`) found something to look at + * that doesn't fail the renderer, and how long it took in ms. */ export interface CheckResult { id: CheckId title: string - status: 'pass' | 'fail' | 'skip' + status: 'pass' | 'fail' | 'skip' | 'advice' /** Why it failed or was skipped, or what was checked. */ details: string[] durationMs: number diff --git a/packages/renderers/testing/test/helpers.test.mjs b/packages/renderers/testing/test/helpers.test.mjs index c8771c291..413b9ec5d 100644 --- a/packages/renderers/testing/test/helpers.test.mjs +++ b/packages/renderers/testing/test/helpers.test.mjs @@ -28,7 +28,7 @@ test('connectInspector builds page URLs on the workbench origin', () => { }) test('check failures are flattened with their titles; samples round trip', () => { - assert.equal(allChecks.length, 30) + assert.equal(allChecks.length, 34) const failures = checkFailures([ {id: 'legend', title: checkTitles.legend, status: 'fail', details: ['two legends'], durationMs: 1}, {id: 'selection', title: checkTitles.selection, status: 'pass', details: [], durationMs: 1}, From 76ce8869cb53b65beb6671aa04cae5a9fca4d693 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 14:25:56 -0800 Subject: [PATCH 2/7] Craft probe: chips in table cells count, a value change's pills may touch, lines group by their own block Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/renderers/harness/browser/craft.spec.ts | 12 ++++++++++++ .../renderers/testing/src/measure/craft/boxes.ts | 11 ++++++++--- .../renderers/testing/src/measure/craft/lines.ts | 13 ++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/renderers/harness/browser/craft.spec.ts b/packages/renderers/harness/browser/craft.spec.ts index 0b2f828c1..9697ef9da 100644 --- a/packages/renderers/harness/browser/craft.spec.ts +++ b/packages/renderers/harness/browser/craft.spec.ts @@ -34,6 +34,14 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m

Build on os for label

Steps checkout@v5 and 8 run steps

+
${pill('x', 'margin-right:0')}${pill('y')}
+
+ ${pill('old', 'margin-right:0')}${pill('new')} +
+
+

a.b

+

accent words

+
@@ -58,6 +66,10 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m return found } expect(unit('touching').touching).toHaveLength(1) + // Chips inside a table cell count; a value change's two pills may touch; two blocks alike in name are two lines. + expect(unit('in-cells').touching).toHaveLength(1) + expect(unit('value-change').touching).toEqual([]) + expect(unit('twins').mixed).toEqual([]) expect(unit('dense').boxes).toBe(7) expect(unit('changes').boxes).toBe(0) expect(unit('lines').mixed.map(line => line.line)).toEqual(['Build on os for label']) diff --git a/packages/renderers/testing/src/measure/craft/boxes.ts b/packages/renderers/testing/src/measure/craft/boxes.ts index 15f9fc5df..81120d6f9 100644 --- a/packages/renderers/testing/src/measure/craft/boxes.ts +++ b/packages/renderers/testing/src/measure/craft/boxes.ts @@ -7,8 +7,10 @@ import {changeMark, shown} from './shared.js' const touchingGap = 1.5 /** Box sides must overlap by more than this, in CSS px, to face each other. */ const facing = 4 -/** What isn't a value box although it may look like one: status words, badges, table cells, controls, icons. */ -const notAValue = '.pk-status-tab, .pk-status-part, .badge, td, th, input, select, textarea, svg, [role="status"]' +/** What isn't a value box although it may look like one: table cells and controls (what they hold still counts). */ +const notAValue = 'td, th, [role="cell"], [role="gridcell"], [role="columnheader"], [role="rowheader"], input, select, textarea' +/** What holds no value boxes: status words, badges and icons. */ +const noValues = '.pk-status-tab, .pk-status-part, .badge, svg, [role="status"]' /** Whether a hue family is a change's: not the accent, and not a neutral. */ const changeHue = (family: string | undefined) => family !== undefined && family !== 'accent' @@ -44,7 +46,7 @@ export function boxesIn(unit: Element, hues: ReturnType): Box const width = unit.getBoundingClientRect().width const found: Box[] = [] for (const element of unit.querySelectorAll('*')) { - if (!(element instanceof HTMLElement) || element.closest(notAValue)) continue + if (!(element instanceof HTMLElement) || element.matches(notAValue) || element.closest(noValues)) continue if (found.some(box => box.element.contains(element))) continue if (!element.textContent.trim() || !shown(element)) continue const style = getComputedStyle(element) @@ -83,6 +85,9 @@ export function touching(boxes: readonly Box[]): {a: string; b: string; gap: num const along = Math.min(a.right, b.right) - Math.max(a.left, b.left) const sideways = Math.max(a.left, b.left) - Math.min(a.right, b.right) const upright = Math.max(a.top, b.top) - Math.min(a.bottom, b.bottom) + // A value change's two pills stand together by design, though each is still checked against other boxes. + const change = first.element.closest('.pk-value-change') + if (change && change === second.element.closest('.pk-value-change')) continue const gap = across > facing ? sideways : along > facing ? upright : Number.POSITIVE_INFINITY if (gap < touchingGap) { pairs.push({a: describe(first.element), b: describe(second.element), gap: Math.round(gap * 10) / 10}) diff --git a/packages/renderers/testing/src/measure/craft/lines.ts b/packages/renderers/testing/src/measure/craft/lines.ts index 6c29260c3..a6544d7ff 100644 --- a/packages/renderers/testing/src/measure/craft/lines.ts +++ b/packages/renderers/testing/src/measure/craft/lines.ts @@ -1,6 +1,5 @@ // Lines that add a decorative color to another emphasis (probe call `craft`). import {familyOf, type familyHues} from '../accents/hues.js' -import {describe} from '../paint.js' import {changeMark, shown} from './shared.js' /** The nearest ancestor that lays text out in lines of its own: not an inline box. */ @@ -21,7 +20,8 @@ const monospace = /mono|menlo|consol|courier/iu * line and status words are left out. */ export function mixedLines(unit: Element, hues: ReturnType): {line: string; treatments: string[]}[] { - const lines = new Map}>() + // By the block that lays the line out, then by the line's middle: two blocks alike in name are still two blocks. + const lines = new Map}>>() const walker = document.createTreeWalker(unit, NodeFilter.SHOW_TEXT) for (let node = walker.nextNode(); node; node = walker.nextNode()) { const parent = node.parentElement @@ -46,14 +46,17 @@ export function mixedLines(unit: Element, hues: ReturnType): range.selectNodeContents(node) for (const rect of range.getClientRects()) { if (rect.width <= 0) continue - const key = `${describe(container)}|${Math.round((rect.top + rect.bottom) / 4)}` - const line = lines.get(key) ?? {texts: [], emphases: new Set()} + const block = lines.get(container) ?? new Map}>() + const middle = Math.round((rect.top + rect.bottom) / 4) + const line = block.get(middle) ?? {texts: [], emphases: new Set()} line.texts.push(text) for (const emphasis of emphases) line.emphases.add(emphasis) - lines.set(key, line) + block.set(middle, line) + lines.set(container, block) } } return [...lines.values()] + .flatMap(block => [...block.values()]) .filter(line => (line.emphases.has('color') && line.emphases.size >= 2) || line.emphases.size >= 3) .map(line => ({line: line.texts.join(' ').slice(0, 80), treatments: [...line.emphases]})) } From cc01829b7d45dbf765a72dbcb0e8ed31ad2508e0 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 14:42:52 -0800 Subject: [PATCH 3/7] Visual craft: projections check reports some of the checklist as craft notes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/agents/create-projection.md | 3 +++ packages/cli/templates/SKILL.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docs/agents/create-projection.md b/docs/agents/create-projection.md index 12970e3b7..e9cc51f78 100644 --- a/docs/agents/create-projection.md +++ b/docs/agents/create-projection.md @@ -787,6 +787,9 @@ width and in dark mode, and check: 7. In the diff, is change color only on what changed? Fix what fails, redraw and check again before showing the person. +`projections check` catches some of these: `touching` fails, and +`repeated-headers`, `chip-density` and `mixed-treatments` report craft notes +as warnings. Fix each note, or tell the person why you kept it. ### Comparator diff --git a/packages/cli/templates/SKILL.md b/packages/cli/templates/SKILL.md index c73eeb482..cee22ed97 100644 --- a/packages/cli/templates/SKILL.md +++ b/packages/cli/templates/SKILL.md @@ -751,6 +751,9 @@ width and in dark mode, and check: 7. In the diff, is change color only on what changed? Fix what fails, redraw and check again before showing the person. +`projections check` catches some of these: `touching` fails, and +`repeated-headers`, `chip-density` and `mixed-treatments` report craft notes +as warnings. Fix each note, or tell the person why you kept it. ## Comparator From 1f53d69d4937b01cd4eeab6c255f0b9315784f25 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 14:50:37 -0800 Subject: [PATCH 4/7] repeated-headers fails rather than advises: no built-in table repeats its headings Calibrated two more craft notes, prose-in-mono and small-emphasis, and left them out: on the built-ins they flagged code that reads like words and bold key markers and section labels drawn that way on purpose. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- changelog.d/craft-checks.md | 2 +- docs/agents/create-projection.md | 5 ++--- packages/cli/templates/SKILL.md | 5 ++--- packages/renderers/testing/README.md | 10 +++++----- packages/renderers/testing/src/checks/catalog.ts | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/changelog.d/craft-checks.md b/changelog.d/craft-checks.md index dddff8976..9362df344 100644 --- a/changelog.d/craft-checks.md +++ b/changelog.d/craft-checks.md @@ -2,4 +2,4 @@ section: renderer-authors --- -- **Four craft checks, three of them advisory**. `touching` fails when two boxed values in a unit (chips, pills or tags) sit less than 1.5 px apart or overlap. `repeated-headers`, `chip-density` and `mixed-treatments` report craft notes instead of failures: table cells that repeat both their row and column headings, a unit with more than six boxed values (or one for every 15 characters of text), and a line that adds a decorative color to code or bold. Their findings use the new `advice` status, which `projections check` reports as warnings and the workbench shows separately from failures. Checked across every built-in scenario, `touching` finds nothing and the advisory checks flag only the pills in `agentic-workflows`. See [the renderer checks](packages/renderers/testing/README.md#craft-notes). +- **Four craft checks, two of them advisory**. `touching` fails when two boxed values in a unit (chips, pills or tags) sit less than 1.5 px apart or overlap, and `repeated-headers` fails when most of a table's cells repeat both their row and column headings. `chip-density` and `mixed-treatments` report craft notes instead of failures: a unit with more than six boxed values (or one for every 15 characters of text), and a line that adds a decorative color to code or bold. Craft notes use the new `advice` status, which `projections check` reports as warnings and the workbench shows separately from failures. Across every built-in scenario, the two failing checks find nothing and the craft notes flag only the pills in `agentic-workflows`. See [the renderer checks](packages/renderers/testing/README.md#craft-notes). diff --git a/docs/agents/create-projection.md b/docs/agents/create-projection.md index e9cc51f78..3dea63e45 100644 --- a/docs/agents/create-projection.md +++ b/docs/agents/create-projection.md @@ -787,9 +787,8 @@ width and in dark mode, and check: 7. In the diff, is change color only on what changed? Fix what fails, redraw and check again before showing the person. -`projections check` catches some of these: `touching` fails, and -`repeated-headers`, `chip-density` and `mixed-treatments` report craft notes -as warnings. Fix each note, or tell the person why you kept it. +`projections check` catches some of these: `touching` and `repeated-headers` +fail, and `chip-density` and `mixed-treatments` report craft notes as warnings. Fix each note, or tell the person why you kept it. ### Comparator diff --git a/packages/cli/templates/SKILL.md b/packages/cli/templates/SKILL.md index cee22ed97..25efabe56 100644 --- a/packages/cli/templates/SKILL.md +++ b/packages/cli/templates/SKILL.md @@ -751,9 +751,8 @@ width and in dark mode, and check: 7. In the diff, is change color only on what changed? Fix what fails, redraw and check again before showing the person. -`projections check` catches some of these: `touching` fails, and -`repeated-headers`, `chip-density` and `mixed-treatments` report craft notes -as warnings. Fix each note, or tell the person why you kept it. +`projections check` catches some of these: `touching` and `repeated-headers` +fail, and `chip-density` and `mixed-treatments` report craft notes as warnings. Fix each note, or tell the person why you kept it. ## Comparator diff --git a/packages/renderers/testing/README.md b/packages/renderers/testing/README.md index cededd64b..83429e144 100644 --- a/packages/renderers/testing/README.md +++ b/packages/renderers/testing/README.md @@ -204,18 +204,18 @@ Build the bundle before the tests. The checks: less than 1.5 px apart or overlap. The two pills of a value change and word highlights in a change hue may touch. Checked at full and phone width in the diff (or the extraction). +- `repeated-headers`: Table cells shouldn't repeat their headings. Fails when a + table has column headings and a heading cell on each row, and more than half + of its cells contain both their row and column heading. ### Craft notes -Three checks (`adviceChecks`) advise rather than fail. Their findings have -status `advice`: craft notes to review before showing a renderer to anyone. +Two checks (`adviceChecks`) advise rather than fail. Their findings have status +`advice`: craft notes to review before showing a renderer to anyone. `projections check` reports them as warnings, and the workbench shows them separately from failures. They follow the visual craft rules in the authoring guide, though a renderer may have good reason to break them. -- `repeated-headers`: Table cells shouldn't repeat their headings. Reported when - a table has column headings and a heading cell on each row, and more than half - of its cells contain both their row and column heading. - `chip-density`: Use chips sparingly. Reported when a unit has more than six boxed values (excluding change marks), or at least four and one for every 15 characters of its text. A selectable chip counts as half. diff --git a/packages/renderers/testing/src/checks/catalog.ts b/packages/renderers/testing/src/checks/catalog.ts index 4e038e16c..fb41f2fc1 100644 --- a/packages/renderers/testing/src/checks/catalog.ts +++ b/packages/renderers/testing/src/checks/catalog.ts @@ -158,7 +158,7 @@ export const checkDescriptions: Record = { touching: "No two boxed values in a unit (chips, pills, tags: a box about a line tall around text, edged on all four sides or a rounded fill) face each other with less than 1.5px between them, or overlap. Keep the kit's spacing between chips. A pair of value-change pills and word highlights in a change's hue may abut. Checked at full width and at phone width in the diff (or the extraction).", 'repeated-headers': - "Advice: a table's cells say what their headings don't. Reported when more than half of a table's cells (in a table with a row of column headings and a heading cell on each row) contain both their row's and their column's heading, as a matrix cell reading `windows-latest · TransparentCompiler` under and beside those headings does. Show a mark, or only what differs, instead.", + "A table's cells say what their headings don't. Fails when more than half of a table's cells (in a table with a row of column headings and a heading cell on each row) contain both their row's and their column's heading, as a matrix cell reading `windows-latest · TransparentCompiler` under and beside those headings does. Show a mark, or only what differs, instead.", 'chip-density': "Advice: chips are rare. Reported for a unit with more than six boxed values that aren't change marks, or with at least four and one for every 15 characters of its text; a selectable chip counts half. Show values, settings and versions as text (the kit's `Facts` and `ValueList`) and keep chips for a few items a reader picks out or selects.", 'mixed-treatments': @@ -166,7 +166,7 @@ export const checkDescriptions: Record = { } /** The checks that advise rather than fail: what they find is a craft note to look at (`CheckResult.status` `advice`). */ -export const adviceChecks: readonly CheckId[] = ['repeated-headers', 'chip-density', 'mixed-treatments'] +export const adviceChecks: readonly CheckId[] = ['chip-density', 'mixed-treatments'] /** Every built-in check's ID, in the order `runChecks` runs them by default. */ export const allChecks = Object.keys(checkTitles) as CheckId[] From d222419306bf213e74ba97b52e96a94e60a85592 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 15:52:11 -0800 Subject: [PATCH 5/7] Craft probe: text inside an sr-only ancestor isn't shown, and empty cells count toward a table's repeated headings Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/renderers/harness/browser/craft.spec.ts | 14 ++++++++++++-- .../renderers/testing/src/measure/craft/shared.ts | 7 ++++++- .../renderers/testing/src/measure/craft/tables.ts | 8 ++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/renderers/harness/browser/craft.spec.ts b/packages/renderers/harness/browser/craft.spec.ts index 9697ef9da..586ef2cd3 100644 --- a/packages/renderers/harness/browser/craft.spec.ts +++ b/packages/renderers/harness/browser/craft.spec.ts @@ -52,8 +52,18 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m
os × compilerTransparentBackground
- - + + + +
os × compilerTransparentBackground
windows●windows · Transparent●windows · Background
macos●macos · Transparent●macos · Background
windows●windows · Transparent●windows · Background
macos●macos · Transparent●macos · Background
+ + + + + + + +
os × compilerTransparentBackground
windowswindows · Transparentwindows · Background
macos
ubuntu
alpine
freebsd
` fixture.style.cssText = 'position:absolute;top:0;left:0;z-index:10;background:#fff;font:13px sans-serif' diff --git a/packages/renderers/testing/src/measure/craft/shared.ts b/packages/renderers/testing/src/measure/craft/shared.ts index 9335ac120..d63756b58 100644 --- a/packages/renderers/testing/src/measure/craft/shared.ts +++ b/packages/renderers/testing/src/measure/craft/shared.ts @@ -4,11 +4,16 @@ import {effectiveOpacity, visuallyHidden} from '../paint.js' /** A change mark: drawn to stand out, so never counted as a box a reader must look past. */ export const changeMark = '[data-change], [data-change-hue], .pk-value-change' +/** Whether an element is painted: it has a box, isn't hidden or transparent, and neither it nor an ancestor is `sr-only`. */ export function shown(element: Element): boolean { const box = element.getBoundingClientRect() if (box.width <= 0 || box.height <= 0) return false const style = getComputedStyle(element) - return style.visibility !== 'hidden' && effectiveOpacity(element) > 0.01 && !visuallyHidden(element, style) + if (style.visibility === 'hidden' || effectiveOpacity(element) <= 0.01) return false + for (let node: Element | null = element; node; node = node.parentElement) { + if (visuallyHidden(node, node === element ? style : getComputedStyle(node))) return false + } + return true } /** The text an element shows: not what only assistive technology hears (`sr-only`), nor a `title`. */ diff --git a/packages/renderers/testing/src/measure/craft/tables.ts b/packages/renderers/testing/src/measure/craft/tables.ts index 51d72bd89..74017adbb 100644 --- a/packages/renderers/testing/src/measure/craft/tables.ts +++ b/packages/renderers/testing/src/measure/craft/tables.ts @@ -6,7 +6,7 @@ const cellSelector = 'td, th, [role="cell"], [role="gridcell"], [role="columnhea const cellsOf = (row: Element) => [...row.children].filter(cell => cell.matches(cellSelector)) const spans = (cell: Element) => cell instanceof HTMLTableCellElement && (cell.colSpan > 1 || cell.rowSpan > 1) -/** How many of a row's cells hold text, and how many of those repeat both their row's and their column's heading. */ +/** How many of a row's data cells are shown (empty or not), and how many repeat both their row's and column's heading. */ function rowRepeats(row: Element, columns: readonly string[]): {cells: number; repeated: number; example: string} { const result = {cells: 0, repeated: 0, example: ''} const cells = cellsOf(row) @@ -15,11 +15,11 @@ function rowRepeats(row: Element, columns: readonly string[]): {cells: number; r const rowText = textOf(heading) if (rowText.length < 2) return result for (const [index, cell] of cells.entries()) { - const text = textOf(cell) const column = columns[index] ?? '' - if (cell === heading || !text || column.length < 2) continue + if (cell === heading || column.length < 2 || !shown(cell)) continue result.cells += 1 - if (text.includes(rowText) && text.includes(column)) { + const text = textOf(cell) + if (text && text.includes(rowText) && text.includes(column)) { result.repeated += 1 result.example ||= text } From 9a75ae4214c8d74d0d61930eee5d68b29acd1437 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 16:48:29 -0800 Subject: [PATCH 6/7] Craft probe: a chip's own change marks it, text split by inline markup stays joined, and every shown cell counts Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../renderers/harness/browser/craft.spec.ts | 21 +++++++++++++++-- .../testing/src/measure/craft/shared.ts | 23 ++++++++++++++++--- .../testing/src/measure/craft/tables.ts | 9 ++++---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/packages/renderers/harness/browser/craft.spec.ts b/packages/renderers/harness/browser/craft.spec.ts index 586ef2cd3..b806ad895 100644 --- a/packages/renderers/harness/browser/craft.spec.ts +++ b/packages/renderers/harness/browser/craft.spec.ts @@ -30,7 +30,10 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m
${['+a', '+b', '+c', '+d', '+e', '+f', '+g'].map(text => `${text}`).join('')}
-
+
+ ${['+a', '+b', '+c', '+d', '+e', '+f', '+g'].map(text => `${text}`).join('')} +
+

Build on os for label

Steps checkout@v5 and 8 run steps

@@ -65,6 +68,19 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m alpine freebsd + + + + + + + +
os × compilerTransparentCompiler
windowswindows · TransparentCompiler
macosmacos · TransparentCompiler
+ + + + +
buildCompilerMode#%
windowswindows Compilerwindows Mode340
` fixture.style.cssText = 'position:absolute;top:0;left:0;z-index:10;background:#fff;font:13px sans-serif' body.append(fixture) @@ -82,6 +98,7 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m expect(unit('twins').mixed).toEqual([]) expect(unit('dense').boxes).toBe(7) expect(unit('changes').boxes).toBe(0) + expect(unit('chip-changes').boxes).toBe(0) expect(unit('lines').mixed.map(line => line.line)).toEqual(['Build on os for label']) - expect(report.tables.map(table => table.table)).toEqual(['table.grid']) + expect(report.tables.map(table => table.table)).toEqual(['table.grid', 'table.split']) }) diff --git a/packages/renderers/testing/src/measure/craft/shared.ts b/packages/renderers/testing/src/measure/craft/shared.ts index d63756b58..904d57acf 100644 --- a/packages/renderers/testing/src/measure/craft/shared.ts +++ b/packages/renderers/testing/src/measure/craft/shared.ts @@ -2,7 +2,7 @@ import {effectiveOpacity, visuallyHidden} from '../paint.js' /** A change mark: drawn to stand out, so never counted as a box a reader must look past. */ -export const changeMark = '[data-change], [data-change-hue], .pk-value-change' +export const changeMark = '[data-change], [data-chip-change], [data-change-hue], .pk-value-change' /** Whether an element is painted: it has a box, isn't hidden or transparent, and neither it nor an ancestor is `sr-only`. */ export function shown(element: Element): boolean { @@ -16,13 +16,30 @@ export function shown(element: Element): boolean { return true } -/** The text an element shows: not what only assistive technology hears (`sr-only`), nor a `title`. */ +/** The box a text node's line runs in: its nearest ancestor (within `root`) that isn't inline. */ +function containerOf(node: Node, root: Element): Element { + for (let element = node.parentElement; element && element !== root; element = element.parentElement) { + const {display} = getComputedStyle(element) + if (display !== 'inline' && display !== 'contents') return element + } + return root +} + +/** + * The text an element shows: not what only assistive technology hears (`sr-only`), nor a `title`. Text split by inline + * markup stays joined as painted (`TransparentCompiler`); separate boxes (blocks, cells, chips) are + * separate words. + */ export function textOf(element: Element): string { let text = '' + let last: Element | undefined const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT) for (let node = walker.nextNode(); node; node = walker.nextNode()) { const parent = node.parentElement - if (parent && shown(parent)) text += ` ${node.textContent ?? ''}` + if (!parent || !shown(parent)) continue + const container = containerOf(node, element) + text += `${last !== undefined && container !== last ? ' ' : ''}${node.textContent ?? ''}` + last = container } return text.replaceAll(/\s+/gu, ' ').trim() } diff --git a/packages/renderers/testing/src/measure/craft/tables.ts b/packages/renderers/testing/src/measure/craft/tables.ts index 74017adbb..5a71337c4 100644 --- a/packages/renderers/testing/src/measure/craft/tables.ts +++ b/packages/renderers/testing/src/measure/craft/tables.ts @@ -13,13 +13,14 @@ function rowRepeats(row: Element, columns: readonly string[]): {cells: number; r const heading = cells.find(cell => cell.matches('th, [role="rowheader"]')) if (!heading) return result const rowText = textOf(heading) - if (rowText.length < 2) return result for (const [index, cell] of cells.entries()) { - const column = columns[index] ?? '' - if (cell === heading || column.length < 2 || !shown(cell)) continue + if (cell === heading || !shown(cell)) continue result.cells += 1 + // A heading shorter than two characters ("#", "%") is in too many texts to say a cell repeats it. + const column = columns[index] ?? '' + if (rowText.length < 2 || column.length < 2) continue const text = textOf(cell) - if (text && text.includes(rowText) && text.includes(column)) { + if (text.includes(rowText) && text.includes(column)) { result.repeated += 1 result.example ||= text } From 3cb76c52dababf0548721a6322448e796dcd5da6 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 17:26:40 -0800 Subject: [PATCH 7/7] Craft probe: only word highlights may abut; a changed chip or pill is a box like any other Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/renderers/harness/browser/craft.spec.ts | 5 +++++ packages/renderers/testing/src/measure/craft/boxes.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/renderers/harness/browser/craft.spec.ts b/packages/renderers/harness/browser/craft.spec.ts index b806ad895..37ce7bd14 100644 --- a/packages/renderers/harness/browser/craft.spec.ts +++ b/packages/renderers/harness/browser/craft.spec.ts @@ -38,6 +38,9 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m

Steps checkout@v5 and 8 run steps

${pill('x', 'margin-right:0')}${pill('y')}
+
+ new${pill('old')} +
${pill('old', 'margin-right:0')}${pill('new')}
@@ -95,6 +98,8 @@ test('the craft probe finds touching boxes, dense chips, repeated headings and m // Chips inside a table cell count; a value change's two pills may touch; two blocks alike in name are two lines. expect(unit('in-cells').touching).toHaveLength(1) expect(unit('value-change').touching).toEqual([]) + // A changed chip filled in its hue is a box like any other: it may not touch an unrelated chip. + expect(unit('filled-change').touching).toHaveLength(1) expect(unit('twins').mixed).toEqual([]) expect(unit('dense').boxes).toBe(7) expect(unit('changes').boxes).toBe(0) diff --git a/packages/renderers/testing/src/measure/craft/boxes.ts b/packages/renderers/testing/src/measure/craft/boxes.ts index 81120d6f9..a9da9e2c0 100644 --- a/packages/renderers/testing/src/measure/craft/boxes.ts +++ b/packages/renderers/testing/src/measure/craft/boxes.ts @@ -38,6 +38,8 @@ export interface Box { frame: 'bordered' | 'filled' rect: DOMRect changed: boolean + /** A word highlight: a fill in a change's hue on words in running text, which may abut the next. */ + highlight: boolean selectable: boolean } @@ -55,6 +57,7 @@ export function boxesIn(unit: Element, hues: ReturnType): Box if (rect.height > px(style.fontSize) * 2.6 || rect.width >= width * 0.9) continue const frame = frameOf(element, style) if (!frame) continue + const hued = frame === 'filled' && changeHue(familyOf(style.backgroundColor, hues)) found.push({ element, frame, @@ -65,7 +68,8 @@ export function boxesIn(unit: Element, hues: ReturnType): Box !!element.querySelector(changeMark) || !!element.parentElement?.closest('.pk-value-change') || // A word highlight filled in a change's hue, drawn without its attribute. - (frame === 'filled' && changeHue(familyOf(style.backgroundColor, hues))), + hued, + highlight: hued && !element.matches('.pk-chip, [data-chip-change]') && !element.closest('.pk-value-change'), selectable: element.matches('button, a, [tabindex]'), }) } @@ -75,8 +79,8 @@ export function boxesIn(unit: Element, hues: ReturnType): Box /** Pairs of boxes that face each other with less than a hairline between them, or overlap. */ export function touching(boxes: readonly Box[]): {a: string; b: string; gap: number}[] { const pairs: {a: string; b: string; gap: number}[] = [] - // A pair of pills inside one value change sits apart by design; filled change marks are word highlights that may abut. - const candidates = boxes.filter(box => box.frame === 'bordered' || !box.changed) + // Word highlights may abut; changed chips and pills are boxes like any other. + const candidates = boxes.filter(box => !box.highlight) for (const [i, first] of candidates.entries()) { for (const second of candidates.slice(i + 1)) { const a = first.rect