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
19 changes: 19 additions & 0 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,22 @@ Cloud observations take precedence for families the cloud actually measured;
otherwise published findings fill the gap. Missing or malformed inventories
remain unknown, and neither aggregate time nor publication time refreshes old
or undated evidence. This transport does not change release readiness.

## Test-workspace resource view

The dashboard CLI loads resources.json (or --resources), a generated public
Scientist catalogue, and displays explicit `tests` relationships against cached
repository CI observations. It never infers test ownership from suffixes or
changes readiness. Per-workflow outcomes, observed time and source revision are
shown when supplied; test-level counts/coverage are explicitly unavailable.
Evidence older than 24 hours is labelled outdated for this navigation view;
adverse conclusions remain visible. This display threshold is not a release gate.

Regenerate the catalogue offline using Scientist's `--catalogue --repos
<PathToMind>/repos.yaml` export, review it, then replace resources.json only after
successful validation. The same export feeds Broca. Relationships and identities
remain owned by Scientist and Mind; this file is a derived public snapshot, not a
hand-maintained registry. Missing catalogues do not affect readiness. Rendering
collects no new evidence, and opening a disclosure triggers no execution.

Resource CI is displayed only when available run URLs match the catalogue canonical GitHub repository. A reused local key, absent run provenance or foreign workflow URL cannot establish resource health; those rows show unavailable.
19 changes: 18 additions & 1 deletion heart/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ class Board:
refreshed_at: str | None = None


resource_catalogue: dict | None = None
resource_repos: dict = field(default_factory=dict)
resource_now: datetime.datetime | None = None

# --- verdict/state → glyph & colour maps ------------------------------------
_VERDICT_STATE = {"red": FAIL, "yellow": WARN, "stale": INFO, "green": OK}
_VERDICT_WORD = {"red": "RED", "yellow": "YELLOW", "stale": "STALE", "green": "GREEN"}
Expand Down Expand Up @@ -683,6 +687,7 @@ def build_board(
now: datetime.datetime | None = None,
stale_after: int = STALE_AFTER_SECONDS,
devbox: dict | None = None,
resource_catalogue: dict | None = None,
) -> Board:
"""Assemble the format-agnostic :class:`Board`. Pure; never raises."""
snapshot = _portable_cached_prompts(snapshot or {})
Expand Down Expand Up @@ -1113,6 +1118,9 @@ def build_board(
"and timeouts, and route confirmed repairs through the bug and start-dev skills."}

board = Board(
resource_catalogue=resource_catalogue,
resource_repos=repos,
resource_now=now,
verdict=v,
score=score,
ts=ts,
Expand Down Expand Up @@ -2283,6 +2291,8 @@ def _html_actions(board: Board) -> str:


def _render_html(board: Board) -> str:
from heart.resources import render as render_resources
resource_html = render_resources(board.resource_catalogue, board.resource_repos, now=board.resource_now) if board.resource_catalogue is not None else ""
word = _VERDICT_WORD.get(board.verdict, "GREEN")
age = format_age(board.age_seconds, stale=board.stale)
rows = []
Expand Down Expand Up @@ -2407,6 +2417,7 @@ def _render_html(board: Board) -> str:
<body>
{hero}
{panel}
{resource_html}
<h2 id="observed-checks">Observed checks</h2>
<div class="board">{''.join(rows)}</div>
<section aria-labelledby="score-heading">
Expand Down Expand Up @@ -2607,11 +2618,13 @@ def render(
quiet: bool = False,
stale_after: int = STALE_AFTER_SECONDS,
devbox: dict | None = None,
resource_catalogue: dict | None = None,
) -> str:
"""Render the unified board in ``fmt``. Pure: snapshot in → string out."""
board = build_board(
snapshot, verdict, validation,
unobserved=unobserved, now=now, stale_after=stale_after, devbox=devbox,
resource_catalogue=resource_catalogue,
)
if fmt == "term":
return _render_term(board, verdict or {}, quiet=quiet)
Expand Down Expand Up @@ -2643,6 +2656,7 @@ def main(argv: list[str] | None = None) -> int:
"""
import argparse
import os
import pathlib

from heart import readiness, state

Expand All @@ -2662,6 +2676,7 @@ def main(argv: list[str] | None = None) -> int:
ap.add_argument("--devbox", metavar="PATH", default=None,
help="published dev-box board JSON to fill unobserved rows "
"(default under --cloud: state/devbox_board.json if present)")
ap.add_argument("--resources", type=pathlib.Path, default=pathlib.Path(__file__).resolve().parents[1] / "resources.json", help="Scientist public resource catalogue")
ap.add_argument("--quiet", action="store_true", help="suppress drill-down details (term)")
ap.add_argument("--no-color", action="store_true", help="disable ANSI colours")
ap.add_argument("--stale-after", type=int, default=STALE_AFTER_SECONDS,
Expand Down Expand Up @@ -2723,8 +2738,10 @@ def main(argv: list[str] | None = None) -> int:
print(json.dumps(badge_endpoint(board)))
return 0

from heart.resources import load as load_resources
resource_catalogue = load_resources(ns.resources) if fmt == "html" and ns.resources.is_file() else None
print(render(snapshot, verdict, validation, fmt=fmt, unobserved=unobserved,
quiet=ns.quiet, stale_after=ns.stale_after, devbox=devbox))
quiet=ns.quiet, stale_after=ns.stale_after, devbox=devbox, resource_catalogue=resource_catalogue))
return 0


Expand Down
70 changes: 70 additions & 0 deletions heart/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Read-only test-workspace view; catalogue is Scientist's public projection."""
from datetime import datetime, timezone
import html
import json
from pathlib import Path
from urllib.parse import urlsplit


def load(path):
data = json.loads(Path(path).read_text())
if data.get('schema_version') != 1 or not isinstance(data.get('resources'), list):
raise ValueError('invalid public resource catalogue')
return data


def link(url, label):
parsed = urlsplit(str(url))
if parsed.scheme != 'https' or not parsed.hostname or parsed.username or parsed.password:
return html.escape(str(label))
return f'<a href="{html.escape(str(url), quote=True)}">{html.escape(str(label))}</a>'


def verified_ci(ci, github):
"""A reused local key cannot establish which remote produced cached runs."""
urls = [ci.get('url')] + [entry.get('url') for entry in (ci.get('workflows') or {}).values()]
urls = [url for url in urls if url]
if not github or not urls:
return {}
for url in urls:
parsed = urlsplit(str(url))
parts = parsed.path.strip('/').split('/')
if (parsed.scheme != 'https' or parsed.netloc.lower() != 'github.com'
or len(parts) < 5 or '/'.join(parts[:2]).lower() != github.lower()
or parts[2:4] != ['actions', 'runs'] or not parts[4].isdigit()):
return {}
return ci


def render(catalogue, repos, *, now=None):
esc = lambda value: html.escape(str(value), quote=True)
cards = []
now = now or datetime.now(timezone.utc)
for resource in (catalogue or {}).get('resources', []):
if 'tests' not in resource.get('relations', []):
continue
name = resource.get('repo', '')
ci = verified_ci((repos.get(name) or {}).get('ci_status') or {}, resource.get('github'))
state = ci.get('conclusion') or ci.get('status') or 'unavailable'
observed = ci.get('ts') or 'Unknown'
freshness = 'Age unknown'
try:
age = (now - datetime.fromisoformat(observed.replace('Z', '+00:00'))).total_seconds()
freshness = ('Evidence outdated' if age > 86400 else 'Observed within 24 hours') if age >= 0 else 'Observation time is in the future'
except (ValueError, TypeError):
pass
projects = ', '.join(p['name'] for p in resource['projects'])
sources = ' · '.join(link(l['url'], l['label']) for l in resource['links'])
workflows = []
for workflow, evidence in (ci.get('workflows') or {}).items():
status = evidence.get('conclusion') or evidence.get('status') or 'unknown'
workflows.append(f'<li>{link(evidence.get("url", ""), workflow)}: {esc(status)}</li>')
detail = ('<ul>' + ''.join(workflows) + '</ul>') if workflows else '<p>No workflow-level evidence available.</p>'
cards.append(f'''<details id="resource-{esc(resource['id'])}"><summary>{esc(resource['name'])} · {esc(projects)} · CI: {esc(state)} · {esc(freshness)}</summary>
<p>Regression, smoke and parity checks for {esc(projects)}. Source remains in the test workspace.</p>
<p>{sources} · {link(ci.get('url', ''), 'Latest recorded CI run')}</p>
<dl><dt>Observed</dt><dd>{esc(observed)} · {esc(freshness)}</dd><dt>Source revision</dt><dd>{esc(ci.get('head_sha') or ci.get('sha') or 'Unknown')}</dd></dl>
{detail}<p>Test-level counts and coverage are not supplied by this CI snapshot. CI is separate from full release validation; these rows do not change readiness.</p>
<p>Next: use Heart's check-in to inspect this workspace's latest run, missing evidence and failures before scheduling any check.</p></details>''')
return ('<section id="test-workspaces"><h2>Test workspaces</h2><p>Project-owned test suites and their recorded CI evidence. Inventory is not a passing result. CI without matching repository run provenance is unavailable. Evidence older than 24 hours is labelled outdated here; release gates retain their own policy.</p>'
+ ''.join(cards) + ('' if cards else '<p>No public test-workspace resources available.</p>') + '</section>')
Loading
Loading