package tui import ( "testing" "unicode/utf8" "albedo/cli/internal/daemon" ) func TestCommandMenuMatchesArgumentChoices(t *testing.T) { menu := CommandMenuModel{Catalog: []daemon.SessionCommand{ {Name: "/reload", Arguments: []daemon.CommandArgument{{Name: "target", Description: "reload target", Choices: []string{"session", "models", "both"}}}}, {Name: "/reload", Arguments: []daemon.CommandArgument{{Name: "target", Choices: []string{"models", "other"}}}}, {Name: "/research", Arguments: []daemon.CommandArgument{{Name: "prompt"}}}, }} tests := []struct { input string want []string }{ {input: "/reload ", want: []string{"/reload session", "/reload models", "/reload both", "/reload other"}}, {input: "/reload m", want: []string{"/reload models"}}, {input: "/reload both", want: []string{"/reload both"}}, {input: "/research some words"}, {input: "/unknown "}, {input: "/reload\n", want: nil}, } for _, test := range tests { t.Run(test.input, func(t *testing.T) { matches := menu.Matches(test.input, utf8.RuneCountInString(test.input)) if len(matches) != len(test.want) { t.Fatalf("got %v, want %v", commandNames(matches), test.want) } for index, match := range matches { if match.Name != test.want[index] { t.Fatalf("got %v, want %v", commandNames(matches), test.want) } } }) } } func commandNames(matches []ChatCommand) []string { result := make([]string, len(matches)) for index, match := range matches { result[index] = match.Name } return result } func TestCommandMenuMatchesNames(t *testing.T) { menu := CommandMenuModel{} matches := menu.Matches("/rel", 4) if len(matches) == 0 || matches[0].Name != "/reload" { t.Fatalf("got %v, want /reload name completion", commandNames(matches)) } }