File size: 2,371 Bytes
8abad49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from fastapi.testclient import TestClient

from app import app


def test_health_and_index() -> None:
    c = TestClient(app)
    h = c.get("/health")
    assert h.status_code == 200
    body = h.json()
    assert body["lambda"] == "CONJECTURE_1"
    assert body["kind"] == "SOFTWARE"
    assert body["publication_eligible"] is False
    idx = c.get("/api/v1/index")
    assert idx.status_code == 200
    assert idx.json()["chunk_count"] == 575


def test_canvas_is_zero_cdn() -> None:
    c = TestClient(app)
    page = c.get("/")
    assert page.status_code == 200
    html = page.text
    assert "cdn." not in html.lower()
    assert "three.js" not in html.lower()
    assert "googleapis" not in html.lower()
    assert "canvas id=\"holo\"" in html
    assert "holographic" in html.lower()
    assert 'id="handles"' in html
    assert 'id="plan"' in html
    assert "/retrieve?q=" in html
    assert "/plan?q=" in html
    assert "UNAVAILABLE" in html


def test_plan_navigate_and_abstain() -> None:
    c = TestClient(app)
    nav = c.post("/api/v1/plan", json={"query": "Lambda uniqueness conjecture TH_L1"})
    assert nav.status_code == 200
    body = nav.json()
    assert body["plan"]["decision"] in ("NAVIGATE", "ABSTAIN")
    assert "graph" in body
    assert body["retrieve"]["kind"] == "SOFTWARE"
    absn = c.post(
        "/api/v1/plan",
        json={"query": "Who won the 2099 world cup according to the corpus?"},
    )
    assert absn.status_code == 200
    assert absn.json()["plan"]["decision"] == "ABSTAIN"
    assert absn.json()["plan"]["citedNodeIds"] == []


def test_get_retrieve_and_plan() -> None:
    c = TestClient(app)
    hit = c.get("/retrieve", params={"q": "Alloy data surfaces honesty doctrine", "k": 4})
    assert hit.status_code == 200
    body = hit.json()
    assert body["schema"] == "szl.second-brain.retrieve/v1"
    assert body["kind"] == "SOFTWARE"
    assert "\"text\":" not in hit.text.lower()
    nav = c.get("/plan", params={"q": "Alloy data surfaces honesty doctrine", "k": 4})
    assert nav.status_code == 200
    plan = nav.json()
    assert plan["schema"] == "szl.second-brain.plan/v1"
    assert plan["kind"] == "SOFTWARE"
    assert plan["decision"] in ("NAVIGATE", "ABSTAIN")
    empty = c.get("/api/v1/plan", params={"q": ""})
    assert empty.status_code == 200
    assert empty.json()["decision"] == "ABSTAIN"