File size: 2,856 Bytes
3b3b2bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Actual localhost HTTP, including SDK requests and database restart."""
from pathlib import Path
import json,os,secrets,socket,subprocess,sys,tempfile,time,urllib.request,urllib.error
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT))
from phillnet_recall import RecallClient

def main():
    with tempfile.TemporaryDirectory() as tmp:
        key=secrets.token_urlsafe(40)
        with socket.socket() as s:s.bind(('127.0.0.1',0));port=s.getsockname()[1]
        url=f'http://127.0.0.1:{port}';env=dict(os.environ,PHILLNET_RECALL_API_KEY=key,PYTHONPATH=str(ROOT))
        def start():
            proc=subprocess.Popen([sys.executable,'-m','phillnet_recall','--db',str(Path(tmp)/'recall.db'),'serve','--port',str(port)],env=env,cwd=ROOT,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
            for _ in range(120):
                if proc.poll() is not None:raise RuntimeError('server exited')
                try:
                    with urllib.request.urlopen(url+'/health',timeout=1):return proc
                except (OSError,urllib.error.URLError):time.sleep(.05)
            proc.terminate();proc.wait(10);raise RuntimeError('startup timeout')
        proc=start();client=RecallClient(url,api_key=key)
        try:
            client.remember_bridge('amber docket','incident register',source='synthetic:glossary')
            client.remember('Nova incident register: Mira',source='synthetic:note')
            assert client.grounded('Nova amber docket')['status']=='retrieved'
            assert client.grounded_context('Nova amber docket')['dependency_complete']
            for p,v in [('region','west'),('owner','Mira')]:
                client.remember(f'Beacon {p} {v}',source='synthetic',entity='Beacon',predicate=p,value=v)
            plan={'where':[{'entity':'?s','predicate':'region','value':'west'},{'entity':'?s','predicate':'owner','value':'Mira'}],'select':['?s']}
            assert client.query(plan)['rows']==[{'?s':'Beacon'}]
            assert client.query_context(plan)['dependency_complete']
        finally:proc.terminate();proc.wait(10)
        proc=start()
        try:
            assert client.query(plan)['rows']==[{'?s':'Beacon'}]
            assert client.grounded('Nova amber docket')['status']=='retrieved'
        finally:proc.terminate();proc.wait(10)
    report={'transport':'actual localhost HTTP, not TestClient','client':'standard-library RecallClient',
            'glossary_write':True,'grounded_search':True,'bridge_dependencies_packed':True,
            'conjunctive_query':True,'query_dependencies_packed':True,'restart_persistence':True,
            'server_left_running':False,'publicly_exposed':False,'docker_built':False}
    (ROOT/'reports/http_v12.json').write_text(json.dumps(report,indent=2)+'\n')
    print(json.dumps(report,indent=2))
if __name__=='__main__':main()