Skip to content
Merged
5 changes: 5 additions & 0 deletions changelog.d/craft-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
section: renderer-authors
---

- **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).
2 changes: 2 additions & 0 deletions docs/agents/create-projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +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` 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

Expand Down
52 changes: 45 additions & 7 deletions packages/cli/src/check/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,42 @@ fn checks_step(titles: &HashMap<String, String>, 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<String> = 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")
Expand Down Expand Up @@ -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"]),
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/templates/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +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` 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

Expand Down
19 changes: 16 additions & 3 deletions packages/host/inspector/src/fixtures/workbench/checks.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -24,6 +24,8 @@ export function StatusIcon({status, className}: {status: CheckResult['status'] |
return <CircleCheck aria-label="Passed" className={cn(shared, 'pj:text-added')} />
case 'fail':
return <CircleX aria-label="Failed" className={cn(shared, 'pj:text-destructive')} />
case 'advice':
return <CircleAlert aria-label="Craft notes" className={cn(shared, 'pj:text-modified')} />
case 'skip':
return <CircleMinus aria-label="Skipped" className={cn(shared, 'pj:text-muted-foreground')} />
case 'running':
Expand Down Expand Up @@ -54,7 +56,11 @@ export function ChecksList({checks, running}: {checks: ScenarioChecks | undefine
{checkTitles[id]}
{result && (
<span className="pj:text-[11px] pj:font-normal pj:text-muted-foreground">
{result.status === 'skip' ? 'skipped' : `${result.durationMs} ms`}
{result.status === 'skip'
? 'skipped'
: result.status === 'advice'
? `craft notes, ${result.durationMs} ms`
: `${result.durationMs} ms`}
</span>
)}
</p>
Expand All @@ -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}) {
Expand Down
109 changes: 109 additions & 0 deletions packages/renderers/harness/browser/craft.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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<CraftReport>('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 = '') =>
`<span style="display:inline-block;padding:0 4px;border:1px solid #888;border-radius:3px;line-height:18px;${style}">${text}</span>`
fixture.innerHTML = `
<div class="touching" data-projections-unit="" style="width:400px">
${pill('a', 'margin-right:0')}${pill('b')}
<span style="display:inline-block;width:8px"></span>${pill('c')}
</div>
<div class="dense" data-projections-unit="" style="width:400px">
${['one', 'two', 'three', 'four', 'five', 'six', 'seven'].map(text => pill(text, 'margin:4px')).join('')}
</div>
<div class="changes" data-projections-unit="" style="width:400px">
${['+a', '+b', '+c', '+d', '+e', '+f', '+g'].map(text => `<span data-change="added" style="display:inline-block;margin:4px;border:1px solid #888;border-radius:3px">${text}</span>`).join('')}
</div>
<div class="chip-changes" data-projections-unit="" style="width:400px">
${['+a', '+b', '+c', '+d', '+e', '+f', '+g'].map(text => `<span data-chip-change="added" style="display:inline-block;margin:4px;border:1px solid #888;border-radius:3px">${text}</span>`).join('')}
</div>
<div class="lines" data-projections-unit=""" style="width:600px">
<p class="decorated">Build on <code style="color:var(--projections-color-accent)">os</code> for label</p>
<p class="quiet">Steps <code>checkout@v5</code> <span style="color:var(--projections-color-fg-muted)">and 8 run steps</span></p>
</div>
<table class="in-cells" data-projections-unit=""><tbody><tr><td>${pill('x', 'margin-right:0')}${pill('y')}</td></tr></tbody></table>
<div class="filled-change" data-projections-unit="" style="width:400px">
<span data-chip-change="added" style="display:inline-block;padding:0 4px;border-radius:3px;background:#dafbe1;line-height:18px">new</span>${pill('old')}
</div>
<div class="value-change" data-projections-unit="" style="width:400px">
<span class="pk-value-change">${pill('old', 'margin-right:0')}${pill('new')}</span>
</div>
<div class="twins" data-projections-unit="" style="display:flex;gap:16px;width:600px">
<p class="twin" style="margin:0"><code>a.b</code></p>
<p class="twin" style="margin:0;color:var(--projections-color-accent)">accent words</p>
</div>
<table class="grid" data-projections-unit="">
<thead><tr><th>os × compiler</th><th>Transparent</th><th>Background</th></tr></thead>
<tbody>
<tr><th>windows</th><td>windows · Transparent</td><td>windows · Background</td></tr>
<tr><th>macos</th><td>macos · Transparent</td><td>macos · Background</td></tr>
</tbody>
</table>
<table class="marks" data-projections-unit="">
<thead><tr><th>os × compiler</th><th>Transparent</th><th>Background</th></tr></thead>
<tbody>
<tr><th>windows</th><td>●<span class="sr-only"><span>windows · Transparent</span></span></td><td>●<span class="sr-only"><span>windows · Background</span></span></td></tr>
<tr><th>macos</th><td>●<span class="sr-only"><span>macos · Transparent</span></span></td><td>●<span class="sr-only">macos · Background</span></td></tr>
</tbody>
</table>
<table class="sparse" data-projections-unit="">
<thead><tr><th>os × compiler</th><th>Transparent</th><th>Background</th></tr></thead>
<tbody>
<tr><th>windows</th><td>windows · Transparent</td><td>windows · Background</td></tr>
<tr><th>macos</th><td></td><td></td></tr>
<tr><th>ubuntu</th><td></td><td></td></tr>
<tr><th>alpine</th><td></td><td></td></tr>
<tr><th>freebsd</th><td></td><td></td></tr>
</tbody>
</table>
<table class="split" data-projections-unit="">
<thead><tr><th>os × compiler</th><th>TransparentCompiler</th></tr></thead>
<tbody>
<tr><th>windows</th><td>windows · Transparent<strong>Compiler</strong></td></tr>
<tr><th>macos</th><td>macos · Transparent<strong>Compiler</strong></td></tr>
</tbody>
</table>
<table class="short" data-projections-unit="">
<thead><tr><th>build</th><th>Compiler</th><th>Mode</th><th>#</th><th>%</th></tr></thead>
<tbody>
<tr><th>windows</th><td>windows Compiler</td><td>windows Mode</td><td>3</td><td>40</td></tr>
</tbody>
</table>`
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<CraftReport>('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)
// 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)
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', 'table.split'])
})
24 changes: 24 additions & 0 deletions packages/renderers/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
- `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

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.

- `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
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/testing/src/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
15 changes: 15 additions & 0 deletions packages/renderers/testing/src/checks/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export const checkTitles: Record<CheckId, string> = {
'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. */
Expand Down Expand Up @@ -151,7 +155,18 @@ export const checkDescriptions: Record<CheckId, string> = {
"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':
"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':
"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[] = ['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[]
Loading
Loading