Files
computer-playbook/tests/unit/python/cli/meta/ci/test_plan.py
T
kevinveenbirkenbachandClaude Opus 5 677a63931c Merge branch 'feature/network/multi-network-serving' into feature/store-i18n
Resolves 68 conflicted files. The governing rule was our structure with their
network semantics: the tor boolean becomes a network mode (clearnet | tor |
multi) throughout the variant layer, while this branch's architecture and mesh
axes, its extracted modules and its i18n content stay.

Where the two sides covered different ground, both are kept rather than one
picked:

- ca_injected answers a ca_client on the deployment's TLS mode OR on an SSO
  issuer that resolves self-signed. 3a3e9ed2c9 records why: an issuer is not
  an object store, so keeping only one side drops the other's coverage.
- get_merged_domains keeps the loud refusal when svc-net-tor is deployed
  without a provisioned node, now gated on their tor_serves_host; their
  node_onion_of returns an empty string there, which would have served every
  onion-exclusive app on clearnet in silence.
- sso_cookie_domains stays the single source for oauth2-proxy's cookie scope.
  Their per-network branch omitted the issuer domain on the onion arm, which
  breaks the callback leg.
- The clearnet CSP batch carries --clearnet-timeout again; their batch dict
  hardcoded zero while the role still passes the flag.
- The dashboard keeps its i18n content dir, image, version and design
  resolution; their side reduced the logo sources to the bare service
  provider values.

Their side wins where it is measurably better: the onion mirror rewrite is
gated per vhost rather than per app, the Playwright onion decision reads the
pass's own domain instead of the role's canonical one, and the matomo
reinjection and dashboard config render per network sibling.

Eight files were broken by the merge without ever carrying a conflict marker,
because git marks only the lines both sides touched:

- utils/cache/domains.py lost the onionize block that sat between two hunks
- roles/sys-front-inj-all/templates/body_filter.lua.j2 called it
- web-app-bluesky, keycloak sso_proxy: the get_entity_name filter was renamed
- trigger/__main__.py, playwright_coverage.py and its test: the deleted tor
  module
- cli/administration/deploy/ci/timings.py read Label.tor
- plugins/filter/csp_filters.py called _aligned_url with four of six arguments
- tests/unit/python/utils/cache/test_domains.py referenced a renamed class
- tests/.../sys-ctl-hlth-csp/files/test_script.py mocked a function main no
  longer calls

Verified: the variant layer (155 tests, 65 subtests), ca_injected (18),
the CI layer (175), the domains cache including the restored guard (32),
retrigger inputs (9), timings and the CSP health script (53). make
quality-high clears autoformat; its remaining findings are tracked separately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-23 09:53:41 +02:00

190 lines
7.7 KiB
Python

