okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
eaef427
main
1//// Every catalog must disambiguate method collisions and reserved Python names. 2//// This invariant covers arbitrary catalogs beyond the installed E2E commands. 3 4import albedo/harness/command .{ 5Argument , Command , Data , ModelCall , Turn , UserCall , 6} 7import gleam/dict 8import gleam/json 9import gleam/option .{ None } 10import gleam/result 11import gleeunit/should 12 13fn demo () -> command . Command { 14Command ( 15"/demo" , 16"Demo" , 17[ Argument ( "arguments" , "freeform" , False , [])], 18True , 19True , 20False , 21None , 22fn ( _context , caller , args ) { 23let arguments = dict . get ( args , "arguments" ) |> result . unwrap ( "" ) 24case caller { 25UserCall -> Ok ( Turn ( "/demo " <> arguments , "turn " <> arguments )) 26ModelCall -> Ok ( Data ( json . string ( "data " <> arguments ))) 27} 28}, 29) 30} 31 32pub fn method_names_are_mintable_and_collision_free_test () -> Nil { 33command . method_name ( "/model" ) |> should . equal ( "model" ) 34command . method_name ( "/fix-lint" ) |> should . equal ( "fix_lint" ) 35command . method_name ( "/skill:model" ) |> should . equal ( "skill_model" ) 36// A whole catalog disambiguates reserved names and collisions. 37let methods = 38command . method_names ([ 39demo (), 40Command ( "/skill:model" , "" , [], True , False , False , None , fn ( _ , _ , _ ) { 41Ok ( Data ( json . string ( "" ))) 42}), 43Command ( "/skill-model" , "" , [], True , False , False , None , fn ( _ , _ , _ ) { 44Ok ( Data ( json . string ( "" ))) 45}), 46Command ( "/catalog" , "" , [], True , False , False , None , fn ( _ , _ , _ ) { 47Ok ( Data ( json . string ( "" ))) 48}), 49Command ( "/__init__" , "" , [], True , False , False , None , fn ( _ , _ , _ ) { 50Ok ( Data ( json . string ( "" ))) 51}), 52]) 53dict . get ( methods , "/skill:model" ) 54|> should . equal ( Ok ( "skill_model" )) 55dict . get ( methods , "/skill-model" ) 56|> should . equal ( Ok ( "skill_model2" )) 57dict . get ( methods , "/catalog" ) |> should . equal ( Ok ( "catalog_" )) 58dict . get ( methods , "/__init__" ) |> should . equal ( Ok ( "__init___" )) 59}