okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
1f92415
main
1"""Every public call in the model's Python namespace is named in the text the 2model is given. Agents otherwise discover the API with dir() and help(), or 3miss parts of it entirely (files.write, cells.last_id, and bash's timeout were 4all real but undocumented).""" 5 6import asyncio 7import importlib 8import inspect 9import re 10from pathlib import Path 11import sys 12import unittest 13 14ROOT = Path (__file__ ).resolve ().parents [2 ] 15sys .path .insert (0 ,str (ROOT / "priv" / "python" )) 16import albedo_cells as kernel # noqa: E402 17from albedo_api import PythonApi # noqa: E402 18 19# Plumbing the kernel or the remote relay calls; not part of the model's API. 20INTERNAL = {"run.Job.claim" } 21 22 23def model_text ()-> str : 24"""Every string literal the harness can show the model, joined.""" 25sources = [ 26* ROOT .glob ("src/albedo/harness/extensions/*/extension.gleam" ), 27ROOT / "src/albedo/harness/command.gleam" , 28 ] 29literals = [] 30for source in sources : 31literals += re .findall (r'"((?:[^"\\]|\\.)*)"' ,source .read_text ()) 32return "" .join (literals ).replace ('\\"' ,'"' ) 33 34 35def namespace ()-> dict [str ,object ]: 36loop = asyncio .new_event_loop () 37 38async def host (method ,args ): 39return []if method in {"commands.list" ,"mcp.list" }else {} 40 41api = PythonApi ( 42loop , 43host , 44RuntimeError , 45kernel .background_capture , 46100 , 47lambda e :None , 48lambda c :None , 49lambda _ :None , 50 ) 51bindings = { 52"cells" :kernel .Cells (), 53"output" :kernel .Output (), 54"show_image" :kernel .show_image , 55 } 56for name in [ 57"run" , 58"work" , 59"paperclips" , 60"files" , 61"skills" , 62"commands" , 63"mcp" , 64"remote" , 65"view" , 66"browser" , 67 ]: 68result = importlib .import_module ("albedo_plugins." + name ).setup (api ) 69bindings .update ( 70loop .run_until_complete (result )if inspect .isawaitable (result )else result 71 ) 72loop .close () 73return bindings 74 75 76class ApiDocsTest (unittest .TestCase ): 77def test_every_public_call_is_named_for_the_model (self ): 78text = model_text () 79missing = [] 80for name ,value in namespace ().items (): 81if isinstance (value , (dict ,type )): 82if name not in text : 83missing .append (name ) 84continue 85if inspect .isfunction (value ): 86if f" { name } (" not in text : 87missing .append (f" { name } (" ) 88continue 89for attribute in dir (type (value ))+ list (vars (value )): 90if ( 91attribute .startswith ("_" ) 92or f" { type ( value ). __module__ . split ( '.' )[ - 1 ] } . { type ( value ). __name__ } . { attribute } " 93in INTERNAL 94 ): 95continue 96if not re .search ( 97rf"\b { re . escape ( name ) } \. { re . escape ( attribute ) } \b" ,text 98 ): 99missing .append (f" { name } . { attribute } " ) 100self .assertEqual ( 101sorted (set (missing )), [],"public API the model is never told about" 102 ) 103 104def test_job_handles_are_documented (self ): 105from albedo_plugins import run 106 107text = model_text () 108public = [ 109name 110for name ,value in inspect .getmembers (run .Job ,callable ) 111if not name .startswith ("_" )and f"run.Job. { name } " not in INTERNAL 112 ] 113fields = ["id" ,"command" ,"exit_code" ,"duration" ,"timed_out" ] 114missing = [ 115name for name in public + fields if not re .search (rf"\bjob\. { name } \b" ,text ) 116 ] 117self .assertEqual ( 118missing , [],"job handle members the model is never told about" 119 ) 120 121 122if __name__ == "__main__" : 123unittest .main ()