Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions heart/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,11 +1923,6 @@ def _html_reason(item: dict) -> str:
return f"<li>{text}</li>"


# The Heart's verdict in the theme's tone vocabulary. The board's own
# `_VERDICT_STATE` stays the internal truth; this is only how it is painted.
_VERDICT_TONE = {"red": "bad", "yellow": "warn", "stale": "warn",
"green": "ok"}

_LEDE = ('Is it safe to release? See what needs attention, then copy a prompt '
'to work through it in your coding chat.')

Expand Down Expand Up @@ -2006,8 +2001,11 @@ def _html_reason(item: dict) -> str:
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}
.actions button{font-weight:650}
.score-value{display:flex;align-items:baseline;gap:.8rem;flex-wrap:wrap}
.score-value strong{font-size:1.5rem;font-variant-numeric:tabular-nums}
.repair{margin:0;min-width:0}
.repair > summary{padding:.85rem 7rem .85rem 1rem;min-height:3.3rem;box-sizing:border-box}
.repair pre{padding:0 1rem 1rem;margin:0}
.prompt-fallback pre,#copy-fallback{white-space:pre-wrap;overflow-wrap:anywhere;
max-height:24rem;overflow:auto;font-size:1rem;line-height:1.5;user-select:text}
.duration{font-weight:750;font-variant-numeric:tabular-nums;color:var(--fg)}
Expand Down Expand Up @@ -2113,15 +2111,17 @@ def _html_actions(board: Board) -> str:
plans = [("Fix Heart systematically", board.fix_plan or build_fix_plan(board))]
if board.stale_plan:
plans.append(("Refresh all missing evidence", board.stale_plan))
buttons = " ".join(_copy_btn(p["prompt"], f"copy prompt: {label}", label)
for label, p in plans)
fallbacks = "".join(
f'<details class="prompt-fallback"><summary>{label} — view / select prompt</summary>'
f'<pre tabindex="0">{_html.escape(plan["prompt"])}</pre></details>'
for label, plan in plans)
return (f'<div class="actions">{buttons}</div>'
rows = []
for label, plan in plans:
button = _copy_btn(plan["prompt"], label, icon=True)
rows.append(
'<div class="check-row repair-row">'
f'<details class="prompt-fallback repair"><summary>{_html.escape(label)}</summary>'
f'<pre tabindex="0">{_html.escape(plan["prompt"])}</pre></details>'
f'<div class="row-actions">{button}</div></div>')
return ('<div class="board repair-actions">' + ''.join(rows) + '</div>'
'<p id="copy-status" role="status" aria-live="polite"></p>'
'<pre id="copy-fallback" tabindex="-1" hidden></pre>' + fallbacks)
'<pre id="copy-fallback" tabindex="-1" hidden></pre>')


def _render_html(board: Board) -> str:
Expand Down Expand Up @@ -2225,16 +2225,23 @@ def _render_html(board: Board) -> str:
<h2>Observed checks</h2>
<p>Expand a check to see its entries. Colours describe observations; the release verdict below determines readiness.</p>
<div class="board">{''.join(rows)}</div>
<p class="verdict {_VERDICT_TONE.get(board.verdict, '')}"><b>{word} · score
{board.score}</b><span class="muted">snapshot {_html.escape(board.ts)} ·
{age} · <a href="dashboard.md">markdown version</a>{github_link}</span></p>
<section aria-labelledby="score-heading">
<h2 id="score-heading">Score</h2>
<p class="score-value"><strong>{board.score}/100</strong>
<span class="muted">Release readiness: {word}</span></p>
<p class="muted">snapshot {_html.escape(board.ts)} ·
{age} · <a href="dashboard.md">markdown version</a>{github_link}</p>
{stale_html}
<p class="vantage">{_html.escape(board.vantage)} ·
{_html.escape(board.devbox_observed or ('no dev-box observation attached' if board.vantage == 'cloud snapshot' else 'observed on this dev box'))}</p>
{_html_score(board)}
<p class="reason-counts">{len(board.red_reasons)} release blockers ·
{len(board.yellow_reasons)} warnings · {len(board.stale_reasons)} evidence gaps</p>
</section>
<section aria-labelledby="resusitate-heading">
<h2 id="resusitate-heading">Resusitate</h2>
{_html_actions(board)}
</section>
{reasons_html}
{_boards_nav_html()}
<footer>Copy a prompt into your coding chat, or a command into your terminal.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ def test_a_worded_copy_face_is_a_chip_and_a_glyph_stays_a_square():
assert is_chip == (len(face.split()) > 1), (cls, face)