from __future__ import annotations
import unittest
from cli.meta.ci import plan
from utils.symbol_glossary import to_emoji
def _entry(
app: str,
variant: str,
mode: str,
*,
network: str = "clearnet",
priority: bool = False,
identifier: str = "0",
covered: str = "0",
clone: bool = False,
instructions: str = "",
) -> dict:
return {
"apps": app,
"variant": variant,
"mode": mode,
"network": network,
"vpn": "true" if mode == "swarm" else "false",
"disable": "",
"priority": "true" if priority else "false",
"instructions": instructions,
"id": identifier,
"covered": covered,
"clone": "true" if clone else "false",
"distro": "debian",
"filesystem": "zfs",
"architecture": "arm64",
"label": f"{to_emoji(mode)}{app} {variant}",
}
_PRIORITY = [
_entry("web-app-a", "0", "compose", network="tor", priority=True, identifier="3")
]
_REGULAR = [
_entry("web-app-b", "0", "swarm", network="multi", identifier="5"),
_entry("web-app-b", "1", "compose", identifier="9"),
]
_CUT = [_entry("web-app-c", "0", "compose", identifier="11", covered="5")]
_ENTRIES = _PRIORITY + _REGULAR + _CUT
class TestCells(unittest.TestCase):
def test_a_row_in_a_chunk_reports_that_chunk(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
chunk = plan._COLUMNS.index("chunk")
self.assertEqual([row[chunk] for row in rows], ["0", "1", "1", ""])
def test_a_priority_row_is_starred_not_ticked(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
status = plan._COLUMNS.index("triggered")
self.assertEqual(rows[0][status], to_emoji("priority"))
self.assertEqual(rows[1][status], to_emoji("enabled"))
def test_a_row_outside_the_sweep_is_marked_disabled(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY])
self.assertEqual(
rows[1][plan._COLUMNS.index("triggered")], to_emoji("disabled")
)
self.assertEqual(rows[1][plan._COLUMNS.index("chunk")], "")
def test_a_priority_row_the_budget_missed_keeps_its_star(self) -> None:
rows = plan.cells(_ENTRIES, [_REGULAR])
status = plan._COLUMNS.index("triggered")
self.assertEqual(rows[0][status], to_emoji("priority") + to_emoji("disabled"))
self.assertEqual(rows[0][plan._COLUMNS.index("chunk")], "")
def test_a_clone_is_named_in_its_own_column(self) -> None:
entries = [*_ENTRIES, _entry("web-app-d", "0", "compose", clone=True)]
rows = plan.cells(entries, [_PRIORITY, _REGULAR])
clone = plan._COLUMNS.index("clone")
self.assertEqual(rows[0][clone], "")
self.assertEqual(rows[-1][clone], to_emoji("clone"))
def test_the_instructions_column_names_the_mode_the_replay_runs_in(self) -> None:
entries = [
*_ENTRIES,
_entry("web-app-d", "0", "swarm", instructions="compose"),
]
rows = plan.cells(entries, [_PRIORITY, _REGULAR])
column = plan._COLUMNS.index("instructions")
self.assertEqual(rows[0][column], "")
self.assertEqual(rows[-1][column], to_emoji("compose"))
def test_the_mode_is_rendered_as_its_glyph(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
mode = plan._COLUMNS.index("mode")
self.assertEqual(rows[0][mode], to_emoji("compose"))
self.assertEqual(rows[1][mode], to_emoji("swarm"))
def test_a_covered_row_names_the_row_number_that_covers_it(self) -> None:
covered = plan._COLUMNS.index("covered_by")
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
self.assertEqual(rows[0][covered], "")
self.assertEqual(rows[3][covered], "2")
def test_a_covered_row_is_cut_instead_of_deployed(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
self.assertEqual(
rows[3][plan._COLUMNS.index("triggered")], to_emoji("redundant")
)
self.assertEqual(rows[3][plan._COLUMNS.index("chunk")], "")
def test_a_clone_is_cut_as_well(self) -> None:
entries = [*_ENTRIES, _entry("web-app-d", "0", "compose", clone=True)]
rows = plan.cells(entries, [_PRIORITY, _REGULAR])
self.assertEqual(
rows[-1][plan._COLUMNS.index("triggered")], to_emoji("redundant")
)
def test_a_pinned_clone_stays_in_the_run(self) -> None:
entries = [_entry("web-app-d", "0", "compose", priority=True, clone=True)]
rows = plan.cells(entries, [entries])
self.assertEqual(
rows[0][plan._COLUMNS.index("triggered")], to_emoji("priority")
)
def test_the_id_counts_the_rows_even_when_discovery_ids_repeat(self) -> None:
identifier = plan._COLUMNS.index("id")
entries = [*_ENTRIES, _entry("web-app-a", "0", "swarm", identifier="3")]
rows = plan.cells(entries, [_PRIORITY, _REGULAR])
self.assertEqual([row[identifier] for row in rows], ["1", "2", "3", "4", "5"])
def test_the_network_mode_is_rendered_as_its_glyph(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
network = plan._COLUMNS.index("network")
self.assertEqual(rows[0][network], to_emoji("tor"))
self.assertEqual(rows[1][network], to_emoji("multi"))
self.assertEqual(rows[2][network], to_emoji("clearnet"))
def test_each_network_mode_of_one_row_reports_its_own_chunk(self) -> None:
tor = _entry("web-app-a", "0", "compose", network="tor", priority=True)
multi = _entry("web-app-a", "0", "compose", network="multi", priority=True)
rows = plan.cells([tor, multi], [[tor]])
chunk = plan._COLUMNS.index("chunk")
self.assertEqual([row[chunk] for row in rows], ["0", ""])
def test_every_row_carries_its_own_distro_and_filesystem_glyph(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
distro = plan._COLUMNS.index("distro")
filesystem = plan._COLUMNS.index("filesystem")
self.assertTrue(all(row[distro] == to_emoji("debian") for row in rows))
self.assertTrue(all(row[filesystem] == to_emoji("zfs") for row in rows))
def test_every_row_carries_its_architecture_glyph(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
architecture = plan._COLUMNS.index("architecture")
self.assertTrue(all(row[architecture] == to_emoji("arm64") for row in rows))
class TestRender(unittest.TestCase):
def _rows(self) -> list[tuple[str, ...]]:
return plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
def test_markdown_is_one_table_with_a_chunk_column(self) -> None:
out = plan.render_markdown("sweep 0", self._rows())
self.assertEqual(out.count("| ---"), 0)
self.assertEqual(out.count("\n|---"), 1)
self.assertIn(f"{to_emoji('chunk')} Chunk", out)
self.assertIn("web-app-a", out)
def test_the_network_column_is_headed_by_the_multi_glyph(self) -> None:
out = plan.render_markdown("sweep 0", self._rows())
self.assertIn(f"{to_emoji('multi')} Network", out)
def test_markdown_keeps_one_line_per_row(self) -> None:
out = plan.render_markdown("sweep 0", self._rows())
body = [line for line in out.splitlines() if line.startswith("| web")]
self.assertEqual(len(body), 0)
self.assertEqual(len([ln for ln in out.splitlines() if ln.startswith("| ")]), 5)
def test_cli_pads_to_display_width(self) -> None:
out = plan.render_cli("sweep 0", self._rows())
lines = out.splitlines()
self.assertEqual(lines[0], "sweep 0")
self.assertTrue(lines[2].startswith("---"))
self.assertEqual(len(lines), 3 + len(_ENTRIES))
if __name__ == "__main__":
unittest.main()