Files
FabledSteward/tests/core/test_audit_page.py
T
bvandeusenandClaude Opus 5.5 414c942cbf
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 1m5s
CI / unit (push) Successful in 1m19s
CI / publish (push) Successful in 57s
feat(plugins): Traefik problems first, UniFi/SNMP/fleet on shared shapes, audit names its entities, templates on tokens (#5126)
Traefik: routers are graded from their latest scrape (router_state: crit on
any real 5xx share, warn on p95 past the latency critical cutoff or a high
4xx share). Failing and slow routers lead as cards that say why; healthy
ones fold into one table that stays open or shut across polls. Proxy
counts are stat tiles; certificates are graded by Settings -> Thresholds
(tls_days).

UniFi: WAN health is a stat strip (latency graded by the thresholds),
devices carry status dots, event categories and firewall actions are
badges, the alarm count reuses .count-badge (renamed from .nav-count).
SNMP: each device wears a status badge and its readings are stat tiles.

Agent fleet: the table comes first, with a Status column (Reporting /
Silent / Never reported, by the host page's stale_after_seconds), silent
agents first, hosts linked, last seen as |ago.

Audit: entries name their entity (one query per type, steward/audit/
service.py) and link it; something deleted since keeps the name its entry
recorded and says "(deleted)".

Tokens: charts read colours through chart-colors.js (stewardColor resolves
a token to the rgb the browser computed; Chart.js defaults take the page's
text and border colours), so host, history, Traefik and SNMP charts drop
their hex. Template hex colours reach 0 (HEX_CEILING = 0), the last rgba
pills go, and heavy weights (600/700/bold, 60 of them) become 500, the
house pair being 400/500; a guard keeps templates there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:25:09 -04:00

46 lines
2.1 KiB
Python

"""Audit entries name the thing they are about, linked to its page, and keep
the recorded name of something deleted since (#5126)."""
from datetime import datetime, timezone
from types import SimpleNamespace as NS
from quart import render_template
from steward.audit.service import entity_labels
class _Empty:
"""A session whose every query finds nothing: every entity was deleted."""
async def execute(self, _stmt):
return NS(all=lambda: [], scalars=lambda: NS(all=lambda: []))
def _ev(etype, eid, action="x.y"):
return NS(entity_type=etype, entity_id=eid, action=action, username="admin",
timestamp=datetime(2026, 10, 6, 12, 0, tzinfo=timezone.utc))
async def test_a_deleted_entity_keeps_the_name_its_entry_recorded():
items = [{"event": _ev("host", "h-123456789"), "detail": {"name": "web-1"}},
{"event": _ev("monitor", "m-abcdef012"), "detail": {}},
{"event": _ev("plugin", "docker"), "detail": {}},
{"event": _ev(None, None), "detail": {}}]
labels = await entity_labels(_Empty(), items)
assert labels[("host", "h-123456789")] == {"label": "web-1", "url": None, "gone": True}
assert labels[("monitor", "m-abcdef012")] == {"label": "m-abcdef", "url": None, "gone": True}
assert labels[("plugin", "docker")] == {"label": "docker", "url": "/settings/plugins/", "gone": False}
assert len(labels) == 3
async def test_the_page_names_and_links_the_entity(app):
events = [
{"event": _ev("host", "h1", "host.renamed"), "detail": {"old": "a", "new": "b"},
"entity": {"label": "web-1", "url": "/hosts/h1", "gone": False}},
{"event": _ev("monitor", "m9", "monitor.deleted"), "detail": {},
"entity": {"label": "api check", "url": None, "gone": True}},
]
async with app.test_request_context("/audit/"):
page = await render_template("audit/list.html", events=events, limit=200, action_filter="")
assert '<a href="/hosts/h1">web-1</a>' in page
assert "api check" in page and "(deleted)" in page
assert "h1</td>" not in page # no bare id where a name is known