Files
FabledSteward/tests/core/test_steward_health.py
T
bvandeusenandClaude Opus 5.5 e98dd10556
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 1m8s
CI / unit (push) Successful in 1m27s
CI / publish (push) Successful in 1m2s
fix(ui): a reading's age no longer puts a <time> element inside a title attribute (#5467)
The `when` filter returns a <time> element, so title="{{ at|when }}" wrote raw
markup into the attribute. That broke the hover text, and in the rule form's
metric preview (#5475) it leaked a stray `">` into the page. `ago` already
carries the exact time as its own tooltip, so both places drop the title.
Also fixes #5467's page test, which needed the escaped apostrophe.

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

62 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Settings → System (#5467): Steward's own health, a verdict then each measure
now and over the day. The verdict names what is wrong, and only that."""
from datetime import datetime, timezone
import pytest
from quart import render_template, session
from steward.core import health
AT = datetime(2026, 10, 9, 12, 0, tzinfo=timezone.utc)
def _previews(**over):
base = {m: {"now": 0.0, "at": AT, "series": [0.0, 0.0], "low": 0.0, "high": 0.0}
for m in health.PROCESS_METRICS}
base["db_roundtrip_ms"] = {"now": 4.0, "at": AT, "series": [3.0, 5.0], "low": 2.0, "high": 9.0}
for m, v in over.items():
base[m] = {**base[m], **v}
return base
@pytest.fixture
def previews(monkeypatch):
def use(**over):
got = _previews(**over)
async def fake(db, source, resource, metric, now=None):
assert (source, resource) == ("steward", "process")
return got[metric]
monkeypatch.setattr("steward.alerts.service.metric_preview", fake)
return use
async def test_a_healthy_steward_has_no_problems(previews):
previews()
got = await health.process_health(None)
assert got["seen"] and got["problems"] == []
assert [r["metric"] for r in got["rows"]] == health.PROCESS_METRICS
async def test_failures_and_gaps_are_named(previews):
previews(ingest_failed={"now": 2.0, "high": 2.0}, unwatched_secs={"high": 420.0},
open_fds_pct={"now": 85.0})
problems = (await health.process_health(None))["problems"]
assert problems[0] == "2 agent posts failed in the last minute"
assert "wasn't watching for up to 7m" in problems[1]
assert problems[2] == "open files at 85% of the limit"
async def test_the_page_reads_as_a_verdict_then_each_measure(app, previews):
previews(unwatched_secs={"high": 420.0})
got = await health.process_health(None)
for r in got["rows"]:
r["spark"] = ""
async with app.test_request_context("/settings/system/"):
session["user_role"] = "admin"
page = " ".join((await render_template("settings/system.html", **got)).split())
assert '<span class="tone-warn">Steward wasn&#39;t watching for up to 7m' in page
assert 'title="<' not in page # a <time> element never lands inside an attribute
assert "Database round trip" in page and "4 ms" in page and "2 ms – 9 ms" in page
assert page.index("page-verdict") < page.index("Agent posts per minute")