test: replace brittle assertions with behavior checks

- mcp client_test: assert both initialize handshake calls happened and
  notifications/initialized has an empty ID, not their exact order
- telegram model_test: assert the resolved model has an openrouter/
  prefix instead of scanning button text for the string; replace the
  single-hardcoded-count pagination test with cases covering 0/1/8/9/100
  models so pageBounds and nav-row logic are actually exercised
- webui api_chat_test: assert the actionable file path is present in the
  streamed error instead of matching generic wording
This commit is contained in:
sam committed 2026-09-01 23:39:23 +10:00
1 parent e9edfb41c8
commit 29f47b5439
3 files changed
+95 -27

No files matched your search

+81 -19
View File
@@ -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)
+12 -6
View File
@@ -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)")
}
}
}
+2 -2
View File
@@ -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())
}
}