diff --git a/tests/integration/test_host_agent_alerts.py b/tests/integration/test_host_agent_alerts.py index 50075a1..b66cfc2 100644 --- a/tests/integration/test_host_agent_alerts.py +++ b/tests/integration/test_host_agent_alerts.py @@ -1,6 +1,10 @@ """Integration: a host-agent ingest POST evaluates alert rules on the host's metrics (#5060). Before, ingest wrote rows straight to plugin_metrics and no -host_agent rule could ever fire.""" +host_agent rule could ever fire. + +The agent registration is seeded with plain SQL: importing the plugin's +models again after the app loaded the plugin raises "Table already defined" +(see test_mcp_plugin_tools).""" from __future__ import annotations import asyncio @@ -23,8 +27,7 @@ def app(): def test_ingest_fires_a_host_rule_from_a_backlog(app): - from sqlalchemy import select - from plugins.host_agent.models import HostAgentRegistration + from sqlalchemy import select, text from steward.alerts import service as alert_svc from steward.models.alerts import AlertEvent, AlertState, AlertStateEnum from steward.models.hosts import Host @@ -41,8 +44,12 @@ def test_ingest_fires_a_host_rule_from_a_backlog(app): host = Host(name=hostname, address="10.9.9.9") s.add_all([user, host]) await s.flush() - s.add(HostAgentRegistration( - host_id=host.id, token_hash=hashlib.sha256(token.encode()).hexdigest())) + await s.execute(text( + "INSERT INTO host_agent_registrations " + "(id, host_id, token_hash, token_created_at, created_at, updated_at) " + "VALUES (:id, :host, :hash, now(), now(), now())"), + {"id": str(uuid.uuid4()), "host": host.id, + "hash": hashlib.sha256(token.encode()).hexdigest()}) s.add(PluginMetric(source_module="host_agent", resource_name=hostname, metric_name="cpu_pct", value=5.0)) await s.flush()