diff --git a/.claude/skills/ui-sweep/scripts/sweep.py b/.claude/skills/ui-sweep/scripts/sweep.py index bccaddcd..39ffd476 100644 --- a/.claude/skills/ui-sweep/scripts/sweep.py +++ b/.claude/skills/ui-sweep/scripts/sweep.py @@ -25,8 +25,8 @@ from playwright.sync_api import sync_playwright SHOWN = ", ".join(["#nullius-builder .nb-tile strong", "#nullius-builder h2", "#nullius-builder h3", - "#nullius-builder .nb-tile-line", "#nullius-builder .nb-subtab", ".bench-card strong", - ".bench-card p", ".std-card p"]) + "#nullius-builder .nb-tile-line", "#nullius-builder .nb-subtab", ".bench-card dt", + ".bench-card dd", ".bench-card-domain:not(.std-clamp)", ".std-card p"]) CUT = """() => [...document.querySelectorAll('""" + SHOWN + """')] .filter(e => e.offsetParent && (e.scrollWidth > e.clientWidth + 1 || e.scrollHeight > e.clientHeight + 1)) .map(e => e.textContent.trim().slice(0, 80))""" diff --git a/AGENTS.md b/AGENTS.md index 400ed71a..febcc43a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -79,6 +79,7 @@ and its resources. The source layout stays under `app/`. names (`runs/`, `traces/`, `builder/`, …; `base.html`, `style.css` and the fonts at the top), including the command builder's JavaScript, which owns the generated recipes. `app/templates/_tables.html` and `app/static/tables.js` are the table toolkit: one column list builds a table's headers, cells and controls. + `app/templates/_cards.html` lays the same field list out as cards, one slot per field. - `app/tests/`, `app/ui_tests/` — the backend suite and the route suite. Beside the backend tests sit scripts run by hand: `app/tests/field_contract.py`, which refreshes the `field_contract.json` the diff --git a/app/nullius/onboarding.py b/app/nullius/onboarding.py index 1b4047c1..733551fb 100644 --- a/app/nullius/onboarding.py +++ b/app/nullius/onboarding.py @@ -34,7 +34,7 @@ ]}, {"id": "bench", "name": "Pick a benchmark", "page": "benchmarks_page", "where": "Benchmarks", "subs": [ {"id": "browse", "text": "Browse the catalogue", "visit": r"^/benchmarks/?$", - "target": [[".bench-filters, #bench-find", "Filter by category, runner or origin"]]}, + "target": [["#benchmarks-tools", "Search or filter by category, runner or origin"]]}, {"id": "open", "text": "Open a benchmark's page", "visit": r"^/benchmarks/(?!new)[^/]+$", "target": [[".bench-card", "Open a benchmark"]]}, ]}, diff --git a/app/static/catalogue/catalogue.css b/app/static/catalogue/catalogue.css index 1fb1e407..0d1d6cd7 100644 --- a/app/static/catalogue/catalogue.css +++ b/app/static/catalogue/catalogue.css @@ -4,19 +4,8 @@ .bench-index-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; } .bench-index-head h1 { margin: 0; font-size: 30px; font-weight: 500; letter-spacing: -.01em; } .bench-count { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; } -.bench-find { display: flex; flex-direction: column; gap: 6px; flex: 0 1 280px; font-size: 12px; color: var(--text-dim); } -.bench-find input { width: 100%; } -.bench-find input { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 44px; box-sizing: border-box; } -.bench-find input:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); } -/* the category chips, then the origin chips after a rule, on one line while they fit */ -.bench-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 30px; } -.bench-filters .bench-cats + .bench-cats { padding-left: 16px; border-left: 1px solid var(--border); } -@media (max-width: 640px) { .bench-filters .bench-cats + .bench-cats { padding-left: 0; border-left: 0; } } -.bench-cats { display: flex; flex-wrap: wrap; gap: 8px; } -.bench-cat { font: inherit; font-size: 13px; cursor: pointer; color: var(--text-dim); background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; min-height: 40px; } -.bench-cat:hover { border-color: var(--accent); color: var(--text); } -.bench-cat.on { background: var(--accent); border-color: var(--accent); color: var(--btn-fg); font-weight: 500; } -.bench-cat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +/* the cards' controls row, under the title */ +.bench-index > .table-controls { margin: 0 0 24px; } .bench-shelf { margin: 0 0 34px; } .bench-shelf[hidden], .bench-card[hidden] { display: none; } .bench-shelf h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 13px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--text); } @@ -27,9 +16,18 @@ .bench-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } @media (max-width: 1180px) { .bench-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } } @media (max-width: 640px) { .bench-grid { grid-template-columns: minmax(0, 1fr); } } -.bench-card { display: flex; flex-direction: column; gap: 14px; padding: 20px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-soft); color: var(--text); transition: border-color .13s ease; } -.bench-card:hover { border-color: var(--accent); text-decoration: none; } -.bench-card:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent); } +/* a card (templates/_cards.html): its title's link stretched over it, so the whole card opens it; a checkbox, a + button or a value with a tooltip sits above that link */ +.bench-card { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 20px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-soft); color: var(--text); transition: border-color .13s ease; } +.bench-card:hover { border-color: var(--accent); } +.card-link, .card-link:hover { color: inherit; text-decoration: none; } +.card-link::after { content: ""; position: absolute; inset: -1px; border-radius: 12px; } +.card-link:focus-visible { outline: none; } +.card-link:focus-visible::after { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent); } +.bench-card :is(input, button, .btn, [title]) { position: relative; z-index: 1; } +.bench-card [title]:not(input, button, .btn) { cursor: pointer; } /* raised for its tooltip, it still opens the card */ +.bench-card-top .bench-harness { margin-left: auto; } +.bench-card-actions { display: flex; flex-wrap: wrap; gap: 8px; } .bench-shelf.st-community .bench-card { background: transparent; border-style: dashed; border-color: var(--border); } .bench-shelf.st-community .bench-card:hover { border-color: var(--accent); } .bench-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; } @@ -40,11 +38,12 @@ .bench-head h1 { display: flex; align-items: center; gap: 14px; } .bench-head h1 .bench-mark { width: 32px; height: 32px; } .bench-card-domain { margin-top: -6px; font-size: 14px; line-height: 1.5; color: var(--text-dim); } -.bench-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-soft); } +/* up to three stats in columns of one width, each its label then its value */ +.bench-stats { display: grid; grid-template-columns: repeat(3, minmax(min-content, 1fr)); gap: 8px; margin: auto 0 0; padding-top: 14px; border-top: 1px solid var(--border-soft); } .bench-stats > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; } -.bench-stats b { font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; } -.bench-stats b.word { font-size: 14px; font-weight: 500; line-height: 1.35; padding-top: 3px; } -.bench-stats span { font-size: 12px; color: var(--text-faint); } +.bench-stats dd { margin: 0; font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; } +.bench-stats dd.word { font-size: 14px; line-height: 1.35; padding-top: 3px; } +.bench-stats dt { font-size: 12px; color: var(--text-faint); } /* a long label wraps between words; its longest word sizes its column */ .bench-card-blocker { font-size: 13px; line-height: 1.5; color: var(--text-dim); } .bench-none { color: var(--text-dim); font-size: 14px; } @@ -137,11 +136,10 @@ .settings-page .settings-test.bad { color: var(--bad); } /* Add a Harbor benchmark: two steps, the dataset read from Harbor, then the entry. */ -/* Find and Add side by side at the right of the title, the button the height of the box */ +/* Add at the right of the title */ .bench-head-tools { display: flex; align-items: flex-end; gap: 12px; flex: 0 1 auto; } -.bench-head-tools .bench-find { flex: 0 1 300px; min-width: 180px; } .bench-head-tools .btn { min-height: 44px; white-space: nowrap; flex: none; } -@media (max-width: 640px) { .bench-head-tools { flex-wrap: wrap; width: 100%; } .bench-head-tools .bench-find { flex: 1 1 100%; } } +@media (max-width: 640px) { .bench-head-tools { flex-wrap: wrap; width: 100%; } } .bench-new { max-width: 860px; } .nb-step { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px; padding: 20px; margin: 0 0 18px; } .nb-step h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-size: 16px; font-weight: 500; } @@ -227,7 +225,7 @@ .std-head h2 { margin: 0 0 6px; font-size: 20px; } .std-mark { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font: 500 18px/1 var(--mono); flex: none; } .std-tags { display: flex; flex-wrap: wrap; gap: 6px; } -.std-tag { padding: 2px 9px; border: 1px solid var(--border); border-radius: 999px; font: 11px/1.5 var(--mono); color: var(--text-dim); } +.std-tag { padding: 2px 9px; border: 1px solid var(--border); border-radius: 5px; font: 11px/1.5 var(--mono); color: var(--text-dim); } .std-versions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 14px; } .std-versions > span { font-size: 12px; color: var(--text-dim); margin-right: 4px; } .std-versions a { display: flex; flex-direction: column; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; color: inherit; text-decoration: none; } @@ -325,7 +323,7 @@ dialog.std-how::backdrop { background: rgba(0, 0, 0, .45); } .std-add-hint { font-size: 12.5px; } @media (max-width: 640px) { dialog.std-how { padding: 18px 16px; } .std-add-fields { grid-template-columns: 1fr; } .std-add-fields :is(input, textarea) { font-size: 16px; } } /* What runs a benchmark, as bubbles - on its card, its page and the Add dialog - named as the filter chips name them. */ -.run-tag { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 500; letter-spacing: .03em; padding: .12rem .55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap; } +.run-tag { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 500; letter-spacing: .03em; padding: .12rem .55rem; border-radius: 5px; border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap; } .run-tag.rt-harbor { color: var(--text); border-color: var(--text-dim); } .run-tag.rt-standard { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); } .run-tags { display: flex; flex-wrap: wrap; gap: 6px; } diff --git a/app/static/catalogue/catalogue.js b/app/static/catalogue/catalogue.js index 167d8bb3..b240a60a 100644 --- a/app/static/catalogue/catalogue.js +++ b/app/static/catalogue/catalogue.js @@ -1,41 +1,13 @@ (() => { const hash = () => { try { return decodeURIComponent(location.hash.slice(1)); } catch { return ''; } }; - // Hash links (/benchmarks#key, /benchmarks#dataset) open the benchmark's page; category or origin chips and the - // Find box keep the cards that match, and a shelf left empty folds away. - const cards = [...document.querySelectorAll('.bench-card')]; + // Hash links (/benchmarks#key, /benchmarks#dataset, /kits#key) open the card's own page; the search and filters + // are the card toolkit's (static/tables.js). + const cards = [...document.querySelectorAll('.bench-card[data-keys]')]; if (cards.length) { const key = hash(); const owner = key && cards.find(c => c.dataset.keys.split(' ').includes(key)); - if (owner) { - location.replace(owner.href + (key === owner.dataset.keys.split(' ')[0] ? '' : '#' + encodeURIComponent(key))); - return; - } - const find = document.getElementById('bench-find'); - const chips = [...document.querySelectorAll('[data-filter] .bench-cat')]; - const none = document.getElementById('bench-none'); - // one value per filter group (category, origin); '' keeps every card - const picked = {}; - const apply = () => { - const words = (find?.value || '').toLowerCase().split(/\s+/).filter(Boolean); - cards.forEach(c => { - // Only runners are a space-separated list; categories may contain spaces. - c.hidden = !(Object.entries(picked).every(([f, v]) => !v || (f === 'runs' ? (c.dataset[f] || '').split(' ').includes(v) : c.dataset[f] === v)) && words.every(w => c.dataset.find.includes(w))); - }); - document.querySelectorAll('[data-shelf]').forEach(shelf => { - const shown = shelf.querySelectorAll('.bench-card:not([hidden])').length; - shelf.hidden = !shown; - shelf.querySelector('.shelf-n').textContent = shown; - }); - chips.forEach(chip => { - const on = chip.dataset.value === (picked[chip.closest('[data-filter]').dataset.filter] || ''); - chip.classList.toggle('on', on); - chip.setAttribute('aria-pressed', String(on)); - }); - if (none) none.hidden = cards.some(c => !c.hidden); - }; - chips.forEach(chip => chip.addEventListener('click', () => { picked[chip.closest('[data-filter]').dataset.filter] = chip.dataset.value; apply(); })); - find?.addEventListener('input', apply); + if (owner) location.replace(owner.querySelector('.card-link').href + (key === owner.dataset.keys.split(' ')[0] ? '' : '#' + encodeURIComponent(key))); return; } diff --git a/app/static/style.css b/app/static/style.css index 12331dc0..0350949b 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -458,6 +458,17 @@ button.seg:hover { filter: brightness(1.25); } /* a column's alignment (its `align`), header and cells */ .grid .align-right { text-align: right; } .grid .align-center { text-align: center; } +/* a row of filter pills (the controls macro's `pills`), under the search and the buttons */ +.filter-pills { display: flex; flex-wrap: wrap; flex: 1 0 100%; gap: 8px; } +.filter-pill { font: inherit; font-size: 13px; cursor: pointer; color: var(--text-dim); background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; min-height: 40px; } +.filter-pill:hover { border-color: var(--accent); color: var(--text); } +.filter-pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--btn-fg); font-weight: 500; } +.filter-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.filter-pills > .ic { align-self: center; color: var(--text-dim); } +.dd-chev { margin-right: -.2rem; } +[data-dropdown][aria-expanded="true"] .dd-chev { transform: rotate(180deg); } +@media (prefers-reduced-motion: no-preference) { .dd-chev { transition: transform .24s ease; } } +.btn.ghost.narrowed { border-color: var(--accent); color: var(--text); } /* a filter button whose column shows not every value */ .tools-count { margin-left: .4rem; padding: 0 .4em; border-radius: 99px; background: var(--accent-soft); color: var(--text); font-size: .72rem; font-variant-numeric: tabular-nums; } .chip.clear { border-style: dashed; } diff --git a/app/static/tables.js b/app/static/tables.js index 9e71a5f1..f5e72df6 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -1,6 +1,6 @@ /* The table toolkit's script: each function is a feature a table.grid opts into (the macros of templates/_tables.html; their styles in style.css, - "the table toolkit"). */ + "the table toolkit"), and the card toolkit's (templates/_cards.html). */ window.NulliusTable = { /* A header with data-type sorts its column on a click or Enter; num sorts descending first. A cell's data-sort wins over its text. A header that @@ -50,37 +50,50 @@ window.NulliusTable = { return resort; }, - /* The value lists (data-filter-menu) under `scope`, the controls macro's - Filter menu. `allowed`: column -> the Set of values ticked, or null when - all are. A row passes when, for each column, one of its values - (data-f-, one per line) is ticked; a box unticked at load filters - from the start. `changed` runs after each change, a list's change event - included. */ + /* The filters under `scope`, the controls macro's: value lists + (data-filter-menu) and rows of pills (data-pills). `allowed`: column -> + the Set of values chosen, or null when all are; every list and row of a + column shows that one state. A row passes when, for each column, one of + its values (data-f-, one per line) is chosen; a choice made at load + filters from the start. `changed` runs after each change, a list's + change event included. */ filters(scope, changed) { - const allowed = {}; - scope.querySelectorAll('[data-filter-menu]').forEach(menu => { - const col = menu.dataset.filterMenu; - const boxes = () => [...menu.querySelectorAll('input[data-value]')]; - const read = () => { - const on = boxes().filter(b => b.checked).map(b => b.dataset.value); - allowed[col] = on.length === boxes().length ? null : new Set(on); // all ticked: no filter - }; - const sync = () => { read(); changed(); }; - read(); - menu.addEventListener('change', sync); - menu.addEventListener('click', e => { - if (e.target.closest('[data-all]')) { boxes().forEach(b => b.checked = true); sync(); } - if (e.target.closest('[data-none]')) { boxes().forEach(b => b.checked = false); sync(); } + const allowed = {}, views = [...scope.querySelectorAll('[data-filter-menu], [data-pills]')]; + const col = v => v.dataset.filterMenu ?? v.dataset.pills; + const values = v => [...v.querySelectorAll('[data-value]')]; + const draw = () => views.forEach(v => { + const set = allowed[col(v)]; + values(v).forEach(b => { if (b.matches('input')) b.checked = !set || set.has(b.dataset.value); else b.setAttribute('aria-pressed', String(Boolean(set?.has(b.dataset.value)))); }); + v.querySelector('.filter-pill[data-all]')?.setAttribute('aria-pressed', String(!set)); + }); + // All chosen means "no filter": keeps the active markers honest. + const choose = (v, on) => { allowed[col(v)] = on && on.size < values(v).length ? on : null; }; + const set = (v, on) => { choose(v, on); draw(); changed(); }; + const chosen = v => new Set(values(v).filter(b => b.checked || b.getAttribute('aria-pressed') === 'true').map(b => b.dataset.value)); + views.forEach(v => { + if (!(col(v) in allowed)) { const on = chosen(v); choose(v, v.dataset.pills !== undefined && !on.size ? null : on); } + if (v.dataset.pills !== undefined) { + // a pill toggles its value; none left is All + v.addEventListener('click', e => { + const b = e.target.closest('[data-value]'), now = allowed[col(v)]; + if (e.target.closest('[data-all]')) return set(v, null); + if (!b) return; + const on = new Set(now || []); + on.has(b.dataset.value) ? on.delete(b.dataset.value) : on.add(b.dataset.value); + set(v, on.size ? on : null); + }); + return; + } + v.addEventListener('change', () => set(v, chosen(v))); + v.addEventListener('click', e => { + if (e.target.closest('[data-all]')) set(v, null); + if (e.target.closest('[data-none]')) set(v, new Set()); }); }); + draw(); const passes = row => Object.entries(allowed).every(([col, set]) => !set || (row.getAttribute('data-f-' + col) ?? '').split('\n').some(v => set.has(v))); - const clear = () => { - scope.querySelectorAll('[data-filter-menu]').forEach(menu => { - menu.querySelectorAll('input[data-value]').forEach(b => b.checked = true); - allowed[menu.dataset.filterMenu] = null; - }); - }; + const clear = () => { Object.keys(allowed).forEach(c => { allowed[c] = null; }); draw(); }; return {allowed, passes, clear}; }, @@ -124,15 +137,16 @@ window.NulliusTable = { btn.addEventListener('focusout', left); }, - /* A table's search box, Filter and Sort by menus (the controls macro), - under `tools`; each optional. Search keeps the rows whose data-search - holds every word of the query, in any order and case; Escape clears it. Filter counts the columns it - narrows; Sort by sets the sort, and follows a header click. `changed` - runs after any of them. Returns {passes, resort}, as filters and sortable - do. */ - toolbar(table, tools, changed) { - const [fbtn, fmenu, sbtn, smenu] = ['filter', 'sort'].flatMap(k => - [tools.querySelector(`[data-tools-btn="${k}"]`), tools.querySelector(`[data-tools="${k}"]`)]); + /* A controls row's search box and filters (the controls macro), under + `tools`; each optional. Search keeps the rows (or cards) whose + data-search holds every word of the query, in any order and case; + Escape clears it. A column narrows when it does not show every value; + the Filter button or a dropdown holding such a column is marked + .narrowed and counts: the Filter button the columns it narrows, a + dropdown the values chosen (after None, 0). Clear filters clears every + column. `changed` runs after any of them. Returns passes(row). */ + narrow(tools, changed) { + const [fbtn, fmenu] = [tools.querySelector('[data-tools-btn="filter"]'), tools.querySelector('[data-tools="filter"]')]; const q = tools.querySelector('[data-search]'); if (q) { q.addEventListener('input', changed); @@ -142,19 +156,29 @@ window.NulliusTable = { const text = (row.dataset.search ?? '').toLowerCase(); return !q || q.value.toLowerCase().split(/\s+/).every(w => text.includes(w)); }; - const count = fbtn?.querySelector('.tools-count'); - const mark = () => { - const n = Object.values(f.allowed).filter(Boolean).length; - count.textContent = n || ''; - count.hidden = !n; - }; + const menus = [...(fmenu ? [[fbtn, fmenu, () => 1]] : []), + ...[...tools.querySelectorAll('[data-dropdown]')].map(b => [b, b.parentNode.querySelector('.menu'), set => set.size])]; + const mark = () => menus.forEach(([btn, menu, n]) => { + const sets = [...menu.querySelectorAll('[data-filter-menu]')].map(v => f.allowed[v.dataset.filterMenu]).filter(Boolean); + const count = btn.querySelector('.tools-count'); + btn.classList.toggle('narrowed', sets.length > 0); + count.textContent = sets.length ? sets.reduce((sum, set) => sum + n(set), 0) : ''; + count.hidden = !sets.length; + }); const narrowed = () => { mark(); changed(); }; - const f = fmenu ? this.filters(fmenu, narrowed) : {allowed: {}, passes: () => true}; - if (fmenu) { - mark(); - fmenu.querySelector('[data-clear]').addEventListener('click', () => { f.clear(); narrowed(); }); - this.menu(fbtn, fmenu); - } + const f = this.filters(tools, narrowed); + mark(); + menus.forEach(([btn, menu]) => this.menu(btn, menu)); + fmenu?.querySelector('[data-clear]').addEventListener('click', () => { f.clear(); narrowed(); }); + return row => f.passes(row) && found(row); + }, + + /* A table's controls row: narrow's search and Filter, and the Sort by + menu, which sets the sort and follows a header click. Returns + {passes, resort}, as narrow and sortable do. */ + toolbar(table, tools, changed) { + const passes = this.narrow(tools, changed); + const [sbtn, smenu] = [tools.querySelector('[data-tools-btn="sort"]'), tools.querySelector('[data-tools="sort"]')]; const heads = [...table.tHead.rows[0].cells]; const sync = () => { if (!smenu) return; @@ -173,7 +197,7 @@ window.NulliusTable = { sync(); this.menu(sbtn, smenu); } - return {passes: row => f.passes(row) && found(row), resort}; + return {passes, resort}; }, /* A table of the table macro (data-table): its controls row (id @@ -193,6 +217,40 @@ window.NulliusTable = { first = this.pager(table, table.id + '.per', t.passes, ticks); }, + /* A collection of the cards macro (data-cards): its controls row (id + -tools) shows the cards (data-card) that pass, the note when none + does; a data-group holding cards hides when none of them shows, and its + data-group-n counts those that do. After a change, a screen reader hears + how many show once the changes pause, counted in the live region's + data-noun. A click anywhere on a card but on a control of its own + follows the card's link, in a new tab or window with the keys or the + button a link takes; a click that ends a text selection does not. */ + cards(root) { + const items = [...root.querySelectorAll('[data-card]')], empty = document.querySelector(`[data-empty="${CSS.escape(root.id)}"]`); + const live = document.querySelector(`[data-live="${CSS.escape(root.id)}"]`), say = this.voice(live); + const follow = e => { + const link = e.target.closest('[data-card]')?.querySelector('.card-link'); + if (!link || e.target.closest('a, button, input, select, textarea, label, summary, [role=button]') || !getSelection().isCollapsed) return; + if (e.button === 1 || e.ctrlKey || e.metaKey || e.shiftKey) window.open(link.href, '_blank', 'noopener'); + else if (e.button === 0) link.click(); + }; + root.addEventListener('click', follow); + root.addEventListener('auxclick', follow); + const draw = () => { + items.forEach(c => { c.hidden = !passes(c); }); + root.querySelectorAll('[data-group]').forEach(g => { + const n = [...g.querySelectorAll('[data-card]')].filter(c => !c.hidden).length, count = g.querySelector('[data-group-n]'); + g.hidden = !n; + if (count) count.textContent = n; + }); + const n = items.filter(c => !c.hidden).length; + empty.hidden = n > 0; + say(n ? `${n} of ${items.length} ${live.dataset.noun}` : empty.textContent); + }; + const passes = this.narrow(document.getElementById(root.id + '-tools'), draw); + draw(); + }, + /* A checkbox column (a `check` column, check_cell in each row): the header ticks or unticks every visible row, and shows all, none or some of them ticked. Returns sync(), to run when rows show or hide. */ @@ -238,6 +296,17 @@ window.NulliusTable = { place(); }, + /* A live region: say(text) reads out the last text once the changes + pause; the first, the page's own drawing at load, is not read out. */ + voice(live) { + let t, loaded = false; + return text => { + clearTimeout(t); + if (loaded) t = setTimeout(() => { live.textContent = text; }, 300); + loaded = true; + }; + }, + /* A table's pages (the pager macro named after its id): the rows `passes` lets through, a page of them at a time, the page's size remembered per viewer under `key`; its empty note shows when none passes. After a @@ -248,7 +317,8 @@ window.NulliusTable = { pager(table, key, passes = () => true, drawn = () => {}) { const bar = document.querySelector(`[data-pager="${CSS.escape(table.id)}"]`), empty = document.querySelector(`[data-empty="${CSS.escape(table.id)}"]`); const [per, note, prev, next, live] = ['[data-per]', '[data-note]', '[data-prev]', '[data-next]', '[data-live]'].map(s => bar.querySelector(s)); - let page = 0, said, loaded = false; + let page = 0; + const say = this.voice(live); try { const n = localStorage.getItem(key); if (n !== null && [...per.options].some(o => o.value === n)) per.value = n; } catch {} const draw = () => { const rows = [...table.tBodies[0].rows], hit = rows.filter(passes), n = +per.value || hit.length || 1; @@ -259,8 +329,7 @@ window.NulliusTable = { prev.disabled = page === 0; next.disabled = (page + 1) * n >= hit.length; empty.hidden = hit.length > 0; - clearTimeout(said); - if (loaded) said = setTimeout(() => { live.textContent = hit.length ? `${note.textContent} ${live.dataset.noun}` : empty.textContent; }, 300); + say(hit.length ? `${note.textContent} ${live.dataset.noun}` : empty.textContent); drawn(); }; const first = () => { page = 0; draw(); }; @@ -271,15 +340,18 @@ window.NulliusTable = { prev.addEventListener('click', () => { page--; draw(); }); next.addEventListener('click', () => { page++; draw(); }); draw(); - loaded = true; return first; }, }; -/* Every table with sticky columns, and every table of the table macro, set up once the page is read. */ -const nulliusTables = () => document.querySelectorAll('table.grid').forEach(t => { - if (t.querySelector('.sticky-col')) NulliusTable.sticky(t); - if (t.hasAttribute('data-table')) NulliusTable.wire(t); -}); +/* Every table with sticky columns, every table of the table macro and every collection of the cards macro, set up + once the page is read. */ +const nulliusTables = () => { + document.querySelectorAll('table.grid').forEach(t => { + if (t.querySelector('.sticky-col')) NulliusTable.sticky(t); + if (t.hasAttribute('data-table')) NulliusTable.wire(t); + }); + document.querySelectorAll('[data-cards]').forEach(c => NulliusTable.cards(c)); +}; if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', nulliusTables); else nulliusTables(); diff --git a/app/templates/_cards.html b/app/templates/_cards.html new file mode 100644 index 00000000..bb2970f4 --- /dev/null +++ b/app/templates/_cards.html @@ -0,0 +1,73 @@ +{#- The card toolkit: items as cards over the same field list as the table toolkit (_tables.html), run by + static/tables.js (NulliusTable.cards) and styled in catalogue/catalogue.css. A field's `card` names the slot it + fills; a field without one is not on the card, and `table` false keeps a card-only field off a table. Slots, in + order: `status`, `tag`*, `meta`, `check` (the top row); `icon`, `title` (exactly one); `text`; `badge`*, `note`*; + `stat` (up to 3, below a line); `alert`; `action`* (* any number, the others at most one). + An item is a dict of display values by field key: a string, a dict {text, class, title, label, href, value} or a + list of them, empty for none; a filter reads a value's `value`, else its text. Plus `href` (its title's link), + `id`, `search` (what the search reads) and `keys`. + A field's `class` goes on each of its values; `card_label` names a stat when its column header does not, and a + value's `label` names it for that item; `style` 'code' sets the text as code; `icon` puts #i- before a + note. `icon` values are image URLs: when one item has one, the others show initials; when none has, no icon. -#} +{% from '_tables.html' import controls, empty_note %} + +{#- Each value of `fields` in `item`, as a dict, to the call block with its field. #} +{% macro each(item, fields) %}{% for f in fields %}{% set v = item.get(f.key) %} +{%- for x in ([v] if v is string or v is mapping or v is number else v or []) if x is not none and x != '' %}{{ caller(f, x if x is mapping else {'text': x}) }}{% endfor %}{% endfor %}{% endmacro %} + +{#- A value as a pill: its field's class and its own, its tooltip. #} +{% macro pill(f, v) %}{% set cls = [f.class, v.class]|select|join(' ') %}{{ v.text }}{% endmacro %} + +{# A collection of cards (NulliusTable.cards): its controls row, its cards, the note when none passes. `id` names it; + `search`, `choices`, `only` and each field's `filter` as the table's controls; `noun` what the live region counts. + The call block, when given, writes the cards instead (grid for each group, such as the Benchmarks' shelves); a + section in it marked data-group hides when none of its cards shows, and its data-group-n counts them. #} +{% macro cards(id, cols, items, search='', choices={}, only={}, empty='No items match.', noun='items') %} +{{ controls(id, cols, search, choices=choices, only=only, sort=false) }} +
{% if caller is defined %}{{ caller() }}{% else %}{{ grid(cols, items, choices=choices) }}{% endif %}
+{{ empty_note(id, empty) }} + +{% endmacro %} + +{# The cards of `items`. `every`: the collection the icon rule reads, when `items` is a part of it; `choices`: the + filtered fields, each written on the card for the filter. #} +{% macro grid(cols, items, every=none, choices={}) %} +{%- set fields = cols|selectattr('card')|list %} +{%- set by = {} %}{% for slot in ['status', 'tag', 'meta', 'check', 'icon', 'title', 'text', 'badge', 'note', 'stat', 'alert', 'action'] %}{% set _ = by.update({slot: fields|selectattr('card', 'equalto', slot)|list}) %}{% endfor %} +{#- the limits, each failing the page: one title, at most three stats, at most one of each other single slot #} +{%- if not by.title or by.stat|length > 3 %}{{ cards_take_one_title_and_at_most_three_stats() }}{% endif %} +{%- for slot in ['status', 'meta', 'check', 'icon', 'title', 'text', 'alert'] if by[slot]|length > 1 %}{{ cards_take_one_of_each_single_slot() }}{% endfor %} +{%- set icon = by.icon[0] if by.icon else none %} +{%- set icons = icon and (every or items)|selectattr(icon.key)|list|length > 0 %} +
+{%- for item in items %} +
+ {%- set top %}{% call(f, v) each(item, by.status) %}{{ pill(f, v) }}{% endcall %} + {%- set tags %}{% call(f, v) each(item, by.tag) %}{{ pill(f, v) }}{% endcall %}{% endset %}{% if tags %}{{ tags }}{% endif %} + {%- call(f, v) each(item, by.meta) %}{{ v.text }}{% endcall %} + {%- call(f, v) each(item, by.check) %}{% endcall %}{% endset %} + {%- if top %} +
{{ top }}
{% endif %} + {%- set title = by.title[0] %}{% set name = item.get(title.key) %}{% set name = name.text if name is mapping else name %} +
{% if icons %}{% set src = item.get(icon.key) %} + {%- if not src %} + {%- elif '#' in src %} + {%- else %}{% endif %}{% endif -%} + {{ name }}
+ {%- call(f, v) each(item, by.text) %} +
{% if f.style == 'code' %}{{ v.text }}{% else %}{{ v.text }}{% endif %}
{% endcall %} + {%- set badges %}{% call(f, v) each(item, by.badge) %}{{ pill(f, v) }}{% endcall %}{% endset %}{% if badges %} +
{{ badges }}
{% endif %} + {%- call(f, v) each(item, by.note) %} +
{% if f.icon %}{% endif %}{{ v.text }}
{% endcall %} + {%- set stats %}{% call(f, v) each(item, by.stat) %}
{{ v.label or f.card_label or f.label }}
{{ v.text }}
{% endcall %}{% endset %}{% if stats %} +
{{ stats }}
{% endif %} + {%- call(f, v) each(item, by.alert) %} +
{{ v.text }}
{% endcall %} + {%- set actions %}{% call(f, v) each(item, by.action) %}{% if v.href %}{{ v.text }}{% else %}{% endif %}{% endcall %}{% endset %}{% if actions %} +
{{ actions }}
{% endif %} +
+{%- endfor %} +
+{%- endmacro %} diff --git a/app/templates/_tables.html b/app/templates/_tables.html index a8a68dc9..df867a92 100644 --- a/app/templates/_tables.html +++ b/app/templates/_tables.html @@ -8,7 +8,8 @@ `check`: blank, a checkbox that ticks every visible row (check_cell in each row); `sr`: the label for a screen reader only; `title`: its tooltip; `menu` false: not in the Columns menu; `fixed`: in it, always on; `off`: off until the viewer chooses; `width` in a table macro's table: 'fit' (default), as wide as its widest cell on one - line, or 'expand', the rest of the width, wrapping. #} + line, or 'expand', the rest of the width, wrapping; `table` false: on cards only (_cards.html, where `card` names + the slot a field fills), never in a table. #} {#- The class attribute of a column's header or cell: its alignment, whether it is pinned, `edge` whether it is the last pinned; `extra` adds to it. #} @@ -33,6 +34,7 @@ writes that cell with the cell macro. Opt-ins: `search`, `columns`, `choices`, `only`, `views`, `actions` as controls'; `empty` and `noun` as pager's. #} {% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none) %} +{%- set cols = cols|rejectattr('table', 'sameas', false)|list %} {{ controls(id, cols, search, columns, choices, only, views, actions) }} {%- for c in cols if c.width == 'expand' %} @@ -61,31 +63,34 @@ {# A table's controls row (static/tables.js `toolbar`) over the columns `cols`; each feature on only when asked. `search`: the search box's name and placeholder, over each row's data-search text; `columns`: the - Columns menu; `choices`: column -> its (value, label) pairs, a Filter menu of them; `only`: column -> the one value - ticked at load, the others unticked; then the Sort by menu. `views` and `actions`: macros writing a page's own + Columns menu; `choices`: column -> its (value, label) pairs to filter by; `only`: column -> the one value chosen + at load; then the Sort by menu, unless `sort` is false. `views` and `actions`: macros writing a page's own buttons, each any number of them, run by the page: views (how the table looks) before Columns, actions (on the - rows or the selection) last. The search goes left, the buttons right. `id`: the table's. #} -{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none) %} + rows or the selection) last. The search goes left, the buttons right. A column's + `filter` says where its choices go, one form or a list of them: 'button' (the default), in the Filter menu; + 'dropdown', a menu of its own; 'pills', a row of toggles under the controls. A column's `filter_icon`, a sprite id + without its `i-`, leads its dropdown's button and its pills. `id`: the table's. #} +{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true) %} +{%- set by = {'button': [], 'dropdown': [], 'pills': []} %}{% for c in cols if c.key in choices %}{% for f in ([c.filter] if c.filter is string else c.filter or ['button']) %}{% set _ = by[f].append(c) %}{% endfor %}{% endfor %}
{% if search %}{% endif %} -
+ {% if columns or by.dropdown or by.button or sort or views or actions %}
{{ slot('views', views) }} {% if columns %}{% endif %} - {% if choices %}{% endif %} + {% for c in by.pills %} +
+ {{ icon(c) }} + {%- for value, text in choices[c.key] %}{% endfor %}
+ {% endfor %}
{% endmacro %} @@ -109,6 +120,19 @@ writes nothing. #} {% macro slot(name, fill) %}{% set html = fill() if fill else '' %}{% if html|trim %}
{{ html }}
{% endif %}{% endmacro %} +{#- A column's `filter_icon`, if it has one. #} +{% macro icon(c) %}{% if c.filter_icon %}{% endif %}{% endmacro %} + +{#- A column's choices as checkboxes, in the Filter menu or a dropdown: all ticked, or only its `only` value. #} +{# `legend=false` in a dropdown, whose button already names the category #} +{% macro values(c, choices, only, legend=true) %} +
+ {% if legend %}{{ c.label }}{% endif %} + + {% for value, text in choices %}{% endfor %} +
+{% endmacro %} + {# A Columns menu (static/tables.js `columns`): its button, and the menu of `cols`' definitions, each a checkbox that shows or hides the cells of that data-col. The menu opens under the .menu-wrap that holds it. #} {% macro columns_button() %}{% endmacro %} @@ -128,7 +152,7 @@ and the page before and after; `empty` shows when no row passes. After a change, what is shown is read out once typing pauses, counted in `noun`. #} {% macro pager(table, empty='No rows match.', noun='rows') %} - +{{ empty_note(table, empty) }}
@@ -139,6 +163,9 @@
{% endmacro %} +{#- The note shown when no row of the table (or card of the collection) `id` passes. #} +{% macro empty_note(id, text) %}{% endmacro %} + {#- A button that cannot act here: greyed, still focusable, `why` its description and, after `action` when given, its tooltip; `id` names the description. An icon button by default; `class` and `text` make it another, such as a count. The cell or line that holds it is positioned, so the hidden reason stays in it. #} diff --git a/app/templates/agents/kits.html b/app/templates/agents/kits.html index 6f61d7fb..74c8909d 100644 --- a/app/templates/agents/kits.html +++ b/app/templates/agents/kits.html @@ -1,7 +1,9 @@ {% extends "base.html" %} {% block title %}{{ entry.label ~ ' kit' if entry else 'Kits' }} — Nullius{% endblock %} {% block crumb %}/ kits{% if entry %} / {{ entry.label }}{% endif %}{% endblock %} -{% block head %}{% endblock %} +{% block head %} +{% if not entry %}{% endif %}{% endblock %} +{% from '_cards.html' import cards %} {% block body %} {% if entry %} {% set d = entry.d %} @@ -35,19 +37,12 @@

Checks

{% else %}
-

Kits

{{ entries|length }} conformance kits

-
- {% for value, label in [('', 'All'), ('agent', 'Agents'), ('capability', 'Capabilities')] %}{% endfor %} -
- - +

Kits

{{ items|length }} conformance kits

+ {#- A card's fields (web/agents.py `_kit_card`); the family's pills filter them. #} + {% set cols = [dict(key='family', label='Family', card='tag', class='std-tag', filter='pills'), dict(key='version', label='Version', card='meta'), + dict(key='title', label='Name', card='title'), dict(key='port', label='Port', card='text', style='code'), + dict(key='checks', label='Checks', card='stat')] %} + {{ cards('kits', cols, items, search='Name, port, check', choices={'family': [('agent', 'Agents'), ('capability', 'Capabilities')]}, empty='No kits match.', noun='kits') }}
{% endif %} {% endblock %} diff --git a/app/templates/agents/standard.html b/app/templates/agents/standard.html index f09b944d..5f1effac 100644 --- a/app/templates/agents/standard.html +++ b/app/templates/agents/standard.html @@ -2,14 +2,16 @@ {% set plural = 'Agents' if kind == 'agent' else 'Capabilities' %} {% block title %}{{ plural }} — Nullius{% endblock %} {% block crumb %}/ {{ plural|lower }}{% endblock %} -{% block head %}{% endblock %} +{% block head %} +{% endblock %} +{% from '_cards.html' import cards %} {% block body %} {# The standard's agents (or capabilities) as cards, as the benchmarks are; a card opens its own page. docs/standard.md #}

{{ plural }}

-

{{ entries|length }} {{ plural|lower if entries|length != 1 else kind }} · +

{{ items|length }} {{ plural|lower if items|length != 1 else kind }} · {% if kind == 'agent' %}driven over ACP, the benchmark's tools served over MCP{% else %}driven over JSON lines{% endif %} · every model call through the relay

@@ -37,22 +39,15 @@

{{ plural }}

{% endcall %} {% if problems %}
Not offered: a definition with problems
    {% for p in problems %}
  • {{ p }}
  • {% endfor %}
{% endif %} - {% if not entries %}

No {{ kind }} yet.

{% endif %} + {% if not items %}

No {{ kind }} yet.

{% endif %} - + {#- A card's fields (web/agents.py `_card`). #} + {% set cols = [dict(key='kind', label='Kind', card='tag', class='cat-tag'), dict(key='protocol', label='Protocol', card='tag', class='std-tag'), + dict(key='example', label='Example', card='tag', class='std-tag'), dict(key='version', label='Version', card='meta'), + dict(key='icon', label='Logo', card='icon', table=false, class='std-mark small'), dict(key='title', label='Name', card='title'), + dict(key='summary', label='Summary', card='text', class='std-clamp'), dict(key='ports', label='Ports proven', card='stat'), + dict(key='runs', label='Benchmarks it runs', card='stat'), dict(key='installs', label='Installs', card='stat', class='word')] %} + {% if items %}{{ cards(plural|lower, cols, items, search='Name, protocol, summary', empty='No ' ~ kind ~ ' matches.', noun=plural|lower) }}{% endif %}
{% endblock %} {% block scripts %}{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index 5ec09fc9..e55e3bbe 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,7 +1,7 @@ {% macro agent_mark(kind, key, label, css='agent-logo') -%} - {% set source = agent_marks.get(key.split('@')[0]) if kind == 'agent' else none %} - {% if source and '#' in source %} - {% elif source %} + {% set source = agent_mark_url(key) if kind == 'agent' else none %} + {% if source and '#' in source %} + {% elif source %} {% else %}{{ label[:1] }}{% endif %} {%- endmacro %} @@ -87,6 +87,9 @@ + + + diff --git a/app/templates/catalogue/benchmarks.html b/app/templates/catalogue/benchmarks.html index 2b3c1dd3..2f37cdc7 100644 --- a/app/templates/catalogue/benchmarks.html +++ b/app/templates/catalogue/benchmarks.html @@ -1,12 +1,11 @@ {% extends "base.html" %} {% block title %}Benchmarks — Nullius{% endblock %} {% block crumb %}/ benchmarks{% endblock %} -{% block head %}{% endblock %} +{% block head %} +{% endblock %} +{% from '_cards.html' import cards, grid %} {% block body %} {% set listed = cat.listed_benchmarks %} -{#- a route's name, the same on the filter chips and on the cards' bubbles #} -{% set run_labels = {'harbor': 'Harbor', 'standard': 'Nullius'} %} -{% set run_names = {'harbor': 'Harbor', 'standard': 'the Nullius standard'} %} {% set count = namespace(datasets=0) %}{% for b in listed %}{% set count.datasets = count.datasets + b.datasets|length %}{% endfor %}
@@ -15,9 +14,6 @@

Benchmarks

{{ listed|length }} benchmarks · {{ count.datasets }} datasets

-
@@ -37,55 +33,25 @@

Benchmarks

{% endcall %} -
-
- - {% for c in cat.categories %} - {% endfor %} -
-
- - {% for r in ['standard', 'harbor'] %} - {% endfor %} -
-
- - {% for o in origins %} - {% endfor %} -
-
- - {# Two shelves: the official benchmarks, then the community benchmarks. A card opens the benchmark's own page. #} + {#- A card's fields (web/catalogue.py `_card`); the filters are the category's pills, and the origin and what runs it as dropdowns. #} + {% set cols = [dict(key='category', label='Category', card='tag', class='cat-tag', filter='pills'), dict(key='origin', label='Origin', card='tag', class='origin-tag', filter='dropdown', filter_icon='origin'), + dict(key='icon', label='Mark', card='icon', table=false, class='bench-mark'), dict(key='title', label='Name', card='title'), + dict(key='domain', label='Domain', card='text'), dict(key='runs', label='Runs with', card='badge', class='run-tag', filter='dropdown', filter_icon='runner'), + dict(key='needs', label='Needs', card='note', icon='wrench'), dict(key='tasks', label='Tasks', card='stat'), + dict(key='datasets', label='Datasets', card='stat'), dict(key='scoring', label='Scored by', card='stat', class='word'), + dict(key='blocker', label='Blocker', card='alert')] %} + {#- Two shelves: the official benchmarks, then the community benchmarks. A card opens the benchmark's own page. #} + {% call cards('benchmarks', cols, items, search='Name, category, dataset', choices=choices, empty='No benchmark matches.', noun='benchmarks') %} {% for state, heading in [('official', 'Official'), ('community', 'Community')] %} - {% set shelf = listed|selectattr('origin', 'equalto', state)|list %} + {% set shelf = items|selectattr('shelf', 'equalto', state)|list %} {% if shelf %} -
-

{{ heading }} {{ shelf|length }}

- +
+

{{ heading }} {{ shelf|length }}

+ {{ grid(cols, shelf, every=items, choices=choices) }}
{% endif %} {% endfor %} - + {% endcall %}
{% endblock %} {% block scripts %}{% endblock %} diff --git a/app/ui_tests/test_agents.py b/app/ui_tests/test_agents.py index 50277f1b..9acee267 100644 --- a/app/ui_tests/test_agents.py +++ b/app/ui_tests/test_agents.py @@ -55,7 +55,7 @@ def test_examples_lead_catalogue_and_sidebar(self): with patch.object(definitions, "load", _LOAD): for url in ("/agents", "/capabilities"): html = self.get(url).get_data(as_text=True) - cards = re.findall(r']*class="bench-card[^"]*"[^>]*>(.*?)', html, re.S) + cards = re.findall(r'
]*>(.*?)
', html, re.S) self.assertTrue(cards) self.assertIn("Example", cards[0]) tree = html.split('data-tree="nav-' + ("agent" if url == "/agents" else "capability") + '"', 1)[1] @@ -82,9 +82,16 @@ def test_bundled_agents_use_shared_marks(self): self.assertIn(f'/static/catalogue/agents/{key}.svg', html) self.assertIn('/static/brand/marks.svg#openai', html) self.assertIn('/static/brand/marks.svg#harbor', html) - # Personal entries without a bundled mark remain legible. + # Beside the logos, an agent without one shows its initials; where none has a logo, no card has an icon. + self.assertIn('', html) fixture_html = self.get("/agents").get_data(as_text=True) - self.assertIn('std-mark small', fixture_html) + self.assertIn('', fixture_html) + self.assertNotIn('std-mark', fixture_html) + with patch.object(definitions, "load", _LOAD): + capabilities = self.get("/capabilities").get_data(as_text=True) + self.assertNotIn('std-mark', capabilities) # capabilities have no logos: no letters either + self.assertIn('', page) # the family's pills, no button + self.assertIn('', page) + self.assertNotIn('data-filter-menu', page) + self.assertNotIn('data-tools-btn="filter"', page) + self.assertIn('data-keys="agent-task-v1" data-f-family="agent "', page) + self.assertIn('', page) + self.assertIn('
Checks
3
', page) + self.assertNotIn('bench-card-title">Agents", html) card = html[html.index('id="fake"'):] self.assertIn('href="/agents/fake"', card) - self.assertIn("2/7ports proven", card) # task and workspace, of the seven agent ports - self.assertIn("1/1benchmarks it runs", card) - self.assertNotIn("agent.task/v1", card[:card.index("")]) # the detail is on its page + self.assertIn("
Ports proven
2/7
", card) # task and workspace, of the seven agent ports + self.assertIn("
Benchmarks it runs
1/1
", card) + self.assertNotIn("agent.task/v1", card[:card.index("")]) # the detail is on its page self.assertEqual(self.get("/agents/nope").status_code, 404) def test_the_add_dialog_builds_a_prompt_and_keeps_the_steps_by_hand_for_each_kind(self): diff --git a/app/ui_tests/test_benchmark_new.py b/app/ui_tests/test_benchmark_new.py index 0d0a49cb..390c3a87 100644 --- a/app/ui_tests/test_benchmark_new.py +++ b/app/ui_tests/test_benchmark_new.py @@ -262,10 +262,10 @@ def test_a_harbor_route_joins_a_benchmark_the_standard_runs_as_one_card(self): self.assertEqual(Path(self.root, "benchmarks", "longmemeval", name).read_bytes(), content) self.assertFalse(os.path.exists(os.path.join(self.root, "benchmarks", "code-bench"))) # no second entry cards = self.get("/benchmarks").get_data(as_text=True) - self.assertEqual(cards.count('")] + self.assertEqual(cards.count('")] self.assertEqual([x for x in ("rt-harbor", "rt-standard", "rt-runner") if x in card], ["rt-harbor", "rt-standard"]) node = shutil.which("node") if node: # its Harbor dataset opens a Harbor recipe, its own the standard's diff --git a/app/ui_tests/test_cards.py b/app/ui_tests/test_cards.py new file mode 100644 index 00000000..85a1d96d --- /dev/null +++ b/app/ui_tests/test_cards.py @@ -0,0 +1,189 @@ +"""The card toolkit: its macros (templates/_cards.html) as a page renders them, and its script +(NulliusTable.cards in static/tables.js) run under Node on the table toolkit's stand-in DOM.""" +import re +import unittest + +import jinja2 + +from .test_tables import APP, node + +# One field of each slot, given in an order unlike the card's. +COLS = [dict(key='stat1', label='Tasks', card='stat'), dict(key='alert', label='Blocker', card='alert'), + dict(key='title', label='Name', card='title'), dict(key='act', label='Open', card='action'), + dict(key='stat2', label='Scored by', card_label='Scorer', card='stat', **{'class': 'word'}), + dict(key='note', label='Needs', card='note', icon='wrench'), dict(key='badge', label='Runs with', card='badge', **{'class': 'run-tag'}), + dict(key='text', label='About', card='text', style='code'), dict(key='icon', label='Logo', card='icon', **{'class': 'bench-mark'}), + dict(key='check', label='Pick', card='check'), dict(key='meta', label='Version', card='meta'), + dict(key='tag', label='Kind', card='tag', **{'class': 'cat-tag'}), dict(key='status', label='State', card='status'), + dict(key='hidden', label='Only in a table')] +FULL = {'href': '/a', 'id': 'a', 'search': 'Alpha one', 'keys': 'a', 'stat1': {'text': 5, 'label': 'Tasks each'}, 'alert': 'Blocked', + 'title': 'Alpha', 'act': {'text': 'Open', 'href': '/a/open'}, 'stat2': 'tests', 'note': {'text': 'needs docker', 'title': 'Install docker'}, + 'badge': [{'text': 'Nullius', 'class': 'rt-standard'}, 'Harbor'], 'text': 'a.port/v1', 'icon': '/m.svg#bm-a', + 'check': {'text': 'Pick Alpha', 'value': 'a'}, 'meta': 'v1', 'tag': 'coding', 'status': 'ready', 'hidden': 'never on a card'} + + +class Macros(unittest.TestCase): + env = jinja2.Environment(loader=jinja2.FileSystemLoader(APP / "templates"), autoescape=True) + + def render(self, cols, items, **kw): + return re.sub(r">\s+<", "><", self.env.from_string("{% from '_cards.html' import cards %}{{ cards('c', cols, items, **kw) }}") + .render(cols=cols, items=items, kw=kw)) + + def test_slots_come_in_their_order_and_a_field_without_one_stays_off(self): + html = self.render(COLS, [FULL]) + order = ['>ready<', 'class="cat-tag">coding<', 'class="bench-harness">v1<', 'aria-label="Pick Alpha"', 'href="/m.svg#bm-a"', + 'class="card-link" href="/a">Alpha<', 'a.port/v1', 'class="run-tag rt-standard">Nullius<', 'class="run-tag">Harbor<', + 'title="Install docker">needs docker<', + '
Tasks each
5
Scorer
tests
', + 'class="bench-card-blocker">Blocked<', '
Open'] + at = [html.index(part) for part in order] + self.assertEqual(at, sorted(at)) + self.assertNotIn('never on a card', html) + self.assertIn('
', html) + self.assertEqual(html.count('
Tasks
0
', html) # a zero is a value + self.assertNotIn('bench-stats', self.render(COLS[2:3], [{'href': '/b', 'title': 'Beta'}])) + + def test_one_title_at_most_one_text_and_three_stats(self): + title, stat, text = COLS[2], COLS[0], COLS[7] + for cols in ([stat], [title, title], [title, text, text], [title] + [stat] * 4, [title, COLS[8], COLS[8]]): + with self.subTest(cols=[c['card'] for c in cols]), self.assertRaises(jinja2.UndefinedError): + self.render(cols, [FULL]) + self.render([title] + [stat] * 3, [FULL]) + + def test_initials_only_beside_a_real_icon(self): + cols = [COLS[8], COLS[2]] + html = self.render(cols, [{'href': '/a', 'title': 'Alpha', 'icon': '/logo.svg'}, {'href': '/b', 'title': 'beta'}]) + self.assertIn('', html) + self.assertIn('', html) + html = self.render(cols, [{'href': '/a', 'title': 'Alpha'}, {'href': '/b', 'title': 'Beta', 'icon': None}]) + self.assertNotIn('aria-hidden="true"><', html.split('data-cards>')[1]) # no icon slot at all + + def test_values_are_escaped(self): + bad = '"' + html = self.render(COLS, [dict(FULL, title=bad, text=bad, search=bad, tag={'text': bad, 'title': bad}, stat2=bad, href='/"x')], + choices={'tag': [(bad, bad)]}) + self.assertNotIn('