From 19372c8a9aa33f3bd5f33a165c4c13ccf5785333 Mon Sep 17 00:00:00 2001 From: codex Date: Tue, 21 Apr 2026 04:52:05 -0300 Subject: [PATCH] test(ariadne): cover VM trend filters --- .../services/test_cluster_state_vm_domains.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/services/test_cluster_state_vm_domains.py b/tests/unit/services/test_cluster_state_vm_domains.py index 34cbd56..6365d64 100644 --- a/tests/unit/services/test_cluster_state_vm_domains.py +++ b/tests/unit/services/test_cluster_state_vm_domains.py @@ -228,6 +228,32 @@ def test_vm_trend_helpers(monkeypatch) -> None: assert vm_trends._pods_phase_trends()["1h"]["running"]["avg"] == 2.0 +def test_vm_trend_helpers_filter_malformed_vectors(monkeypatch) -> None: + monkeypatch.setattr( + vm_trends, + "_vm_vector", + lambda _expr: [ + "bad", + {"metric": {"namespace": "apps"}, "value": 5.0}, + {"metric": {"namespace": 3, "job_name": "bad"}, "value": 4.0}, + {"metric": {"namespace": "apps", "job_name": "api"}, "value": 3.0}, + ], + ) + assert vm_trends._job_failure_trend("1h") == [{"namespace": "apps", "job": "api", "value": 3.0}] + + monkeypatch.setattr( + vm_trends, + "_vm_vector", + lambda _expr: [ + "bad", + {"metric": {"namespace": "apps"}, "value": 5.0}, + {"metric": {"namespace": "apps", "pod": 3}, "value": 4.0}, + {"metric": {"namespace": "apps", "pod": "api"}, "value": 3.0}, + ], + ) + assert vm_trends._pod_reason_entries("expr", 5) == [{"namespace": "apps", "pod": "api", "value": 3.0}] + + def test_vm_usage_helpers(monkeypatch) -> None: monkeypatch.setattr(vm_usage, "_vm_scalar", lambda _expr: 10.0) monkeypatch.setattr(