mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-07 03:15:56 +00:00
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>
119 lines
4.0 KiB
Python
119 lines
4.0 KiB
Python
import argparse
|
|
import io
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from contextlib import redirect_stderr, redirect_stdout
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from cli.meta.ci.logs.download import fetch, github
|
|
from cli.meta.ci.logs.download.__main__ import (
|
|
_build_parser,
|
|
_selected_conclusions,
|
|
main,
|
|
)
|
|
|
|
_RUN_URL = "https://github.com/o/r/actions/runs/123" # nocheck: url
|
|
|
|
|
|
class TestResolveRun(unittest.TestCase):
|
|
def test_url(self):
|
|
self.assertEqual(github.resolve_run(_RUN_URL, None), ("o", "r", "123"))
|
|
|
|
def test_url_with_job_suffix(self):
|
|
self.assertEqual(
|
|
github.resolve_run(_RUN_URL + "/job/456", None), ("o", "r", "123")
|
|
)
|
|
|
|
def test_bare_id_with_repo_override(self):
|
|
self.assertEqual(
|
|
github.resolve_run("123", "acme/widget"), ("acme", "widget", "123")
|
|
)
|
|
|
|
def test_bare_id_resolves_current_repo(self):
|
|
with patch.object(github, "gh", return_value="acme/widget\n"):
|
|
self.assertEqual(github.resolve_run("123", None), ("acme", "widget", "123"))
|
|
|
|
def test_garbage_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
github.resolve_run("not-a-run", None)
|
|
|
|
|
|
class TestSelectedConclusions(unittest.TestCase):
|
|
@staticmethod
|
|
def _ns(**flags):
|
|
base = {"success": False, "failed": False, "cancelled": False, "skipped": False}
|
|
base.update(flags)
|
|
return argparse.Namespace(**base)
|
|
|
|
def test_none_selected_returns_none(self):
|
|
self.assertIsNone(_selected_conclusions(self._ns()))
|
|
|
|
def test_failed_maps_to_failure(self):
|
|
self.assertEqual(_selected_conclusions(self._ns(failed=True)), {"failure"})
|
|
|
|
def test_multiple(self):
|
|
self.assertEqual(
|
|
_selected_conclusions(self._ns(success=True, cancelled=True)),
|
|
{"success", "cancelled"},
|
|
)
|
|
|
|
|
|
class TestWriteManifest(unittest.TestCase):
|
|
def test_writes_jobs_json_and_summary(self):
|
|
jobs = [
|
|
{"id": 1, "name": "A", "conclusion": "failure", "status": "completed"},
|
|
{"id": 2, "name": "B", "conclusion": None, "status": "in_progress"},
|
|
]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
dest = Path(tmp)
|
|
fetch.write_manifest(jobs, dest)
|
|
jobs_json = (dest / "jobs.json").read_text() # nocheck: cache-read
|
|
self.assertEqual(json.loads(jobs_json), jobs)
|
|
summary_text = (dest / "summary.tsv").read_text() # nocheck: cache-read
|
|
summary = summary_text.splitlines()
|
|
self.assertEqual(summary[0], "id\tconclusion\tstatus\tname")
|
|
self.assertEqual(summary[1], "1\tfailure\tcompleted\tA")
|
|
self.assertEqual(summary[2], "2\t\tin_progress\tB")
|
|
|
|
|
|
class TestParser(unittest.TestCase):
|
|
def test_defaults(self):
|
|
args = _build_parser().parse_args(["123"])
|
|
self.assertEqual(args.run, "123")
|
|
self.assertFalse(args.failed)
|
|
self.assertIsNone(args.destination)
|
|
|
|
def test_flags(self):
|
|
args = _build_parser().parse_args(["123", "-f", "-d", "/x", "-j", "4"])
|
|
self.assertTrue(args.failed)
|
|
self.assertEqual(args.destination, "/x")
|
|
self.assertEqual(args.jobs, 4)
|
|
|
|
|
|
class TestMain(unittest.TestCase):
|
|
def test_smoke_no_jobs(self):
|
|
with (
|
|
tempfile.TemporaryDirectory() as tmp,
|
|
patch(
|
|
"cli.meta.ci.logs.download.__main__.resolve_run",
|
|
return_value=("o", "r", "1"),
|
|
),
|
|
patch("cli.meta.ci.logs.download.__main__.list_jobs", return_value=[]),
|
|
):
|
|
buf = io.StringIO()
|
|
with redirect_stdout(buf):
|
|
rc = main(["1", "--no-artifacts", "-d", tmp])
|
|
self.assertEqual(rc, 0)
|
|
self.assertIn("done", buf.getvalue())
|
|
|
|
def test_bad_run_ref_returns_2(self):
|
|
with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
|
|
rc = main(["not-a-run", "--no-logs", "--no-artifacts"])
|
|
self.assertEqual(rc, 2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|