File size: 2,580 Bytes
28308b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest

from scripts.model_catalog_scan import diff_catalogs
from scripts.model_catalog_notify import build_body


class ModelCatalogDiffTests(unittest.TestCase):
    def test_reports_exact_added_removed_and_unavailable_models(self):
        previous = {"state": {"groq/A": {"provider": "groq", "profile": "A", "status": "available", "models": ["old-model", "stable-model"]}}}
        current = {"state": {"groq/A": {"provider": "groq", "profile": "A", "status": "available", "models": ["new-model", "stable-model"], "default_model": "old-model", "default_available": False}}}
        result = diff_catalogs(previous, current)
        self.assertEqual(result["added_models"][0]["model"], "new-model")
        self.assertEqual(result["removed_models"][0]["model"], "old-model")
        self.assertEqual(result["unavailable_defaults"][0]["model"], "old-model")
        self.assertTrue(result["has_changes"])

    def test_reports_provider_errors_with_exact_status(self):
        current = {"state": {"gemini/default": {"provider": "gemini", "profile": "default", "status": "rate_limited", "models": [], "detail": "retry after 60"}}}
        result = diff_catalogs({}, current)
        self.assertEqual(result["provider_errors"][0]["status"], "rate_limited")
        self.assertIn("gemini", result["provider_errors"][0]["provider"])

    def test_empty_profile_configuration_is_reported(self):
        from scripts.model_catalog_scan import audit_payload
        from benchmarks.model_watch_adapter import ModelWatchConfig, ObserveOnlyModelsAdapter
        from types import SimpleNamespace
        payload = audit_payload(SimpleNamespace(results=(), skipped_rate_limited=()), ObserveOnlyModelsAdapter(config=ModelWatchConfig()), [], {})
        self.assertEqual(payload["profile_count"], 0)
        self.assertTrue(payload["diff"]["has_changes"])
        self.assertEqual(payload["diff"]["provider_errors"][0]["status"], "missing_profiles")

    def test_notification_contains_exact_names_and_closed_gate(self):
        body = build_body({
            "auto_apply_gate_open": False,
            "diff": {
                "added_models": [{"provider": "groq", "profile": "A", "model": "new-model"}],
                "removed_models": [{"provider": "groq", "profile": "A", "model": "old-model"}],
                "unavailable_defaults": [],
                "provider_errors": [],
            },
        })
        self.assertIn("new-model", body)
        self.assertIn("old-model", body)
        self.assertIn("CHIUSA", body)


if __name__ == "__main__":
    unittest.main()