okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
bed4fdc
main
1"""Check a packaged binary outside its checkout, without development tools on PATH. 2 3Usage: python3 test/manual/nix_package_smoke.py /absolute/path/to/bin/albedo 4""" 5 6import json 7import pathlib 8import subprocess 9import sys 10import tempfile 11import urllib .request 12 13binary = sys .argv [1 ] 14with tempfile .TemporaryDirectory (prefix = "albedo-nix-smoke-" )as directory : 15base = pathlib .Path (directory ) 16home = base / "home" 17home .mkdir () 18 (home / "extensions.json" ).write_text (json .dumps ({"models" : {"refreshHours" :0 }})) 19env = { 20"HOME" :str (base ), 21"ALBEDO_HOME" :str (home ), 22"ALBEDO_NO_BROWSER" :"1" , 23"PATH" :"/usr/bin:/bin" , 24"TERM" :"dumb" , 25 } 26try : 27result = subprocess .run ( 28 [binary ,"sessions" ,"--json" ], 29cwd = base , 30env = env , 31capture_output = True , 32text = True , 33timeout = 45 , 34 ) 35if result .returncode : 36result .stdout ,result .stderr ) 37log = home / "daemon.log" 38if log .exists (): 39log .read_text ()[- 10000 :]) 40raise SystemExit (result .returncode ) 41assert json .loads (result .stdout )== [],result .stdout 42record = json .loads ((home / "daemon.json" ).read_text ()) 43req = urllib .request .Request ( 44f"http://127.0.0.1: { record [ 'port' ] } /server" , 45headers = {"Authorization" :"Bearer " + record ["token" ]}, 46 ) 47with urllib .request .urlopen (req ,timeout = 5 )as response : 48identity = json .load (response ) 49assert identity ["protocol" ]== record ["version" ],identity 50assert identity ["instance_id" ],identity 51assert identity ["build" ]== record ["build" ],identity 52if record .get ("instance_id" ): 53assert identity ["instance_id" ]== record ["instance_id" ],identity 54assert identity ["state" ]== "ready" ,identity 55json .dumps ({"binary" :binary ,"sessions" : [],"server" :identity })) 56finally : 57stop = subprocess .run ( 58 [binary ,"daemon" ,"--stop" ], 59cwd = base , 60env = env , 61capture_output = True , 62text = True , 63timeout = 10 , 64 ) 65assert stop .returncode == 0 ,"shutdown error: " + stop .stderr