mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +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>
107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
"""Unit tests for the unified suppression-marker grammar."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from utils.annotations.suppress import (
|
|
is_suppressed_anywhere,
|
|
is_suppressed_at,
|
|
is_suppressed_in_head,
|
|
line_has_rule,
|
|
suppressed_line_numbers,
|
|
)
|
|
|
|
|
|
class TestLineHasRule(unittest.TestCase):
|
|
def test_noqa_and_nocheck_are_synonyms(self):
|
|
self.assertTrue(line_has_rule("# noqa: url", "url"))
|
|
self.assertTrue(line_has_rule("# nocheck: url", "url"))
|
|
|
|
def test_case_insensitive(self):
|
|
self.assertTrue(line_has_rule("# NOQA: URL", "url"))
|
|
self.assertTrue(line_has_rule("# NoCheck: Url", "url"))
|
|
|
|
def test_html_jinja_and_slash_prefixes(self):
|
|
self.assertTrue(line_has_rule("<!-- nocheck: url -->", "url"))
|
|
self.assertTrue(line_has_rule("{# nocheck: url #}", "url"))
|
|
self.assertTrue(line_has_rule("// noqa: url", "url"))
|
|
|
|
def test_inline_marker_in_code(self):
|
|
line = 'tokens.append("https://example.org") # nocheck: url'
|
|
self.assertTrue(line_has_rule(line, "url"))
|
|
|
|
def test_multi_rule_comma_separated(self):
|
|
line = "# noqa: shared, email"
|
|
self.assertTrue(line_has_rule(line, "shared"))
|
|
self.assertTrue(line_has_rule(line, "email"))
|
|
self.assertFalse(line_has_rule(line, "url"))
|
|
|
|
def test_unrelated_text_does_not_match(self):
|
|
self.assertFalse(line_has_rule("# this is just a comment", "url"))
|
|
self.assertFalse(line_has_rule("noqa url", "url")) # missing colon
|
|
|
|
def test_word_boundary_avoids_false_positives(self):
|
|
self.assertFalse(line_has_rule("# nocheck: url-other", "url"))
|
|
self.assertTrue(line_has_rule("# nocheck: url-other", "url-other"))
|
|
|
|
|
|
class TestIsSuppressedAt(unittest.TestCase):
|
|
def test_same_line_mode(self):
|
|
lines = ["x = 1", "y = 2 # nocheck: url"]
|
|
self.assertTrue(is_suppressed_at(lines, 2, "url", mode="same-line"))
|
|
self.assertFalse(is_suppressed_at(lines, 1, "url", mode="same-line"))
|
|
|
|
def test_line_above_mode(self):
|
|
lines = ["# nocheck: docker-version", "version: 1.2.3"]
|
|
self.assertTrue(is_suppressed_at(lines, 2, "docker-version", mode="line-above"))
|
|
self.assertFalse(is_suppressed_at(lines, 2, "docker-version", mode="same-line"))
|
|
|
|
def test_line_above_skips_blank_lines(self):
|
|
lines = ["# noqa: email", "", "", "email:"]
|
|
self.assertTrue(is_suppressed_at(lines, 4, "email", mode="line-above"))
|
|
|
|
def test_default_mode_accepts_either(self):
|
|
same = ["foo # nocheck: url"]
|
|
above = ["# nocheck: url", "foo"]
|
|
self.assertTrue(is_suppressed_at(same, 1, "url"))
|
|
self.assertTrue(is_suppressed_at(above, 2, "url"))
|
|
|
|
def test_out_of_range_returns_false(self):
|
|
self.assertFalse(is_suppressed_at([], 1, "url"))
|
|
self.assertFalse(is_suppressed_at(["x"], 0, "url"))
|
|
self.assertFalse(is_suppressed_at(["x"], 999, "url"))
|
|
|
|
|
|
class TestFileLevelHelpers(unittest.TestCase):
|
|
def test_head_marker_within_scan_window(self):
|
|
lines = ['"""docstring."""', "# nocheck: file-size", "rest = 1"]
|
|
self.assertTrue(is_suppressed_in_head(lines, "file-size", scan_lines=30))
|
|
|
|
def test_head_marker_outside_scan_window_misses(self):
|
|
lines = ["x = 1"] * 40 + ["# nocheck: file-size"]
|
|
self.assertFalse(is_suppressed_in_head(lines, "file-size", scan_lines=30))
|
|
|
|
def test_anywhere_marker(self):
|
|
lines = ["x = 1"] * 100 + ["# nocheck: run-once"]
|
|
self.assertTrue(is_suppressed_anywhere(lines, "run-once"))
|
|
|
|
def test_anywhere_no_match(self):
|
|
self.assertFalse(is_suppressed_anywhere(["x", "y"], "run-once"))
|
|
|
|
|
|
class TestSuppressedLineNumbers(unittest.TestCase):
|
|
def test_returns_one_based_line_numbers(self):
|
|
lines = [
|
|
"# unrelated",
|
|
"# noqa: url",
|
|
"x # nocheck: url",
|
|
"# noqa: shared",
|
|
]
|
|
self.assertEqual(suppressed_line_numbers(lines, "url"), {2, 3})
|
|
self.assertEqual(suppressed_line_numbers(lines, "shared"), {4})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|