import httpx
from app.agent_runs import AgentRunRepository
from app.constants import CHECKMK_DT_ENABLED, CHECKMK_DT_SECRET, CHECKMK_DT_USER, FLAG_ON
from app.downtime import CheckmkDowntimeClient
from tests.test_web import (VIEWER, admin, app, client, csrf_from, login_ok, post, # noqa: F401
users, viewer)
DT_SECRET = "downtime-geheimnis-xyz"
def make_run(app, question="Warum CPU?", steps=None, abort=None):
repo = AgentRunRepository(app.state.db)
steps = steps if steps is not None else [
{"number": 1, "tool": "get_service_status", "arguments": {"host": "web01"}, "result": "",
"duration": 0.5, "error": None}]
return repo.insert(1_700_000_000, "telegram", "111", "ask", question, "Antwort x", abort, steps)
def test_agent_pages_require_admin(client, app, viewer):
run_id = make_run(app)
assert client.get("/agent").status_code == 303
login_ok(client, VIEWER)
assert client.get("/agent").status_code == 403
assert client.get(f"/agent/{run_id}").status_code == 403
assert "/agent" not in client.get("/").text
def test_agent_list_and_detail_for_admin_escaped(client, app, admin):
run_id = make_run(app, abort="step_limit")
login_ok(client)
assert 'href="/agent"' in client.get("/").text
page = client.get("/agent")
assert page.status_code == 200 and f"/agent/{run_id}" in page.text and "Schrittlimit" in page.text
assert "CPU" not in page.text and "<b>CPU</b>" in page.text
detail = client.get(f"/agent/{run_id}")
assert detail.status_code == 200 and "get_service_status" in detail.text and "host=web01" in detail.text
assert "" not in detail.text and "<script>" in detail.text
assert "Antwort <i>x</i>" in detail.text and "