chintakapp commited on
Commit
1f5ebc7
·
1 Parent(s): b50c965

api modified

Browse files
brain/tests/test_login_routes.py CHANGED
@@ -164,3 +164,9 @@ def test_health_says_whether_login_is_configured():
164
 
165
  def test_login_is_unavailable_when_no_service_is_wired():
166
  assert build(sessions=False).post("/auth/google", json=google_body()).status_code == 503
 
 
 
 
 
 
 
164
 
165
  def test_login_is_unavailable_when_no_service_is_wired():
166
  assert build(sessions=False).post("/auth/google", json=google_body()).status_code == 503
167
+
168
+
169
+ def test_the_api_schema_and_docs_are_not_published():
170
+ client = build()
171
+ for path in ("/openapi.json", "/docs", "/redoc"):
172
+ assert client.get(path).status_code == 404
brain/tests/test_store_supabase.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SupabaseStore against a stand-in PostgREST: what it sends, and what it does with the answers."""
2
+
3
+ import json
4
+ from datetime import date
5
+
6
+ import httpx
7
+
8
+ from brain.persona.types import Mode, Scope
9
+ from brain.store.supabase import SupabaseStore
10
+
11
+
12
+ def store_with(handler):
13
+ client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
14
+ return SupabaseStore("https://x.supabase.co", "service-key", client=client)
15
+
16
+
17
+ async def test_a_function_that_returns_nothing_is_not_an_error():
18
+ # bump_usage and touch_memories return void, so PostgREST answers 204 with no body. Reading
19
+ # that as JSON raised on every chat turn: usage was never counted, and touching memories
20
+ # would have failed the reply itself.
21
+ seen: list[str] = []
22
+
23
+ def handler(request: httpx.Request) -> httpx.Response:
24
+ seen.append(request.url.path)
25
+ return httpx.Response(204)
26
+
27
+ store = store_with(handler)
28
+ await store.bump_usage("u1", date(2026, 9, 27), "chat", "gemini-3.5-flash-lite", 1)
29
+ await store.touch_memories("u1", ["m1", "m2"])
30
+ assert seen == ["/rest/v1/rpc/bump_usage", "/rest/v1/rpc/touch_memories"]
31
+
32
+
33
+ async def test_touching_memories_sends_the_user_and_the_ids():
34
+ bodies: list[dict] = []
35
+
36
+ def handler(request: httpx.Request) -> httpx.Response:
37
+ bodies.append(json.loads(request.content))
38
+ return httpx.Response(204)
39
+
40
+ await store_with(handler).touch_memories("u1", ["m1"])
41
+ assert bodies == [{"p_user": "u1", "ids": ["m1"]}]
42
+
43
+
44
+ async def test_touching_no_memories_makes_no_request():
45
+ calls: list[str] = []
46
+
47
+ def handler(request: httpx.Request) -> httpx.Response:
48
+ calls.append(request.url.path)
49
+ return httpx.Response(204)
50
+
51
+ await store_with(handler).touch_memories("u1", [])
52
+ assert calls == []
53
+
54
+
55
+ async def test_a_function_that_returns_rows_is_still_read_as_json():
56
+ rows = [{"id": "m1", "content": "Karnak likes tea.", "scope": "shared", "score": 0.83}]
57
+ store = store_with(lambda request: httpx.Response(200, json=rows))
58
+ hits = await store.match_memories("u1", [0.1, 0.2], Mode.NORMAL, 5, 0.55)
59
+ assert [(h.id, h.scope, h.score) for h in hits] == [("m1", Scope.SHARED, 0.83)]