forge
Explore
Log in

Don't you dare go Hollow

hezarfen_zeka

Clone
★ 0

0 watching0 forksPython1.9 MiBe01a4faAhmet Kaan Gümüş2 months ago25 commits

test_capabilities.py124 lines, 5.1 KiBHistoryRawDownload
1"""Yetenek defterinin testleri.
2
3Buradaki en onemli test bir GERCEGI pinler: backend'in ZEKA'ya gonderebildigi
4adlar `chat.reply`, `rag.index`, `insight.student`, `insight.refresh`tir;
5`insight.class` ilan edilir ama backend'de onu gonderen bir yol yoktur. Bu,
6servisin backend'i cagirdigi depo yolundan (2. yon, `insight.*` -- calisir)
7AYRI bir yondur. Iki taraf da degistiginde bu testler ve
8`docs/BACKEND-GEREKSINIMLERI.md` madde 1 birlikte guncellenir.
9"""
10
11from __future__ import annotations
12
13import unittest
14
15from src import capabilities, handlers
16from src.protocol import CapabilityError
17
18
19class CapabilityNameTests(unittest.TestCase):
20 def test_declared_names(self):
21 self.assertEqual(
22 capabilities.NAMES,
23 ("insight.student", "insight.class", "insight.refresh", "insight.report"),
24 )
25
26 def test_backend_callable_set_is_the_dispatch_table(self):
27 # constant.rs:568,574 (chat.reply, rag.index) + ai/insight.rs
28 # (compute_student/refresh/**report**) ve web/insights.rs kapilari --
29 # 2026-09-18. `insight.report`in sabiti (constant.rs:645), dagitimi ve
30 # `POST /runs/{run_day}/report` kapisi ayni gun landedi.
31 self.assertEqual(
32 capabilities.BACKEND_CALLABLE_CAPABILITIES,
33 (
34 "chat.reply",
35 "rag.index",
36 "insight.student",
37 "insight.refresh",
38 "insight.report",
39 ),
40 )
41 # `insight.class` ilan edilir ama backend GONDERMEZ (kadro listeleme
42 # yolu yok). Backend tarafi acildiginda bu satiri ve
43 # docs/BACKEND-GEREKSINIMLERI.md Madde 1'i birlikte guncelleyin.
44 self.assertEqual(
45 set(capabilities.NAMES) - set(capabilities.BACKEND_CALLABLE_CAPABILITIES),
46 {"insight.class"},
47 )
48
49 def test_sections_vocabulary_is_the_summary_modules(self):
50 self.assertEqual(
51 capabilities.SECTIONS, ("marks", "attendance", "submission", "study")
52 )
53
54 def test_every_name_has_a_schema(self):
55 self.assertEqual(set(capabilities.SCHEMAS), set(capabilities.NAMES))
56 for request_type, response_type in capabilities.SCHEMAS.values():
57 self.assertTrue(hasattr(request_type, "__annotations__"))
58 self.assertTrue(hasattr(response_type, "__annotations__"))
59
60 def test_student_payload_carries_no_school(self):
61 # Okul cerceve seviyesindedir (ai/protocol.rs:36-47); payload'da ikinci
62 # bir kaynak olmasi ikisinin celisebilecegi bir yer yaratirdi.
63 self.assertNotIn("school", capabilities.StudentRequest.__annotations__)
64 self.assertNotIn("school", capabilities.ClassRequest.__annotations__)
65 self.assertNotIn("school", capabilities.RefreshRequest.__annotations__)
66
67
68class DispatchTests(unittest.TestCase):
69 def tearDown(self):
70 capabilities._handlers.clear()
71
72 def test_unknown_capability_is_refused(self):
73 # Kayit defteri modul genelidir ve baska testler `handlers.wire()`
74 # cagirir; bu test BOS bir defteri sart kosar.
75 capabilities._handlers.clear()
76 with self.assertRaises(CapabilityError) as caught:
77 capabilities.dispatch("insight.student", "demo", {})
78 self.assertEqual(caught.exception.code, "unknown_capability")
79
80 def test_registering_an_undeclared_name_is_refused(self):
81 with self.assertRaises(KeyError):
82 capabilities.register("chat.reply", lambda school, payload: {})
83
84 def test_handler_receives_the_school_from_the_frame(self):
85 seen = {}
86
87 def handler(school, payload):
88 seen["school"] = school
89 seen["payload"] = payload
90 return {"user_id": payload["user_id"]}
91
92 capabilities.register(capabilities.INSIGHT_STUDENT, handler)
93 result = capabilities.dispatch("insight.student", "demo", {"user_id": "u1"})
94 self.assertEqual(seen["school"], "demo")
95 self.assertEqual(result, {"user_id": "u1"})
96
97 def test_non_object_payload_is_refused(self):
98 capabilities.register(capabilities.INSIGHT_CLASS, lambda school, payload: {})
99 with self.assertRaises(CapabilityError) as caught:
100 capabilities.dispatch("insight.class", "demo", ["liste"])
101 self.assertEqual(caught.exception.code, "bad_request")
102
103 def test_summary_separates_the_three_facts(self):
104 handlers.wire()
105 text = capabilities.summary()
106 # 1) backend'in GONDEREBILDIGI adlar ...
107 self.assertIn(
108 "backend'in cagirabildigi yetenekler: "
109 "chat.reply, rag.index, insight.student, insight.refresh, "
110 "insight.report",
111 text,
112 )
113 # 2) ... depo yolunu (2. yon) kapsamadigi ...
114 self.assertIn("servis->backend depo yolu: kopru/insight.*", text)
115 # 3) ... ve ilan edilen her adin bir isleyicisi oldugu.
116 self.assertIn("servis tarafi isleyiciler: 4/4 kayitli", text)
117 self.assertIn("backend'in dagitim tablosunda olmayan: insight.class", text)
118 # Eski hali "TANIMSIZ" diyordu ve isleyici kayitliyken bile servisin
119 # bir sey yapmadigini ima ediyordu.
120 self.assertNotIn("TANIMSIZ", text)
121
122
123if __name__ == "__main__":
124 unittest.main()