mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
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>
231 lines
8.4 KiB
Python
231 lines
8.4 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
import unittest.mock as mock
|
|
from typing import ClassVar
|
|
|
|
from cli.meta.ci import matrix
|
|
|
|
|
|
def _entry(
|
|
app: str,
|
|
variant: str,
|
|
mode: str,
|
|
*,
|
|
network: str = "clearnet",
|
|
priority: bool = False,
|
|
covered: str = "0",
|
|
clone: bool = False,
|
|
) -> dict:
|
|
return {
|
|
"apps": app,
|
|
"variant": variant,
|
|
"mode": mode,
|
|
"network": network,
|
|
"priority": "true" if priority else "false",
|
|
"covered": covered,
|
|
"clone": "true" if clone else "false",
|
|
}
|
|
|
|
|
|
class TestChunksOf(unittest.TestCase):
|
|
def _chunks(self, entries: list[dict], *, size: int) -> list[list[dict]]:
|
|
with (
|
|
mock.patch.object(matrix.slots, "chunk_size", return_value=size),
|
|
mock.patch.object(matrix.slots, "chunk_blocks", return_value=4),
|
|
mock.patch.object(matrix.slots, "available", return_value=99),
|
|
):
|
|
return matrix.chunks_of(entries, 0)
|
|
|
|
def test_a_chunk_is_sorted_by_name_then_variant(self) -> None:
|
|
entries = [
|
|
_entry("web-app-b", "1", "compose"),
|
|
_entry("web-app-a", "1", "compose"),
|
|
_entry("web-app-a", "0", "compose"),
|
|
]
|
|
chunk = self._chunks(entries, size=9)[0]
|
|
self.assertEqual(
|
|
[(e["apps"], e["variant"]) for e in chunk],
|
|
[("web-app-a", "0"), ("web-app-a", "1"), ("web-app-b", "1")],
|
|
)
|
|
|
|
def test_the_split_still_follows_the_discovery_ranking(self) -> None:
|
|
entries = [
|
|
_entry("web-app-z", "0", "compose"),
|
|
_entry("web-app-a", "0", "compose"),
|
|
]
|
|
chunks = self._chunks(entries, size=1)
|
|
self.assertEqual(
|
|
[chunk[0]["apps"] for chunk in chunks], ["web-app-z", "web-app-a"]
|
|
)
|
|
|
|
def test_a_short_priority_chunk_leaves_the_regular_rows_a_spare_block(
|
|
self,
|
|
) -> None:
|
|
entries = [_entry("web-app-p", "0", "compose", priority=True)] + [
|
|
_entry(f"web-app-{index:02d}", "0", "compose") for index in range(20)
|
|
]
|
|
with (
|
|
mock.patch.object(matrix.slots, "chunk_size", return_value=10),
|
|
mock.patch.object(matrix.slots, "chunk_count", return_value=2),
|
|
mock.patch.object(matrix.slots, "chunk_blocks", return_value=3),
|
|
mock.patch.object(matrix.slots, "available", return_value=21),
|
|
):
|
|
chunks = matrix.chunks_of(entries, 0)
|
|
self.assertEqual(
|
|
[len(chunk) for chunk in chunks],
|
|
[1, 10, 10],
|
|
"the split must get every declared block, not only the ones the "
|
|
"budget fills, or the rows a short priority chunk leaves go unplanned",
|
|
)
|
|
|
|
def test_priority_chunks_are_sorted_on_their_own(self) -> None:
|
|
entries = [
|
|
_entry("web-app-z", "0", "compose", priority=True),
|
|
_entry("web-app-a", "0", "compose", priority=True),
|
|
_entry("web-app-b", "0", "compose"),
|
|
]
|
|
chunks = self._chunks(entries, size=9)
|
|
self.assertEqual([e["apps"] for e in chunks[0]], ["web-app-a", "web-app-z"])
|
|
self.assertEqual([e["apps"] for e in chunks[1]], ["web-app-b"])
|
|
|
|
|
|
_REGULAR = [
|
|
_entry("web-app-a", "0", "compose"),
|
|
_entry("web-app-b", "1", "swarm", network="tor"),
|
|
_entry("web-app-b", "2", "compose"),
|
|
]
|
|
|
|
|
|
class TestRedundant(unittest.TestCase):
|
|
def _chunked(self, entries: list[dict]) -> list[dict]:
|
|
with (
|
|
mock.patch.object(matrix.slots, "chunk_size", return_value=10),
|
|
mock.patch.object(matrix.slots, "chunk_blocks", return_value=4),
|
|
mock.patch.object(matrix.slots, "available", return_value=99),
|
|
):
|
|
return [row for chunk in matrix.chunks_of(entries, 0) for row in chunk]
|
|
|
|
def test_a_covered_row_never_reaches_a_chunk(self) -> None:
|
|
entries = [_entry("web-app-a", "0", "compose", covered="7")]
|
|
self.assertEqual(self._chunked(entries), [])
|
|
|
|
def test_a_clone_never_reaches_a_chunk(self) -> None:
|
|
entries = [_entry("web-app-a", "0", "compose", clone=True)]
|
|
self.assertEqual(self._chunked(entries), [])
|
|
|
|
def test_a_plain_row_still_reaches_a_chunk(self) -> None:
|
|
entries = [_entry("web-app-a", "0", "compose")]
|
|
self.assertEqual(len(self._chunked(entries)), 1)
|
|
|
|
def test_a_pinned_clone_is_kept(self) -> None:
|
|
entries = [_entry("web-app-a", "0", "compose", priority=True, clone=True)]
|
|
self.assertEqual(len(self._chunked(entries)), 1)
|
|
|
|
|
|
class TestOffsetIndex(unittest.TestCase):
|
|
def test_nothing_given_starts_at_the_head(self) -> None:
|
|
for raw in (None, "", 0, "0"):
|
|
with self.subTest(raw=raw):
|
|
self.assertEqual(matrix.offset_index(raw, _REGULAR), 0)
|
|
|
|
def test_a_number_is_a_row_count(self) -> None:
|
|
self.assertEqual(matrix.offset_index("2", _REGULAR), 2)
|
|
|
|
def test_a_negative_count_reads_as_the_head(self) -> None:
|
|
self.assertEqual(matrix.offset_index("-5", _REGULAR), 0)
|
|
|
|
def test_a_role_token_starts_at_its_first_row(self) -> None:
|
|
self.assertEqual(matrix.offset_index("web-app-b", _REGULAR), 1)
|
|
|
|
def test_a_pinned_variant_starts_at_that_variant(self) -> None:
|
|
self.assertEqual(matrix.offset_index("web-app-b#2", _REGULAR), 2)
|
|
|
|
def test_a_pinned_mode_picks_the_row_of_that_mode(self) -> None:
|
|
self.assertEqual(matrix.offset_index("web-app-b#1@swarm", _REGULAR), 1)
|
|
|
|
def test_a_pinned_network_mode_picks_the_row_of_that_network_mode(self) -> None:
|
|
self.assertEqual(matrix.offset_index("web-app-b+tor", _REGULAR), 1)
|
|
self.assertEqual(matrix.offset_index("web-app-b+clearnet", _REGULAR), 2)
|
|
with self.assertRaises(SystemExit):
|
|
matrix.offset_index("web-app-b+multi", _REGULAR)
|
|
|
|
def test_a_token_naming_no_regular_row_aborts(self) -> None:
|
|
with self.assertRaises(SystemExit):
|
|
matrix.offset_index("web-app-gone#3", _REGULAR)
|
|
|
|
|
|
def _row(app: str, variant: int) -> dict:
|
|
return {"name": app, "variant": variant, "test_compose": True}
|
|
|
|
|
|
class TestCandidates(unittest.TestCase):
|
|
_DISCOVERED: ClassVar[list] = [
|
|
_row("web-app-a", 0),
|
|
_row("web-app-b", 0),
|
|
_row("web-app-b", 1),
|
|
]
|
|
|
|
def _candidates(self, priority: str) -> list[dict]:
|
|
with mock.patch.object(
|
|
matrix.query, "discover_rows", return_value=list(self._DISCOVERED)
|
|
):
|
|
return matrix.candidates(
|
|
modes=("compose",), whitelist="", priority=priority, lifecycles=""
|
|
)
|
|
|
|
def _regular(self, priority: str) -> set[tuple[str, int]]:
|
|
return {
|
|
(row["name"], row["variant"])
|
|
for row in self._candidates(priority)
|
|
if not row["priority"]
|
|
}
|
|
|
|
def test_a_pinned_variant_leaves_its_siblings_in_the_regular_line(self) -> None:
|
|
self.assertEqual(
|
|
self._regular("web-app-b#0"), {("web-app-a", 0), ("web-app-b", 1)}
|
|
)
|
|
|
|
def test_a_pinned_variant_does_not_come_back_as_a_regular_row(self) -> None:
|
|
self.assertNotIn(("web-app-b", 0), self._regular("web-app-b#0"))
|
|
|
|
def test_a_bare_token_withdraws_the_whole_role(self) -> None:
|
|
with mock.patch.object(
|
|
matrix.query, "discover_rows", return_value=list(self._DISCOVERED)
|
|
) as discovered:
|
|
matrix.candidates(
|
|
modes=("compose",), whitelist="", priority="web-app-b", lifecycles=""
|
|
)
|
|
self.assertEqual(discovered.call_args.kwargs["blacklist"], "web-app-b")
|
|
|
|
|
|
class TestWithDeployedServices(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
matrix.deployed_rounds.cache_clear()
|
|
self.addCleanup(matrix.deployed_rounds.cache_clear)
|
|
|
|
def test_each_variant_takes_the_apps_its_own_round_deploys(self) -> None:
|
|
plan = [
|
|
(0, "plan-0", {}, ("web-app-a", "svc-db-postgres"), ()),
|
|
(1, "plan-1", {}, ("web-app-a", "svc-ai-lmstudio"), ()),
|
|
]
|
|
with mock.patch.object(
|
|
matrix, "plan_dev_inventory_matrix", return_value=plan
|
|
) as planner:
|
|
rows = [
|
|
matrix.with_deployed_services(
|
|
{"name": "web-app-a", "variant": variant, "services": ["x"]}
|
|
)
|
|
for variant in (0, 1)
|
|
]
|
|
|
|
self.assertEqual(
|
|
[row["services"] for row in rows],
|
|
[("web-app-a", "svc-db-postgres"), ("web-app-a", "svc-ai-lmstudio")],
|
|
)
|
|
planner.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|