from router_system.cache import RouterCache def test_exact_hit(): c = RouterCache() result = {"response": "hello", "domain": "general"} assert c.get("query") is None c.put("query", result) level, got = c.get("query") assert level == "exact" assert got["response"] == "hello" def test_semantic_hit(): c = RouterCache(semantic_enabled=True, similarity_threshold=0.5) c.put("?python?????", {"response": "code", "domain": "code"}) # ?????????? L2 hit = c.get("?python????????") assert hit is not None assert hit[0] == "semantic" def test_promote_to_exact(): c = RouterCache(promote_frequency=3) result = {"response": "x", "domain": "general"} c.put("query", result) # ?????? 3 ? ? ??????? for _ in range(3): hit = c.get("query") assert hit is not None assert c.stats()["exact_size"] == 1 def test_stats(): c = RouterCache() c.put("q", {"response": "r"}) c.get("q") c.get("q") c.get("miss") s = c.stats() assert s["exact_hits"] == 2 assert s["misses"] == 1