"""The rule form's Resource and Metric pickers read the latest-value table, one row per series, never the raw history: a DISTINCT over plugin_metrics reads every sample and held the rule page for up to 15 s on host_agent.""" from types import SimpleNamespace from steward.alerts import service as alert_svc async def _sql(fn, source) -> list[str]: """The SQL `fn` sends for `source`, against a session that returns no rows.""" sent: list[str] = [] async def execute(stmt): sent.append(str(stmt.compile(compile_kwargs={"literal_binds": True}))) return [] await fn(SimpleNamespace(execute=execute), source) return sent async def test_resources_come_from_the_latest_value_table(): (sql,) = await _sql(alert_svc.resources_for, "host_agent") assert "FROM plugin_metric_latest" in sql and "plugin_metrics" not in sql async def test_a_dynamic_source_s_metrics_come_from_the_latest_value_table(): (sql,) = await _sql(alert_svc.metrics_for, "snmp") assert "FROM plugin_metric_latest" in sql and "plugin_metrics" not in sql