test(alerts): seed the agent registration with SQL, not a second model import (#5060)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m9s
CI / unit (push) Successful in 1m10s
CI / publish (push) Successful in 1m0s

Importing plugins.host_agent.models after the app loaded the plugin defines
host_agent_registrations twice (run 8310).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 12:56:10 -04:00
co-authored by Claude Opus 5.5
parent 0742b7a2b7
commit da0c6cad17
+12 -5
View File
@@ -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()