okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(tests): share fixtures and move workspace checks to E2Eeaef427

main
1.9 KiB59 linesraw
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.{
5  Argument, 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 {
14  Command(
15    "/demo",
16    "Demo",
17    [Argument("arguments", "freeform", False, [])],
18    True,
19    True,
20    False,
21    None,
22    fn(_context, caller, args) {
23      let arguments = dict.get(args, "arguments") |> result.unwrap("")
24      case caller {
25        UserCall -> Ok(Turn("/demo " <> arguments, "turn " <> arguments))
26        ModelCall -> Ok(Data(json.string("data " <> arguments)))
27      }
28    },
29  )
30}
31
32pub fn method_names_are_mintable_and_collision_free_test() -> Nil {
33  command.method_name("/model") |> should.equal("model")
34  command.method_name("/fix-lint") |> should.equal("fix_lint")
35  command.method_name("/skill:model") |> should.equal("skill_model")
36  // A whole catalog disambiguates reserved names and collisions.
37  let methods =
38    command.method_names([
39      demo(),
40      Command("/skill:model", "", [], True, False, False, None, fn(_, _, _) {
41        Ok(Data(json.string("")))
42      }),
43      Command("/skill-model", "", [], True, False, False, None, fn(_, _, _) {
44        Ok(Data(json.string("")))
45      }),
46      Command("/catalog", "", [], True, False, False, None, fn(_, _, _) {
47        Ok(Data(json.string("")))
48      }),
49      Command("/__init__", "", [], True, False, False, None, fn(_, _, _) {
50        Ok(Data(json.string("")))
51      }),
52    ])
53  dict.get(methods, "/skill:model")
54  |> should.equal(Ok("skill_model"))
55  dict.get(methods, "/skill-model")
56  |> should.equal(Ok("skill_model2"))
57  dict.get(methods, "/catalog") |> should.equal(Ok("catalog_"))
58  dict.get(methods, "/__init__") |> should.equal(Ok("__init___"))
59}