diff --git a/bin/morning.sh b/bin/morning.sh index 4357fe01..7fd3ead7 100755 --- a/bin/morning.sh +++ b/bin/morning.sh @@ -9,11 +9,12 @@ # touch YOUR checkout — sync and clean-slate. This script is exactly those two # steps, so the morning is: run this in a terminal, then open the board. # -# bash PyAutoBrain/bin/morning.sh # sync + clean + publish, -# # then board URL +# bash PyAutoBrain/bin/morning.sh # sync + clean + publish +# # (Brain + Heart dev-box +# # observations), then board URL # bash PyAutoBrain/bin/morning.sh --digest # also print the board's # # markdown digest (needs gh) -# bash PyAutoBrain/bin/morning.sh --no-publish # skip the dev-box publish +# bash PyAutoBrain/bin/morning.sh --no-publish # skip both dev-box publishes # DRY_RUN=1 bash PyAutoBrain/bin/morning.sh # preview clean-slate only # # To run overnight automatically (so the board is fresh on waking), schedule @@ -43,6 +44,19 @@ if [ "${1:-}" != "--no-publish" ]; then # this morning's local observations a minute later. bash "$HERE/../board/board.sh" publish \ || echo "morning: dev-box publish skipped (see above) — the board keeps its last stamp" + + # The Heart's cloud board has the same blind spot for the same reason: its + # local-only check families render grey unless THIS box publishes what it + # saw (the observation expires after 48h). Publishing it here, beside the + # Brain's, is what keeps those eight rows lit — they went grey because this + # leg did not exist and the last hand-run was a week old. + heart="$HERE/../../PyAutoHeart/bin/pyauto-heart" + if [ -x "$heart" ]; then + echo + echo "== morning: publish the Heart's dev-box observation ==" + ( "$heart" tick && "$heart" publish ) \ + || echo "morning: Heart dev-box publish skipped (see above) — the Heart board keeps its last stamp" + fi fi echo diff --git a/board/_theme.py b/board/_theme.py index 73d56f91..866091f6 100644 --- a/board/_theme.py +++ b/board/_theme.py @@ -296,6 +296,8 @@ } import html as _html +import re as _re +from pathlib import Path as _Path WORD = "PyAuto" # the half of every wordmark that stays white @@ -653,6 +655,46 @@ def stats(*pairs): return f'' if items else "" +# The board family's canonical membership and order live in ONE place: +# `config/policy.yaml` `board: boards:`. Every renderer that draws the footer +# used to keep its own copy of that list, and every copy drifted — the three +# sibling organs shipped a tuple written before the Cortex had a board, so +# their footers were both short a chip and out of the ruled organ order. +# +# `board_links` is that single read, offered to every renderer. It stays a +# stdlib regex over the one-pair-per-line block rather than a yaml parse for +# the same reason `_intake._board_links` does: these renderers also run bare +# in workflows that install nothing, and this module is presentation-only — +# it must not grow a dependency. File order IS the order: editing +# `policy.yaml` reorders every board's footer at once, which is the point. +_BOARDS_BLOCK = _re.compile(r"^ boards:\n((?: \w+: \S+\n)+)", _re.M) +_BOARD_PAIR = _re.compile(r"^ (\w+): (\S+)$", _re.M) + + +def board_links(base_url, current=None, policy=None): + """The family's `name -> board URL` mapping, in `policy.yaml` order. + + `base_url` is the Pages origin the caller already derives for itself + (e.g. `https://.github.io`); each entry becomes + `//`. `current` — this page's own board key — is dropped, + so a renderer can hand the result straight to `boards_footer`. Returns an + empty mapping when the config surface is unreadable, which renders as no + footer rather than a broken one. + """ + path = _Path(policy) if policy else _Path(__file__).resolve().parents[1] / "config" / "policy.yaml" + try: + text = path.read_text(encoding="utf-8") + except OSError: + return {} + block = _BOARDS_BLOCK.search(text) + if not block: + return {} + base = str(base_url or "").rstrip("/") + return {name: f"{base}/{repo}/" + for name, repo in _BOARD_PAIR.findall(block.group(1)) + if name != current} + + def boards_footer(links, current): """The family footer — one chip per sibling board, each in its own organ's colour, so the six pages read as one system. `links` is the diff --git a/tests/test_board_theme.py b/tests/test_board_theme.py index ca8c4444..484aef4c 100644 --- a/tests/test_board_theme.py +++ b/tests/test_board_theme.py @@ -196,6 +196,44 @@ def test_boards_footer_skips_self_and_tags_each_sibling(): assert f'.boards a[data-organ="{key}"]' in _theme.css("mind") +def test_board_links_reads_the_declared_family_in_file_order(): + # The footer's membership and order are config, not code. Every sibling + # renderer used to keep its own tuple; each one drifted (no Cortex chip, + # ad-hoc order). This helper is the one read, so the order it returns is + # the order `config/policy.yaml` declares — the ruled organ order. + links = _theme.board_links("https://example.invalid") + assert list(links) == ["brain", "mind", "cortex", "memory", + "heart", "hands", "organism"] + assert list(links) == POLICY_BOARDS + assert links["cortex"] == "https://example.invalid/PyAutoCortex/" + + +def test_board_links_drops_the_page_it_is_rendered_on(): + for current in POLICY_BOARDS: + links = _theme.board_links("https://example.invalid", current) + assert current not in links + assert list(links) == [k for k in POLICY_BOARDS if k != current] + + +def test_board_links_tolerates_a_trailing_slash_on_the_base(): + assert (_theme.board_links("https://example.invalid/") + == _theme.board_links("https://example.invalid")) + + +def test_board_links_renders_the_family_footer_end_to_end(): + # What every sibling renderer actually does: one read, one footer. + footer = _theme.boards_footer( + _theme.board_links("https://example.invalid", "heart"), "heart") + order = re.findall(r'data-organ="(\w+)"', footer) + assert order == ["brain", "mind", "cortex", "memory", "hands", "organism"] + + +def test_board_links_returns_nothing_when_the_config_is_unreadable(): + # A missing config surface renders no footer, never a broken one. + assert _theme.board_links("https://example.invalid", + policy="/nonexistent/policy.yaml") == {} + + def test_stats_render_pairs_and_vanish_when_empty(): assert _theme.stats() == "" assert "3In flight" in _theme.stats((3, "In flight"))