| 1 | package serve |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/command" |
| 10 | "reasonix/internal/config" |
| 11 | "reasonix/internal/control" |
| 12 | "reasonix/internal/skill" |
| 13 | ) |
| 14 | |
| 15 | func TestServeCommandsUsesActiveControllerCatalog(t *testing.T) { |
| 16 | bc := NewBroadcaster() |
| 17 | ctrl := control.New(control.Options{ |
| 18 | Sink: bc, |
| 19 | Commands: []command.Command{{Name: "remote-review", Description: "Review remotely", ArgHint: "<scope>"}}, |
| 20 | Skills: []skill.Skill{{Name: "remote-skill", Description: "Remote skill", RunAs: skill.RunSubagent}}, |
| 21 | }) |
| 22 | srv := httptest.NewServer(New(ctrl, bc, config.ServeConfig{}).Handler()) |
| 23 | defer srv.Close() |
| 24 | resp, err := http.Get(srv.URL + "/commands") |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | defer resp.Body.Close() |
| 29 | var entries []commandCatalogEntry |
| 30 | if err := json.NewDecoder(resp.Body).Decode(&entries); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | byName := make(map[string]commandCatalogEntry, len(entries)) |
| 34 | for _, entry := range entries { |
| 35 | byName[entry.Name] = entry |
| 36 | } |
| 37 | if got := byName["remote-review"]; got.Kind != "custom" || got.Hint != "<scope>" { |
| 38 | t.Fatalf("remote command = %+v", got) |
| 39 | } |
| 40 | if got := byName["remote-skill"]; got.Kind != "subagent" || got.Group != "subagents" { |
| 41 | t.Fatalf("remote skill = %+v", got) |
| 42 | } |
| 43 | if byName["new"].Kind != "builtin" || byName["clear"].Kind != "builtin" { |
| 44 | t.Fatalf("remote builtins missing: %+v", byName) |
| 45 | } |
| 46 | if byName["reload-cmd"].Kind != "builtin" { |
| 47 | t.Fatalf("remote reload-cmd missing: %+v", byName["reload-cmd"]) |
| 48 | } |
| 49 | if _, ok := byName["theme"]; ok { |
| 50 | t.Fatal("remote catalog advertised the local-only /theme command") |
| 51 | } |
| 52 | if _, ok := byName["reload"]; ok { |
| 53 | t.Fatal("remote catalog advertised the local-only /reload command") |
| 54 | } |
| 55 | } |
| 56 |