diff --git a/heart/dashboard.py b/heart/dashboard.py index 096b7730..b7485d23 100644 --- a/heart/dashboard.py +++ b/heart/dashboard.py @@ -1882,24 +1882,26 @@ def _md_escape(text: str) -> str: return text.replace("|", "\\|") -def _copy_btn(payload: str, label: str = "copy", face: str = "copy prompt") -> str: - """A one-tap clipboard button (the PyAutoMind dashboard pattern): tap it - and the payload — a Claude prompt or a command — is ready to paste. - - ``face`` is what the button shows: the bare 📋 for a chip beside a row, a - short worded face (⌨ command chain) where the board offers more than one - payload and the reader has to choose between them. - - A worded face takes the theme's `text` modifier. The base `button.copy` is - a fixed 2.6rem SQUARE — right for a bare glyph, and a trap for words: the - label wrapped inside 42px into a one-word-per-line column and spilled out - of its own box. Whitespace in the face is the test, because that is what - makes a face a phrase rather than a glyph. - """ +def _copy_btn(payload: str, label: str = "copy", face: str = "copy prompt", + *, icon: bool = False) -> str: + """Copy a payload with either a named action or an accessible icon.""" cls = "copy text" if len(face.split()) > 1 else "copy" + content = _html.escape(face) + if icon: + cls = "copy icon" + # Terminal for commands; clipboard for prompts. SVGs remain decorative: + # the button itself supplies the accessible name and tooltip. + path = ('' if face == "copy command" else + '' + '') + content = ('' + path + '') + label = f"{face}: {label}" return (f"") + f"aria-label='{_html.escape(label, quote=True)}' " + f"data-cmd=\"{_html.escape(payload, quote=True)}\">{content}") def _html_reason(item: dict) -> str: @@ -1926,8 +1928,7 @@ def _html_reason(item: dict) -> str: _VERDICT_TONE = {"red": "bad", "yellow": "warn", "stale": "warn", "green": "ok"} -_LEDE = ('[these guys are giving me life]
' - 'Is it safe to release? See what needs attention, then copy a prompt ' +_LEDE = ('Is it safe to release? See what needs attention, then copy a prompt ' 'to work through it in your coding chat.') # The page-specific shapes the shared sheet has no opinion on: the per-row @@ -1935,16 +1936,35 @@ def _html_reason(item: dict) -> str: # variables, so this board follows the family accent rather than setting a # second palette. _EXTRA_CSS = """ -table.board td.dot{width:1.15rem;padding-right:.35rem} -table.board td.dot::before{content:"";display:inline-block;width:10px; - height:10px;border-radius:50%;margin-top:.35rem;background:var(--muted)} -table.board tr.ok td.dot::before{background:var(--ok)} -table.board tr.warn td.dot::before{background:var(--warn)} -table.board tr.fail td.dot::before{background:var(--bad)} -table.board tr.info td.dot::before{background:var(--muted)} -table.board td.name{font-weight:600;white-space:nowrap} -table.board tr.unobs td.name,table.board tr.unobs td.sum{color:var(--muted)} -/* Details use readable prose; numeric fields get structural emphasis. */ +/* All check categories share one compact disclosure grid. */ +.board{border:1px solid var(--line);border-radius:10px;overflow:hidden} +.check-row{position:relative;border-bottom:1px solid var(--line)} +.check-row:last-child{border-bottom:0} +.check{min-width:0;margin:0} +.check > summary{display:grid;grid-template-columns:.8rem .7rem 12rem minmax(0,1fr); + align-items:center;gap:.65rem;list-style:none;padding:.7rem 7rem .7rem .8rem;min-height:3.3rem; + box-sizing:border-box} +.check > summary::-webkit-details-marker{display:none} +.check > summary::before{content:"›";font-size:1.3rem;color:var(--muted)} +.check[open] > summary::before{transform:rotate(90deg)} +.check > summary:hover{background:var(--btn)} +.check .dot{width:10px;height:10px;border-radius:50%;background:var(--muted)} +.check-row.ok .dot{background:var(--ok)} +.check-row.warn .dot{background:var(--warn)} +.check-row.fail .dot{background:var(--bad)} +.check .name{font-weight:650;overflow-wrap:normal;white-space:nowrap} +.check .sum{font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} +.check-row.unobs .name,.check-row.unobs .sum{color:var(--muted)} +.check-body{padding:0 1rem 1rem 3.5rem;min-width:0} +.row-actions{position:absolute;top:0;right:0;display:flex;justify-content:flex-end;gap:.25rem;padding:.25rem .5rem} +body button.copy.icon{display:inline-flex;align-items:center;justify-content:center; + width:44px;height:44px;min-width:44px;min-height:44px;padding:0} +.copy.icon svg{pointer-events:none} +.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px; + overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0} +.repo-lines{list-style:none;padding:0} +.repo-lines li{display:flex;gap:1rem;flex-wrap:wrap;margin:.5rem 0} +.repo-lines strong{min-width:12rem} ul.det{margin:.6rem 0 0;padding-left:1.2rem;color:var(--fg); font-size:1rem;white-space:normal;line-height:1.65} ul.det li{margin:.5rem 0;overflow-wrap:anywhere} @@ -1968,35 +1988,22 @@ def _html_reason(item: dict) -> str: .reasons li{margin:.3rem 0} .hint{color:var(--muted);font-size:.85em;margin:.5rem 0 0} footer{margin-top:2rem;color:var(--muted);font-size:.82em} -/* Narrow screens: the shared theme turns a table row into a stacked card - (`table.recent` under its own breakpoint); these three lines say how THIS - board's cells fall into it. Measured at a 390px viewport before: the name - column held 127px for one short line while the summary was squeezed into - 213px and ran 472px down the screen — the text bunched to the right with - the name column left as empty height beside it. Now the dot and the name - read as one header line and the summary takes the full width beneath. */ -@media(max-width:34rem){ - table.board td.dot{width:auto;padding-right:.4rem} - table.board td.dot::before{margin-top:0} - table.board td.name{white-space:normal} - table.board td.sum{flex:1 0 100%;margin-top:.15rem} - table.board ul.det{padding-left:.9rem} +@media(max-width:48rem){ + .check > summary{grid-template-columns:.8rem .7rem minmax(0,1fr);gap:.45rem} + .check .sum{grid-column:3;white-space:normal} + .check .name{white-space:normal} + .check-body{padding:.2rem .8rem .8rem} } + """ _EXTRA_CSS += """ h2,h3{color:var(--fg);border-color:var(--line)} h2::after{display:none} -.lyric{display:inline-block;font-size:1.15rem;margin-bottom:.65rem} -table.board td,table.board summary{font-size:1rem;line-height:1.55} -/* The table algorithm otherwise gives this column its one-character minimum - width (body defaults to overflow-wrap:anywhere), splitting Libraries and - Worktree drift even on tablet screens. The phone rows already stack. */ -table.board td.name{white-space:nowrap;overflow-wrap:normal} summary{cursor:pointer;overflow-wrap:anywhere;white-space:normal;padding:.6rem 0; color:var(--fg)} summary:focus-visible,button:focus-visible{outline:3px solid var(--fg);outline-offset:3px} -body button.copy,body table.board button.copy.text{min-width:44px;min-height:44px; +body button.copy{min-width:44px;min-height:44px; width:auto;height:auto;padding:.55rem .8rem;white-space:normal;font-size:1rem; overflow:visible;text-overflow:clip} .actions{display:flex;gap:.65rem;flex-wrap:wrap;margin:1rem 0} @@ -2056,7 +2063,7 @@ def _html_reason(item: dict) -> str: def _html_entries(entries: list[dict]) -> str: - attention, other = [], [] + rows = [] for entry in entries: e = lambda value: _html.escape(str(value or "")) impact = ("Release blocker" if entry.get("release_severity") == "red" else @@ -2075,15 +2082,8 @@ def _html_entries(entries: list[dict]) -> str: f' · {impact}
{e(entry.get("reason"))}{link} {button}' f'
Observation source{e(entry.get("source"))}' f' · {e(entry.get("observed_at") or "time unknown")}
') - (attention if entry.get("state") in (FAIL, WARN) else other).append(row) - if not attention: - return '
    ' + ''.join(other) + '
' - result = '
    ' + ''.join(attention[:3]) + '
' - for label, rows in (("more findings", attention[3:]), ("passing / informational observations", other)): - if rows: - result += (f'
Show {len(rows)} {label}' - '
    ' + ''.join(rows) + '
') - return result + rows.append(row) + return '
    ' + ''.join(rows) + '
' def _html_score(board: Board) -> str: @@ -2130,40 +2130,61 @@ def _render_html(board: Board) -> str: rows = [] for sec in board.sections: cls = _STATE_HTML[sec.state] - summary = _html.escape(sec.summary) - if sec.observed_ago: - summary += f" · {_html.escape(sec.observed_ago)}" + actions, links = [], [] for link in sec.links: - summary += (f" " - f"{_html.escape(str(link.get('label', 'link')))} ↗") + links.append(f'' + f'{_html.escape(str(link.get("label", "link")))} ↗') if link.get("prompt"): - summary += " " + _copy_btn(str(link["prompt"]), - "copy the fix prompt for a Claude Code chat") + links.append(_copy_btn(str(link["prompt"]), + str(link.get("label", sec.title)), icon=True)) if sec.action and sec.action.get("payload"): payload = str(sec.action["payload"]) - summary += " " + _copy_btn(payload, - str(sec.action.get("label", "copy")), - "copy command" if payload.startswith("pyauto-heart ") - else "copy prompt") - details = "" + actions.append(_copy_btn(payload, str(sec.action.get("label", sec.title)), + "copy command" if payload.startswith("pyauto-heart ") + else "copy prompt", icon=True)) + if not actions: + prompt = (f'/health Review the Heart dashboard category "{sec.title}". ' + f'Current summary: {sec.summary}. Inspect the latest evidence; ' + 'refresh missing or expired observations before proposing repairs. ' + 'Route confirmed repairs through the development workflow. ' + 'This is not approval to merge or release.') + actions.append(_copy_btn(prompt, sec.title, icon=True)) if sec.timing_html: details = sec.timing_html - elif sec.entries: - opened = " open" if sec.state in (FAIL, WARN) else "" - details = (f'{_html.escape(sec.title)} — ' - f'observations ({len(sec.entries)}){_html_entries(sec.entries)}') - elif sec.details: - items = "".join(f"
  • {d}
  • " for d in - (sec.detail_html or [_html.escape(d) for d in sec.details])) - opened = " open" if sec.state in (FAIL, WARN) else "" - details = (f"{_html.escape(sec.title)} — " - f"details ({len(sec.details)})
      {items}
    ") + elif sec.entries and sec.key not in ("libraries", "workspaces"): + details = _html_entries(sec.entries) + else: + if sec.key in ("libraries", "workspaces"): + items = [] + for line in sec.details: + name, _, reason = line.partition(" ") + items.append(f'
  • {_html.escape(name)}' + f'{_html.escape(reason.strip())}
  • ') + details = '
      ' + ''.join(items) + '
    ' + if sec.entries: + details += ('
    Observation sources and actions' + + _html_entries(sec.entries) + '
    ') + else: + items = "".join(f"
  • {d}
  • " for d in + (sec.detail_html or [_html.escape(d) for d in sec.details])) + details = f'
      {items}
    ' if items else '' + if sec.observed_ago: + details = f'

    {_html.escape(sec.observed_ago)}

    ' + details + if links: + details += '

    ' + ' · '.join(links) + '

    ' + if not details: + details = '

    No further observations recorded.

    ' state_label = {OK: "Passing", WARN: "Warning", FAIL: "Needs attention", INFO: "Information", UNOBS: "Not observed here"}[sec.state] rows.append( - f"" - f"{_html.escape(sec.title)}" - f"{state_label} · {summary}{details}" + f'
    ' + f'' + f'{_html.escape(sec.title)}' + f'{state_label}: ' + f'{_html.escape(sec.summary)}' + f'
    {details}
    ' + f'
    {"".join(actions)}
    ' ) reasons_html = "" for severity, label in (("red", "Release blockers"), ("yellow", "Warnings"), @@ -2201,6 +2222,9 @@ def _render_html(board: Board) -> str: {hero} +

    Observed checks

    +

    Expand a check to see its entries. Colours describe observations; the release verdict below determines readiness.

    +
    {''.join(rows)}

    {word} · score {board.score}snapshot {_html.escape(board.ts)} · {age} · markdown version{github_link}

    @@ -2212,9 +2236,6 @@ def _render_html(board: Board) -> str: {len(board.yellow_reasons)} warnings · {len(board.stale_reasons)} evidence gaps

    {_html_actions(board)} {reasons_html} -

    Observed checks

    -

    Section colours describe observations. The release verdict above determines readiness.

    -{''.join(rows)}
    {_boards_nav_html()}
    Copy a prompt into your coding chat, or a command into your terminal. Copying does not run a check or change any files.
    diff --git a/tests/test_dashboard_disclosures.py b/tests/test_dashboard_disclosures.py new file mode 100644 index 00000000..e7b155c5 --- /dev/null +++ b/tests/test_dashboard_disclosures.py @@ -0,0 +1,122 @@ +"""The overview stays compact while every observation remains reachable.""" +from html.parser import HTMLParser + +from heart import dashboard +from tests.test_dashboard import ( + FRESH_NOW, _legacy_import, _lib, _unit_timings_slice, + make_snapshot, make_verdict, +) + + +class Node: + def __init__(self, tag='', attrs=()): + self.tag, self.attrs, self.children = tag, dict(attrs), [] + + def find(self, tag=None, cls=None): + for child in self.children: + if isinstance(child, Node): + if ((tag is None or child.tag == tag) and + (cls is None or cls in child.attrs.get('class', '').split())): + yield child + yield from child.find(tag, cls) + + def text(self): + return ''.join(c.text() if isinstance(c, Node) else c for c in self.children) + + +class Page(HTMLParser): + def __init__(self, html): + super().__init__() + self.root = Node() + self.stack = [self.root] + self.feed(html) + assert len(self.stack) == 1, 'Unclosed HTML elements' + + def handle_starttag(self, tag, attrs): + node = Node(tag, attrs) + self.stack[-1].children.append(node) + if tag not in {'meta', 'br', 'hr', 'input', 'img', 'link'}: + self.stack.append(node) + + def handle_endtag(self, tag): + assert self.stack[-1].tag == tag, (self.stack[-1].tag, tag) + self.stack.pop() + + def handle_data(self, data): + self.stack[-1].children.append(data) + + +def test_all_categories_start_collapsed_with_summary_and_separate_named_icons(): + board = dashboard.build_board(make_snapshot(), make_verdict(), now=FRESH_NOW) + # Include every severity, an empty category, and both clipboard types. + board.sections = [dashboard.Section( + f'category-{state}', f'Category {state}', state, 'A short state summary.', + action={'payload': 'pyauto-heart fix drift', 'label': 'Inspect drift'} + if state == dashboard.WARN else None, + ) for state in (dashboard.OK, dashboard.WARN, dashboard.FAIL, + dashboard.INFO, dashboard.UNOBS)] + root = Page(dashboard._render_html(board)).root + rows = list(root.find(cls='check-row')) + assert len(rows) == len(board.sections) + for row, section in zip(rows, board.sections): + check = next(row.find('details', 'check')) + assert 'open' not in check.attrs + summary = next(check.find('summary')) + assert section.title in summary.text() and section.summary in summary.text() + assert not list(summary.find('button')) and not list(summary.find('a')) + actions = next(row.find(cls='row-actions')) + buttons = list(actions.find('button')) + assert buttons + for button in buttons: + assert button.attrs['aria-label'] == button.attrs['title'] + assert button.attrs['data-cmd'] + assert button.text() == '' # icons, not visible word labels + svg = next(button.find('svg')) + assert svg.attrs['aria-hidden'] == 'true' + assert not list(check.find(cls='row-actions')) + + +def test_libraries_reveal_all_six_compact_repo_lines_and_observation_sources(): + snapshot = make_snapshot() + snapshot['repos']['FixtureLibrary'] = _lib('failure') + board = dashboard.build_board(snapshot, make_verdict(), now=FRESH_NOW, + unobserved=('repo_state',)) + root = Page(dashboard._render_html(board)).root + check = next(n for n in root.find('details', 'check') + if n.attrs['id'] == 'check-libraries') + lines = list(next(check.find(cls='repo-lines')).find('li')) + assert len(lines) == 6 + for line in lines: + assert 'CI' in line.text() and 'repo state n/a here' in line.text() + assert any('FixtureLibrary' in line.text() for line in lines) + entries = list(check.find('li', 'entry')) + assert len(entries) == len(next(s for s in board.sections if s.key == 'libraries').entries) + assert 'Observation source' in check.text() + + +def test_timing_cards_are_inside_category_and_checks_precede_score_actions_gaps(): + board = dashboard.build_board( + make_snapshot(unit_timings=_unit_timings_slice(), import_time=_legacy_import()), + dict(make_verdict('stale'), stale_reasons=['install verification not run'], + stale_details=[{'key': 'install_unknown'}]), now=FRESH_NOW) + html = dashboard._render_html(board) + root = Page(html).root + checks = list(root.find('details', 'check')) + timing = next(c for c in checks if c.attrs['id'] == 'check-import_time') + assert 'open' not in timing.attrs + assert list(timing.find(cls='timing-card')) + assert all('timing-card' not in n.attrs.get('class', '') + for c in checks for n in next(c.find('summary')).find()) + assert (html.index('
    ') < html.index('Why this score:') < + html.index('Fix Heart systematically') < html.index('Evidence gaps (')) + assert '[these guys are giving me life]' not in html + + +def test_icon_copy_payloads_round_trip_quotes_newlines_and_markup(): + payload = '/health Inspect "repo"\nKeep & don\'t execute it.' + for face in ('copy command', 'copy prompt'): + root = Page(dashboard._copy_btn(payload, 'Inspect "repo"', face, icon=True)).root + button = next(root.find('button')) + assert button.attrs['data-cmd'] == payload + assert button.attrs['aria-label'].startswith(face + ': ') + assert button.attrs['title'].endswith('Inspect "repo"') diff --git a/tests/test_dashboard_reasons.py b/tests/test_dashboard_reasons.py index 1526eb16..788b0477 100644 --- a/tests/test_dashboard_reasons.py +++ b/tests/test_dashboard_reasons.py @@ -150,10 +150,10 @@ def test_validation_actions_and_json_contract_remain_separate(): assert {r["severity"] for r in payload["blockers"]} <= {"red", "yellow", "stale"} -def test_large_inventory_discloses_rest_without_losing_entries(): +def test_expanded_category_shows_complete_inventory_without_another_disclosure(): rows = [{"subject": f"Repo{i}", "reason": "behind origin", "state": "warn", "affects_release": False} for i in range(12)] html = dashboard._html_entries(rows) - assert "Show 9 more findings" in html + assert "more findings" not in html assert html.count('class="entry warn"') == 12 - assert html.index("Repo2") < html.index("Show 9 more findings") < html.index("Repo3") + assert html.index("Repo2") < html.index("Repo3") < html.index("Repo11") diff --git a/tests/test_fix.py b/tests/test_fix.py index 52acafc2..27799289 100644 --- a/tests/test_fix.py +++ b/tests/test_fix.py @@ -88,7 +88,7 @@ def test_html_all_tiers_complete_disclosure_and_safe_fallback(): assert '' not in html assert 'role="status" aria-live="polite"' in html assert 'class="prompt-fallback"' in html - assert "[these guys are giving me life]" in html + assert "[these guys are giving me life]" not in html assert html.index("Fix Heart systematically") < html.index("Release blockers (12)")