From 543f32ccf9c2b3212b123947b137f809c3b4bd3f Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Sun, 11 Oct 2026 18:41:42 +0100 Subject: [PATCH 1/2] Add project test-workspace dropdowns to Heart --- docs/internals.md | 17 + heart/dashboard.py | 19 +- heart/resources.py | 54 ++ resources.json | 845 +++++++++++++++++++++++++++++++ tests/test_resource_dropdowns.py | 38 ++ 5 files changed, 972 insertions(+), 1 deletion(-) create mode 100644 heart/resources.py create mode 100644 resources.json create mode 100644 tests/test_resource_dropdowns.py diff --git a/docs/internals.md b/docs/internals.md index 26dcc990..c6b310f9 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -196,3 +196,20 @@ 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 +/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. diff --git a/heart/dashboard.py b/heart/dashboard.py index 5ee5a03c..fbed2d17 100644 --- a/heart/dashboard.py +++ b/heart/dashboard.py @@ -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"} @@ -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 {}) @@ -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, @@ -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 = [] @@ -2407,6 +2417,7 @@ def _render_html(board: Board) -> str: {hero} {panel} +{resource_html}

Observed checks

{''.join(rows)}
@@ -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) @@ -2643,6 +2656,7 @@ def main(argv: list[str] | None = None) -> int: """ import argparse import os + import pathlib from heart import readiness, state @@ -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, @@ -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 diff --git a/heart/resources.py b/heart/resources.py new file mode 100644 index 00000000..84ba9b78 --- /dev/null +++ b/heart/resources.py @@ -0,0 +1,54 @@ +"""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'{html.escape(str(label))}' + + +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 = (repos.get(name) or {}).get('ci_status') or {} + 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'
  • {link(evidence.get("url", ""), workflow)}: {esc(status)}
  • ') + detail = ('
      ' + ''.join(workflows) + '
    ') if workflows else '

    No workflow-level evidence available.

    ' + cards.append(f'''
    {esc(resource['name'])} · {esc(projects)} · CI: {esc(state)} · {esc(freshness)} +

    Regression, smoke and parity checks for {esc(projects)}. Source remains in the test workspace.

    +

    {sources} · {link(ci.get('url', ''), 'Latest recorded CI run')}

    +
    Observed
    {esc(observed)} · {esc(freshness)}
    Source revision
    {esc(ci.get('head_sha') or ci.get('sha') or 'Unknown')}
    +{detail}

    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.

    +

    Next: use Heart's check-in to inspect this workspace's latest run, missing evidence and failures before scheduling any check.

    ''') + return ('

    Test workspaces

    Project-owned test suites and their recorded CI evidence. Inventory is not a passing result. Evidence older than 24 hours is labelled outdated here; release gates retain their own policy.

    ' + + ''.join(cards) + ('' if cards else '

    No public test-workspace resources available.

    ') + '
    ') diff --git a/resources.json b/resources.json new file mode 100644 index 00000000..78621a16 --- /dev/null +++ b/resources.json @@ -0,0 +1,845 @@ +{ + "schema_version": 1, + "resources": [ + { + "id": "fit", + "name": "PyAutoFit", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoFit" + } + ], + "repo": "PyAutoFit", + "github": "PyAutoLabs/PyAutoFit", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + }, + { + "id": "galaxy", + "name": "PyAutoGalaxy" + }, + { + "id": "lens", + "name": "PyAutoLens" + }, + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "software", + "dependencies" + ] + }, + { + "id": "nerves", + "name": "PyAutoNerves", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoNerves" + } + ], + "repo": "PyAutoNerves", + "github": "PyAutoLabs/PyAutoNerves", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + }, + { + "id": "array", + "name": "PyAutoArray" + }, + { + "id": "galaxy", + "name": "PyAutoGalaxy" + }, + { + "id": "lens", + "name": "PyAutoLens" + }, + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "dependencies" + ] + }, + { + "id": "fit-workspace", + "name": "autofit_workspace", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_workspace" + } + ], + "repo": "autofit_workspace", + "github": "PyAutoLabs/autofit_workspace", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "workspaces" + ] + }, + { + "id": "fit-tutorials", + "name": "HowToFit", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/HowToFit" + } + ], + "repo": "HowToFit", + "github": "PyAutoLabs/HowToFit", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "tutorials" + ] + }, + { + "id": "fit-docs", + "name": "PyAutoFit documentation", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoFit/tree/main/docs" + }, + { + "label": "Published", + "url": "https://pyautofit.readthedocs.io/en/latest/" + } + ], + "repo": "PyAutoFit", + "github": "PyAutoLabs/PyAutoFit", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "fit-assistant", + "name": "autofit_assistant", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_assistant" + } + ], + "repo": "autofit_assistant", + "github": "PyAutoLabs/autofit_assistant", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "assistants" + ] + }, + { + "id": "fit-profiling", + "name": "autofit_profiling", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_profiling" + } + ], + "repo": "autofit_profiling", + "github": "PyAutoLabs/autofit_profiling", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "profiling" + ] + }, + { + "id": "fit-inference", + "name": "autofit_inference", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_inference" + } + ], + "repo": "autofit_inference", + "github": "PyAutoLabs/autofit_inference", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "inference" + ] + }, + { + "id": "fit-visualization", + "name": "autofit_visualization", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_visualization" + } + ], + "repo": "autofit_visualization", + "github": "PyAutoLabs/autofit_visualization", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "visualization" + ] + }, + { + "id": "fit-tests", + "name": "autofit_workspace_test", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autofit_workspace_test" + } + ], + "repo": "autofit_workspace_test", + "github": "PyAutoLabs/autofit_workspace_test", + "projects": [ + { + "id": "fit", + "name": "PyAutoFit" + } + ], + "relations": [ + "tests" + ] + }, + { + "id": "array", + "name": "PyAutoArray", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoArray" + } + ], + "repo": "PyAutoArray", + "github": "PyAutoLabs/PyAutoArray", + "projects": [ + { + "id": "array", + "name": "PyAutoArray" + }, + { + "id": "galaxy", + "name": "PyAutoGalaxy" + }, + { + "id": "lens", + "name": "PyAutoLens" + }, + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "software", + "dependencies" + ] + }, + { + "id": "array-docs", + "name": "PyAutoArray documentation source", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoArray/tree/main/docs" + } + ], + "repo": "PyAutoArray", + "github": "PyAutoLabs/PyAutoArray", + "projects": [ + { + "id": "array", + "name": "PyAutoArray" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "galaxy", + "name": "PyAutoGalaxy", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoGalaxy" + } + ], + "repo": "PyAutoGalaxy", + "github": "PyAutoLabs/PyAutoGalaxy", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + }, + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "software", + "dependencies" + ] + }, + { + "id": "galaxy-workspace", + "name": "autogalaxy_workspace", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autogalaxy_workspace" + } + ], + "repo": "autogalaxy_workspace", + "github": "PyAutoLabs/autogalaxy_workspace", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "workspaces" + ] + }, + { + "id": "galaxy-tutorials", + "name": "HowToGalaxy", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/HowToGalaxy" + } + ], + "repo": "HowToGalaxy", + "github": "PyAutoLabs/HowToGalaxy", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "tutorials" + ] + }, + { + "id": "galaxy-docs", + "name": "PyAutoGalaxy documentation", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoGalaxy/tree/main/docs" + }, + { + "label": "Published", + "url": "https://pyautogalaxy.readthedocs.io/en/latest/" + } + ], + "repo": "PyAutoGalaxy", + "github": "PyAutoLabs/PyAutoGalaxy", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "galaxy-assistant", + "name": "autogalaxy_assistant", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autogalaxy_assistant" + } + ], + "repo": "autogalaxy_assistant", + "github": "PyAutoLabs/autogalaxy_assistant", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "assistants" + ] + }, + { + "id": "galaxy-visualization", + "name": "autogalaxy_visualization", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autogalaxy_visualization" + } + ], + "repo": "autogalaxy_visualization", + "github": "PyAutoLabs/autogalaxy_visualization", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "visualization" + ] + }, + { + "id": "galaxy-tests", + "name": "autogalaxy_workspace_test", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autogalaxy_workspace_test" + } + ], + "repo": "autogalaxy_workspace_test", + "github": "PyAutoLabs/autogalaxy_workspace_test", + "projects": [ + { + "id": "galaxy", + "name": "PyAutoGalaxy" + } + ], + "relations": [ + "tests" + ] + }, + { + "id": "lens", + "name": "PyAutoLens", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoLens" + } + ], + "repo": "PyAutoLens", + "github": "PyAutoLabs/PyAutoLens", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "software" + ] + }, + { + "id": "lens-workspace", + "name": "autolens_workspace", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_workspace" + } + ], + "repo": "autolens_workspace", + "github": "PyAutoLabs/autolens_workspace", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "workspaces" + ] + }, + { + "id": "lens-tutorials", + "name": "HowToLens", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/HowToLens" + } + ], + "repo": "HowToLens", + "github": "PyAutoLabs/HowToLens", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "tutorials" + ] + }, + { + "id": "lens-docs", + "name": "PyAutoLens documentation", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoLens/tree/main/docs" + }, + { + "label": "Published", + "url": "https://pyautolens.readthedocs.io/en/latest/" + } + ], + "repo": "PyAutoLens", + "github": "PyAutoLabs/PyAutoLens", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "lens-assistant", + "name": "autolens_assistant", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_assistant" + } + ], + "repo": "autolens_assistant", + "github": "PyAutoLabs/autolens_assistant", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "assistants" + ] + }, + { + "id": "lens-profiling", + "name": "autolens_profiling", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_profiling" + } + ], + "repo": "autolens_profiling", + "github": "PyAutoLabs/autolens_profiling", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "profiling" + ] + }, + { + "id": "lens-inference", + "name": "autolens_inference", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_inference" + } + ], + "repo": "autolens_inference", + "github": "PyAutoLabs/autolens_inference", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "inference" + ] + }, + { + "id": "lens-visualization", + "name": "autolens_visualization", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_visualization" + } + ], + "repo": "autolens_visualization", + "github": "PyAutoLabs/autolens_visualization", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "visualization" + ] + }, + { + "id": "lens-tests", + "name": "autolens_workspace_test", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autolens_workspace_test" + } + ], + "repo": "autolens_workspace_test", + "github": "PyAutoLabs/autolens_workspace_test", + "projects": [ + { + "id": "lens", + "name": "PyAutoLens" + } + ], + "relations": [ + "tests" + ] + }, + { + "id": "reduce", + "name": "PyAutoReduce", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoReduce" + } + ], + "repo": "PyAutoReduce", + "github": "PyAutoLabs/PyAutoReduce", + "projects": [ + { + "id": "reduce", + "name": "PyAutoReduce" + } + ], + "relations": [ + "software" + ] + }, + { + "id": "reduce-workspace", + "name": "autoreduce_workspace", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autoreduce_workspace" + } + ], + "repo": "autoreduce_workspace", + "github": "PyAutoLabs/autoreduce_workspace", + "projects": [ + { + "id": "reduce", + "name": "PyAutoReduce" + } + ], + "relations": [ + "workspaces" + ] + }, + { + "id": "reduce-guide", + "name": "PyAutoReduce project guide", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoReduce/tree/main/README.md" + } + ], + "repo": "PyAutoReduce", + "github": "PyAutoLabs/PyAutoReduce", + "projects": [ + { + "id": "reduce", + "name": "PyAutoReduce" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "cti", + "name": "PyAutoCTI", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoCTI" + } + ], + "repo": "PyAutoCTI", + "github": "PyAutoLabs/PyAutoCTI", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "software" + ] + }, + { + "id": "cti-workspace", + "name": "autocti_workspace", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autocti_workspace" + } + ], + "repo": "autocti_workspace", + "github": "PyAutoLabs/autocti_workspace", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "workspaces" + ] + }, + { + "id": "cti-docs", + "name": "PyAutoCTI documentation", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/PyAutoCTI/tree/main/docs" + }, + { + "label": "Published", + "url": "https://pyautocti.readthedocs.io/en/latest/" + } + ], + "repo": "PyAutoCTI", + "github": "PyAutoLabs/PyAutoCTI", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "documentation" + ] + }, + { + "id": "cti-assistant", + "name": "autocti_assistant", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autocti_assistant" + } + ], + "repo": "autocti_assistant", + "github": "PyAutoLabs/autocti_assistant", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "assistants" + ] + }, + { + "id": "cti-visualization", + "name": "autocti_visualization", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autocti_visualization" + } + ], + "repo": "autocti_visualization", + "github": "PyAutoLabs/autocti_visualization", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "visualization" + ] + }, + { + "id": "cti-tests", + "name": "autocti_workspace_test", + "links": [ + { + "label": "Source", + "url": "https://github.com/PyAutoLabs/autocti_workspace_test" + } + ], + "repo": "autocti_workspace_test", + "github": "PyAutoLabs/autocti_workspace_test", + "projects": [ + { + "id": "cti", + "name": "PyAutoCTI" + } + ], + "relations": [ + "tests" + ] + } + ] +} diff --git a/tests/test_resource_dropdowns.py b/tests/test_resource_dropdowns.py new file mode 100644 index 00000000..bb805240 --- /dev/null +++ b/tests/test_resource_dropdowns.py @@ -0,0 +1,38 @@ +from datetime import datetime, timezone +from heart.resources import render +from heart.dashboard import render as dashboard + +CATALOGUE = {'schema_version': 1, 'resources': [{'id': 'example-tests', 'name': 'Example tests', + 'repo': 'checks', 'github': 'Example/Checks', 'relations': ['tests'], + 'projects': [{'id': 'demo', 'name': 'Demo'}], 'links': [{'label': 'Source', 'url': 'https://github.com/Example/Checks'}]}]} + + +def test_unknown_is_not_pass(): + page = render(CATALOGUE, {}) + assert 'CI: unavailable' in page and 'Age unknown' in page + assert 'resource-example-tests' in page + assert 'Test-level counts' in page + + +def test_old_failure_stays_failure_and_links_run(): + ci = {'conclusion': 'failure', 'ts': '2020-01-01T00:00:00+00:00', 'head_sha': 'abcdef', + 'url': 'https://github.com/Example/Checks/actions/runs/1', + 'workflows': {'Smoke': {'conclusion': 'failure'}}} + page = render(CATALOGUE, {'checks': {'ci_status': ci}}, now=datetime(2026, 1, 1, tzinfo=timezone.utc)) + assert 'CI: failure' in page and 'Evidence outdated' in page + assert 'abcdef' in page and '/actions/runs/1' in page + assert 'Smoke' in page + + +def test_fresh_success_and_dashboard_integration(): + now = datetime(2026, 1, 1, tzinfo=timezone.utc) + snapshot = {'ts': now.isoformat(), 'repos': {'checks': {'ci_status': {'conclusion': 'success', 'ts': now.isoformat()}}}} + page = dashboard(snapshot, {'verdict': 'green', 'score': 100}, fmt='html', now=now, resource_catalogue=CATALOGUE) + assert 'CI: success' in page and 'Observed within 24 hours' in page + assert 'id="resource-example-tests"' in page + assert 'hashchange' in page + + +def test_unsafe_evidence_url_is_not_linked(): + page = render(CATALOGUE, {'checks': {'ci_status': {'url': 'javascript:alert(1)'}}}) + assert 'javascript:' not in page From 689e6400205e86f3f724f4ebc0417a07f2a34b86 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Sun, 11 Oct 2026 18:45:39 +0100 Subject: [PATCH 2/2] Require canonical run provenance for test resource CI --- docs/internals.md | 2 ++ heart/resources.py | 20 ++++++++++++++++++-- tests/test_resource_dropdowns.py | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/internals.md b/docs/internals.md index c6b310f9..ff858fa5 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -213,3 +213,5 @@ 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. diff --git a/heart/resources.py b/heart/resources.py index 84ba9b78..69fa65cf 100644 --- a/heart/resources.py +++ b/heart/resources.py @@ -20,6 +20,22 @@ def link(url, label): return f'{html.escape(str(label))}' +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 = [] @@ -28,7 +44,7 @@ def render(catalogue, repos, *, now=None): if 'tests' not in resource.get('relations', []): continue name = resource.get('repo', '') - ci = (repos.get(name) or {}).get('ci_status') or {} + 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' @@ -50,5 +66,5 @@ def render(catalogue, repos, *, now=None):
    Observed
    {esc(observed)} · {esc(freshness)}
    Source revision
    {esc(ci.get('head_sha') or ci.get('sha') or 'Unknown')}
    {detail}

    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.

    Next: use Heart's check-in to inspect this workspace's latest run, missing evidence and failures before scheduling any check.

    ''') - return ('

    Test workspaces

    Project-owned test suites and their recorded CI evidence. Inventory is not a passing result. Evidence older than 24 hours is labelled outdated here; release gates retain their own policy.

    ' + return ('

    Test workspaces

    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.

    ' + ''.join(cards) + ('' if cards else '

    No public test-workspace resources available.

    ') + '
    ') diff --git a/tests/test_resource_dropdowns.py b/tests/test_resource_dropdowns.py index bb805240..eeb57689 100644 --- a/tests/test_resource_dropdowns.py +++ b/tests/test_resource_dropdowns.py @@ -26,7 +26,7 @@ def test_old_failure_stays_failure_and_links_run(): def test_fresh_success_and_dashboard_integration(): now = datetime(2026, 1, 1, tzinfo=timezone.utc) - snapshot = {'ts': now.isoformat(), 'repos': {'checks': {'ci_status': {'conclusion': 'success', 'ts': now.isoformat()}}}} + snapshot = {'ts': now.isoformat(), 'repos': {'checks': {'ci_status': {'conclusion': 'success', 'ts': now.isoformat(), 'url': 'https://github.com/Example/Checks/actions/runs/1'}}}} page = dashboard(snapshot, {'verdict': 'green', 'score': 100}, fmt='html', now=now, resource_catalogue=CATALOGUE) assert 'CI: success' in page and 'Observed within 24 hours' in page assert 'id="resource-example-tests"' in page @@ -36,3 +36,16 @@ def test_fresh_success_and_dashboard_integration(): def test_unsafe_evidence_url_is_not_linked(): page = render(CATALOGUE, {'checks': {'ci_status': {'url': 'javascript:alert(1)'}}}) assert 'javascript:' not in page + + +def test_foreign_or_unattributed_ci_is_unavailable(): + for url in ['', 'https://github.com/Other/Checks/actions/runs/1']: + page = render(CATALOGUE, {'checks': {'ci_status': {'conclusion': 'success', 'url': url}}}) + assert 'CI: unavailable' in page + assert 'CI: success' not in page and 'Other/Checks' not in page + + +def test_foreign_workflow_invalidates_aggregate(): + ci = {'conclusion': 'success', 'url': 'https://github.com/Example/Checks/actions/runs/1', + 'workflows': {'Smoke': {'conclusion': 'success', 'url': 'https://github.com/Other/Checks/actions/runs/2'}}} + assert 'CI: unavailable' in render(CATALOGUE, {'checks': {'ci_status': ci}})