faces = [f for _, f in buttons]
assert "Refresh all missing evidence" in faces
assert "Refresh all missing evidence" not in faces
assert "copy prompt: Refresh all missing evidence" in html
assert "copy prompt" in faces
assert all(len(face.split()) > 1 for face in faces)

Expand Down
49 changes: 48 additions & 1 deletion tests/test_dashboard_disclosures.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_all_categories_start_collapsed_with_summary_and_separate_named_icons():
) 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'))
rows = list(next(root.find(cls='board')).find(cls='check-row'))
assert len(rows) == len(board.sections)
for row, section in zip(rows, board.sections):
check = next(row.find('details', 'check'))
Expand Down Expand Up @@ -120,3 +120,50 @@ def test_icon_copy_payloads_round_trip_quotes_newlines_and_markup():
assert button.attrs['data-cmd'] == payload
assert button.attrs['aria-label'].startswith(face + ': ')
assert button.attrs['title'].endswith('Inspect "repo"')


def test_score_and_resusitate_sections_keep_breakdown_and_readiness():
verdict = dict(make_verdict('stale', 65),
stale_reasons=['Missing workspace report', 'Missing install evidence',
'Missing release validation'])
board = dashboard.build_board(make_snapshot(), verdict, now=FRESH_NOW)
board.penalties = [dict(key=key, points=points, count=1, weight=points, cap=points)
for key, points in [('test_unknown', 10), ('install_unknown', 10),
('validation_absent', 15)]]
root = Page(dashboard._render_html(board)).root
headings = [h.text() for h in root.find('h2')]
assert headings == ['Observed checks', 'Score', 'Resusitate', 'Evidence gaps (3)']
score = next(s for s in root.find('section')
if s.attrs.get('aria-labelledby') == 'score-heading')
assert '65/100' in score.text() and 'Release readiness: STALE' in score.text()
assert 'Why this score: 65/100' in score.text()
assert 'Missing workspace test report: −10 (1 × 10, cap 10)' in score.text()
assert 'Missing install verification: −10 (1 × 10, cap 10)' in score.text()
assert 'Missing release validation: −15 (1 × 15, cap 15)' in score.text()
assert '0 release blockers ·\n0 warnings · 3 evidence gaps' in score.text()
assert not list(root.find(cls='verdict'))


def test_repair_rows_copy_exact_prompts_without_toggling_prompt_disclosures():
for stale in (False, True):
verdict = dict(make_verdict('stale' if stale else 'green'),
stale_reasons=['install verification not run'] if stale else [],
stale_details=[{'key': 'install_unknown'}] if stale else [])
board = dashboard.build_board(make_snapshot(), verdict, now=FRESH_NOW)
root = Page(dashboard._render_html(board)).root
section = next(s for s in root.find('section')
if s.attrs.get('aria-labelledby') == 'resusitate-heading')
rows = list(section.find(cls='repair-row'))
plans = [board.fix_plan] + ([board.stale_plan] if stale else [])
assert len(rows) == len(plans)
for row, plan in zip(rows, plans):
details = next(row.find('details'))
assert 'open' not in details.attrs
label = next(details.find('summary')).text()
button = next(row.find('button'))
assert not list(details.find('button'))
assert button.attrs['aria-label'] == f'copy prompt: {label}'
assert button.attrs['data-cmd'] == plan['prompt']
assert next(details.find('pre')).text() == plan['prompt']
assert button.text() == '' and list(button.find('svg'))
assert next(section.find('p')).attrs['aria-live'] == 'polite'
2 changes: 1 addition & 1 deletion tests/test_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_html_all_tiers_complete_disclosure_and_safe_fallback():
assert "warning &lt;script&gt;unsafe&lt;/script&gt;" in html
assert '<script>unsafe</script>' not in html
assert 'role="status" aria-live="polite"' in html
assert 'class="prompt-fallback"' in html
assert 'class="prompt-fallback repair"' in html
assert "[these guys are giving me life]" not in html
assert html.index("Fix Heart systematically") < html.index("Release blockers (12)")

Expand Down
Loading