#5211 "Lists load as you scroll: audit, alert history, Ansible runs" (milestone 477), per preference 172. - core/paging.py: keyset paging over (time, id), newest first, with an opaque "<iso>|<id>" cursor; a page reads one row past itself to know whether another follows. No OFFSET, so rows added while someone scrolls never shift the pages after them. - _macros.html scroll_more / scroll_end and static/scroll-more.js, written once: an IntersectionObserver with a 600px margin fetches the next page before the reader reaches the end; "Loading more…" while in flight, "End of the list." at the end, and a failed page says so with a Retry button instead of re-firing on every scroll. - Audit log: no "Load more" link and no 500-row cap. - Alert history: no 200-row stop with "pick a shorter range"; alert_svc.history takes the cursor, so the MCP tool and the page share one query. - Ansible runs: no silent cap of 50. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.8 KiB
Python
59 lines
2.8 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, after=None, 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
|
|
|
|
|
|
|
|
async def test_the_log_continues_itself_instead_of_a_load_more_link(app):
|
|
events = [{"event": _ev("host", "h1", "host.renamed"), "detail": {}, "entity": None}]
|
|
async with app.test_request_context("/audit/"):
|
|
more = await render_template("audit/list.html", events=events,
|
|
after="2026-10-07T03:00:00+00:00|0190abc", action_filter="host.")
|
|
last = await render_template("audit/_rows.html", events=events, after=None, action_filter="")
|
|
assert ('data-scroll-more hx-get="/audit/?before=2026-10-07T03%3A00%3A00%2B00%3A00%7C0190abc'
|
|
'&action=host."') in more
|
|
assert "Load more" not in more
|
|
assert "data-scroll-more" not in last and "End of the list." in last
|