Files
computer-playbook/tests/unit/python/cli/meta/ci/test_plan.py
T
kevinveenbirkenbachandClaude Opus 5 575a5a87ac refactor(layout): sort shipped scripts by language and split the unit suite
Every script a role ships now lives under `files/<language>/`, and the unit
suite is split the same way: `tests/unit/python/` beside new sibling trees for
the other languages. `tests/lint/filesystem/test_role_files_layout.py` keeps it
that way; directories whose shape is dictated from outside carry a `.nocheck`
naming the constraint (Docker build contexts, WordPress mu-plugins, the Joomla
extension, Odoo addons, Playwright suites, the `files/test/test.sh` harness
that `test-e2e-cli` resolves generically).

This cannot be applied in halves. Moving a file and repointing what names it
are the same change: 14 references resolve only at deploy time, so the tree is
green either before or after, never between.

Those 14 were found by static resolution over every reference class, not by the
test suite -- a full `make quality-high` was green while all of them were
broken:

  * 7 `src:` values built from a role variable holding a bare filename
    (svc-bkp-remote-2-local, decidim, espocrm, friendica, joomla, pixelfed x2).
    The variable doubles as the destination name inside the container, so the
    language segment belongs at the call site, not in the variable.
  * `sys-service/tasks/04_base.yml` resolved every consumer's systemd script
    through `first_found(..., errors='strict')` over `files/script.{sh,py}`.
    18 roles ship exactly that and have no template fallback: the play would
    have died on each.
  * `sys-front-inj-javascript` fell back to `<role>/files/javascript.js`; the
    interface now reads `files/javascript/javascript.js`.
  * `sys-front-inj-logout/templates/head_sub.j2` built the cache-busting mtime
    path through `path_absolute(... 'files', ...)`.
  * 4 `ansible.builtin.script:` invocations naming a bare command
    (pull.py, prune.sh, set_postgres_superuser_password.sh, ganesha-serve.sh).
  * `dev-python/files/shell/install.sh` pointed at a sibling role's script.

Depth-dependent paths inside the moved trees were bumped accordingly: 59
`parents[N]` computations, 12 relative climbs, and the per-role recover CLI,
whose path `cli/administration/recover/recoverers.py` still assembled from the
pre-move location.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 01:31:09 +02:00

151 lines
5.9 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,
*,
priority: bool = False,
identifier: str = "0",
covered: str = "0",
clone: bool = False,
) -> dict:
return {
"apps": app,
"variant": variant,
"mode": mode,
"tor": "true" if variant == "0" else "false",
"disable": "",
"priority": "true" if priority else "false",
"weight": "42",
"id": identifier,
"covered": covered,
"clone": "true" if clone else "false",
"distro": "debian",
"filesystem": "zfs",
"label": f"{to_emoji(mode)}{app} {variant}",
}
_PRIORITY = [_entry("web-app-a", "0", "compose", priority=True, identifier="3")]
_REGULAR = [
_entry("web-app-b", "0", "swarm", 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_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_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_tor_state_is_rendered_as_its_glyph(self) -> None:
rows = plan.cells(_ENTRIES, [_PRIORITY, _REGULAR])
tor = plan._COLUMNS.index("tor")
self.assertEqual(rows[0][tor], to_emoji("tor"))
self.assertEqual(rows[2][tor], to_emoji("clearnet"))
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))
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_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()