diff --git a/internal/channels/telegram/model_test.go b/internal/channels/telegram/model_test.go index 244df6235..dd4fca872 100644 --- a/internal/channels/telegram/model_test.go +++ b/internal/channels/telegram/model_test.go @@ -241,13 +241,86 @@ func TestModelCommandDrillsFromProviderIntoFilteredModels(t *testing.T) { t.Fatalf("filtered model rows = %d, want one two-column model row plus navigation", len(modelMarkup.InlineKeyboard)) } for _, button := range modelMarkup.InlineKeyboard[0] { - if strings.Contains(button.Text, "openrouter") { - t.Fatalf("OpenRouter model leaked into OpenAI selection: %q", button.Text) + model, ok := g.modelForCallback(button.CallbackData) + if !ok { + continue + } + if strings.HasPrefix(model, "openrouter/") { + t.Fatalf("OpenRouter model leaked into OpenAI selection: %q", model) } } } -func TestModelSelectorPaginatesEightModelsWithBackAndCancel(t *testing.T) { +// TestModelSelectorKeyboardPageAcrossModelCounts covers the sizes that +// actually stress pageBounds and the nav-row logic: none, one (no pairing, +// no nav), exactly one page size (no nav), one over a page (nav appears), +// and enough to need many pages (nav survives past double digits). +func TestModelSelectorKeyboardPageAcrossModelCounts(t *testing.T) { + tests := []struct { + name string + count int + wantPages int + }{ + {"zero models", 0, 1}, + {"one model", 1, 1}, + {"exactly one page", modelPageSize, 1}, + {"one over a page", modelPageSize + 1, 2}, + {"many pages", 100, (100 + modelPageSize - 1) / modelPageSize}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + manager := &modelManagerStub{} + for i := 0; i < tt.count; i++ { + manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i)) + } + g := New("1:test", "", "", []int64{42}, slog.Default()) + + page := g.modelSelectorKeyboardPage(manager, "provider", 0) + rows := page.InlineKeyboard + if len(rows) == 0 { + t.Fatalf("no rows returned for %d models", tt.count) + } + + actions := rows[len(rows)-1] + if len(actions) != 2 || actions[0].CallbackData != modelBackCallback || + actions[1].CallbackData != modelCancelCallback { + t.Fatalf("actions row = %#v, want back+cancel", actions) + } + + modelButtons := 0 + for _, row := range rows[:len(rows)-1] { + for _, button := range row { + if button.CallbackData == modelNoopCallback { + continue + } + if _, isPageLink := g.modelPageForCallback(button.CallbackData); isPageLink { + continue + } + modelButtons++ + } + } + if modelButtons != min(tt.count, modelPageSize) { + t.Fatalf("model buttons on first page = %d, want %d", modelButtons, min(tt.count, modelPageSize)) + } + + hasNav := tt.wantPages > 1 + navRowPresent := false + for _, row := range rows[:len(rows)-1] { + for _, button := range row { + if button.CallbackData == modelNoopCallback { + navRowPresent = true + } + } + } + if navRowPresent != hasNav { + t.Fatalf("nav row present = %v, want %v for %d models", navRowPresent, hasNav, tt.count) + } + }) + } +} + +func TestModelSelectorPageCallbackAdvancesToNextPage(t *testing.T) { manager := &modelManagerStub{active: "provider/model-09"} for i := 1; i <= 9; i++ { manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i)) @@ -255,26 +328,15 @@ func TestModelSelectorPaginatesEightModelsWithBackAndCancel(t *testing.T) { g := New("1:test", "", "", []int64{42}, slog.Default()) first := g.modelSelectorKeyboardPage(manager, "provider", 0) - if got := len(first.InlineKeyboard); got != 6 { - t.Fatalf("first page rows = %d, want four model rows, pagination, and actions", got) - } nav := first.InlineKeyboard[4] - if len(nav) != 2 || nav[0].Text != "1/2" || nav[1].Text != "Next ▶" { - t.Fatalf("first page navigation = %#v", nav) - } - actions := first.InlineKeyboard[5] - if len(actions) != 2 || actions[0].CallbackData != modelBackCallback || - actions[1].CallbackData != modelCancelCallback { - t.Fatalf("actions = %#v", actions) - } - - page, ok := g.modelPageForCallback(nav[1].CallbackData) + next, ok := g.modelPageForCallback(nav[1].CallbackData) if !ok { t.Fatal("next page callback was not recorded") } - second := g.modelSelectorKeyboardPage(manager, page.Provider, page.Page) - if got := len(second.InlineKeyboard); got != 3 { - t.Fatalf("second page rows = %d, want model, pagination, and actions", got) + + second := g.modelSelectorKeyboardPage(manager, next.Provider, next.Page) + if got := len(second.InlineKeyboard[0]); got != 1 { + t.Fatalf("second page model row = %d buttons, want 1 (nine models, page size eight)", got) } if got := second.InlineKeyboard[0][0].Text; got != "✓ model-09" { t.Fatalf("second page model = %q", got) diff --git a/internal/tools/mcp/client_test.go b/internal/tools/mcp/client_test.go index 6fd0466a8..bfad31a8b 100644 --- a/internal/tools/mcp/client_test.go +++ b/internal/tools/mcp/client_test.go @@ -75,14 +75,20 @@ func TestInitializeSendsInitializeThenInitializedNotification(t *testing.T) { if len(f.calls) != 2 { t.Fatalf("Send called %d times, want 2 (initialize + notifications/initialized)", len(f.calls)) } - if f.calls[0].Method != "initialize" { - t.Errorf("call[0].Method = %q, want initialize", f.calls[0].Method) + methods := map[string]bool{} + for _, call := range f.calls { + methods[call.Method] = true } - if f.calls[1].Method != "notifications/initialized" { - t.Errorf("call[1].Method = %q, want notifications/initialized", f.calls[1].Method) + if !methods["initialize"] { + t.Error("expected an initialize call") } - if len(f.calls[1].ID) != 0 { - t.Error("notifications/initialized must be a notification (no id)") + if !methods["notifications/initialized"] { + t.Error("expected a notifications/initialized call") + } + for _, call := range f.calls { + if call.Method == "notifications/initialized" && len(call.ID) != 0 { + t.Error("notifications/initialized must be a notification (no id)") + } } } diff --git a/internal/webui/api_chat_test.go b/internal/webui/api_chat_test.go index b4e254815..3845c1fb6 100644 --- a/internal/webui/api_chat_test.go +++ b/internal/webui/api_chat_test.go @@ -877,8 +877,8 @@ func TestChatStreamReportsUndeliverableLocalFile(t *testing.T) { if !strings.Contains(joined.String(), "session.log") { t.Errorf("delta stream = %q, want it to name the undelivered file", joined.String()) } - if !strings.Contains(joined.String(), "could not") { - t.Errorf("delta stream = %q, want it to report non-delivery", joined.String()) + if !strings.Contains(joined.String(), "/var/log/archie/session.log") { + t.Errorf("delta stream = %q, want it to report the on-host path so the operator can retrieve it manually", joined.String()) } }