style: repo-wide lint pass — make the lint gate green again

Push builds have been RED on the lint step since ~build 209 from accumulated
formatting drift. This is the mechanical cleanup: ruff format + ruff --fix
(UP038 isinstance unions, SIM105 contextlib.suppress, UP031 f-strings, SIM115
tempfile context manager), shfmt -i 2 -ci, nixpkgs-fmt/statix/deadnix (merged
attrsets, dropped unused lib args), yamllint, and shell quoting fixes in
tests/lasuite-docs/setup_custom_tests.sh. No behaviour changes intended;
lint: PASS, unit tests: 138 passed.
This commit is contained in:
2026-06-09 21:56:15 +00:00
parent e76d4005ab
commit 9a7772563a
115 changed files with 952 additions and 660 deletions

View File

@ -12,9 +12,8 @@ import os
import sys
import tempfile
_tok = tempfile.NamedTemporaryFile("w", delete=False, suffix=".tok")
_tok.write("test-token")
_tok.close()
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".tok") as _tok:
_tok.write("test-token")
os.environ["DRONE_TOKEN_FILE"] = _tok.name
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "dashboard"))
@ -23,10 +22,17 @@ import dashboard # noqa: E402
def _row(**kw):
base = {
"recipe": "custom-html", "status": "success", "number": 4, "ref": "db9a9502",
"version": "db9a95024e9d", "level": 4, "level_cap_reason": "",
"has_screenshot": True, "flags": {"clean_teardown": True, "no_secret_leak": True},
"finished": 0, "url": "https://drone.x/cc-ci/4",
"recipe": "custom-html",
"status": "success",
"number": 4,
"ref": "db9a9502",
"version": "db9a95024e9d",
"level": 4,
"level_cap_reason": "",
"has_screenshot": True,
"flags": {"clean_teardown": True, "no_secret_leak": True},
"finished": 0,
"url": "https://drone.x/cc-ci/4",
}
base.update(kw)
return base
@ -43,24 +49,33 @@ def test_level_color_ramp_and_fallback():
def test_overview_grid_mirrors_results():
out = dashboard.render_overview([_row()])
assert "custom-html" in out
assert "level 4" in out # the corner level pill
assert dashboard.level_color(4) in out # coloured by level
assert "db9a95024e9d" in out # version from results.json
assert "/runs/4/screenshot.png" in out # thumbnail
assert "/runs/4/summary.png" in out # links to full card
assert "/recipe/custom-html" in out # history link
assert "level 4" in out # the corner level pill
assert dashboard.level_color(4) in out # coloured by level
assert "db9a95024e9d" in out # version from results.json
assert "/runs/4/screenshot.png" in out # thumbnail
assert "/runs/4/summary.png" in out # links to full card
assert "/recipe/custom-html" in out # history link
assert "✔ teardown" in out and "✔ no-leak" in out
def test_overview_never_greener_than_data():
# A failed run at level 0 must show level 0 + the failure pill — never a green/high level.
out = dashboard.render_overview([_row(status="failure", level=0, has_screenshot=False,
flags={}, level_cap_reason="L1 install FAILED")])
out = dashboard.render_overview(
[
_row(
status="failure",
level=0,
has_screenshot=False,
flags={},
level_cap_reason="L1 install FAILED",
)
]
)
assert "level 0" in out
assert dashboard.level_color(0) in out # red
assert dashboard.level_color(0) in out # red
assert dashboard._COLORS["failure"] in out
assert "level 4" not in out and "level 5" not in out and "level 6" not in out
assert "no screenshot" in out # placeholder, no broken image
assert "no screenshot" in out # placeholder, no broken image
def test_level_pill_unknown_when_no_results():
@ -74,7 +89,7 @@ def test_history_table_lists_runs():
assert "#4" in out and "#3" in out
assert "L4" in out and "L2" in out
assert "← all recipes" in out
assert "/runs/4/summary.png" in out # per-run card link
assert "/runs/4/summary.png" in out # per-run card link
def test_history_empty():
@ -83,12 +98,24 @@ def test_history_empty():
def test_build_row_projects_results(monkeypatch):
monkeypatch.setattr(dashboard, "_results_for", lambda n: {
"version": "1.2.3", "level": 2, "level_cap_reason": "cap",
"screenshot": "screenshot.png", "flags": {"clean_teardown": True},
})
b = {"number": 7, "status": "success", "event": "custom",
"params": {"RECIPE": "n8n", "REF": "abcdef1234567890"}, "finished": 10}
monkeypatch.setattr(
dashboard,
"_results_for",
lambda n: {
"version": "1.2.3",
"level": 2,
"level_cap_reason": "cap",
"screenshot": "screenshot.png",
"flags": {"clean_teardown": True},
},
)
b = {
"number": 7,
"status": "success",
"event": "custom",
"params": {"RECIPE": "n8n", "REF": "abcdef1234567890"},
"finished": 10,
}
r = dashboard._build_row(b)
assert r["recipe"] == "n8n" and r["number"] == 7
assert r["level"] == 2 and r["version"] == "1.2.3"
@ -99,11 +126,16 @@ def test_build_row_projects_results(monkeypatch):
def test_build_row_degrades_without_results(monkeypatch):
# No results.json (e.g. an old run): grid still renders from Drone fields, level absent.
monkeypatch.setattr(dashboard, "_results_for", lambda n: {})
b = {"number": 9, "status": "running", "event": "custom",
"params": {"RECIPE": "ghost", "REF": "deadbeefcafe1234567890"}, "finished": 0}
b = {
"number": 9,
"status": "running",
"event": "custom",
"params": {"RECIPE": "ghost", "REF": "deadbeefcafe1234567890"},
"finished": 0,
}
r = dashboard._build_row(b)
assert r["level"] is None and r["has_screenshot"] is False
assert r["version"] == "deadbeefcafe" # ref[:12] fallback
assert r["version"] == "deadbeefcafe" # ref[:12] fallback
# render must not crash or claim a level
assert "level —" in dashboard.render_overview([r])
@ -111,7 +143,7 @@ def test_build_row_degrades_without_results(monkeypatch):
def test_level_badge_shows_level_coloured(monkeypatch):
svg = dashboard.render_level_badge("custom-html", 4)
assert "custom-html" in svg and "level 4" in svg
assert dashboard.level_color(4) in svg # coloured by level
assert dashboard.level_color(4) in svg # coloured by level
assert svg.startswith("<svg") and "image" not in svg # plain SVG
# A higher displayed level than earned would be inflation — badge shows exactly the given level.
assert "level 5" not in svg and "level 6" not in svg
@ -133,8 +165,8 @@ def test_results_for_traversal_guarded():
dashboard.CCCI_RUNS_DIR = d
try:
assert dashboard._results_for("5") == {"level": 3}
assert dashboard._results_for("../../etc") == {} # traversal rejected
assert dashboard._results_for("nonexist") == {} # missing → {}
assert dashboard._results_for("../../etc") == {} # traversal rejected
assert dashboard._results_for("nonexist") == {} # missing → {}
assert dashboard._results_for("") == {}
finally:
dashboard.CCCI_RUNS_DIR = orig