Files
magpie/internal/tui/group_provider_off_test.go
T
yetone 2a1ef15ba9 routing: a found group's card leaves out a provider switched off, and counts it (XYenon)
XYenon on Discord (#feedback, 10-30): "已经关闭的提供商还会显示在路由页的
自动成组里是不是不太对". A provider switched off stays a member of the
groups magpie found (#2671, on purpose: agents on auto-<model> aren't
moved while it is off), and the gateway already skips it (membersIn reads
only providers that are on; TestFoundGroupWithAProviderOff covers chat,
and a fallback group, affinity and a group's classifier (decide_group.go)
go through the same FindGroup). So no request reached it. What was wrong was the page: the
card still listed it as "B · model (switched off)" and its logo sat in
the group's icon stack, where every other model list leaves a provider
switched off out.

- Routing page (plugins/routing/client.js): a found group's card, its
  remove-picker row and its logos (groupIcons, also used by the group
  pickers) leave out members whose provider is switched off; a tag
  "{n} switched off" says how many, its title why (offWords). When none
  would be left they are listed as before. The editor and a manual
  group's pick still show them, greyed with why. A group of the user's
  is unchanged: it lists what they put in.
- i18n: "{n} switched off" in zh, zh-TW, ja, de.
- TUI (sibling): the routing list's line for a found group does the same
  ("N models · ... · 1 switched off"), and a group's page marks such a
  member "· switched off: skipped until it is on again" (any group).
- docs/subsystems/providers-accounts.md: the row says it.

Tests: routing-provider-off.test.cjs gains a found group (card text,
tag text and title, no logo of the provider off, editor still has it)
and one whose only member is off (listed as before, no tag); every
language, 1100 and 420 wide, Chromium and WebKit.
TestFoundGroupLineLeavesASwitchedOffProviderOut (internal/tui).

Run on mote (mote-run, this tree): node --test of 45 GUI files
(group-*, panel-routing*, routing-group*, routing-groups*,
routing-provider-off, i18n-keys, found-*, remove-found*): 488/488 pass.
go test ./internal/tui ok; go test ./internal/gui: all ok except
TestMainWindowCorners/macOS_26_SDK, red on macOS 27 and already filed
(#3949), an AppKit window test this change doesn't reach. gofmt -l
clean; go vet ./internal/tui for darwin, linux (-tags nogui), windows ok.

Broken by hand: with client.js from HEAD the new GUI case is red
(expected 'A Cloud · luna', actual 'A Cloud · luna → B Cloud · luna
(switched off)'); with listedMembers returning every member the TUI test
is red ("2 models · ... pa/luna → pb/luna").

Not tried: the real app with a real provider switched off; the full GUI
suite (1002 files) and the full go test ./... were not run.
2026-10-30 02:28:29 +08:00

62 lines
2.1 KiB
Go

package tui
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A group magpie found keeps a member whose provider is switched off
// (#2671), but its line on the routing page lists only those the gateway
// can send to, and says how many are off (XYenon on Discord: a provider
// switched off was still listed in the found group). A group of the user's
// lists what they put in; the group's own page marks the member off.
func TestFoundGroupLineLeavesASwitchedOffProviderOut(t *testing.T) {
home(t)
for _, p := range []provider.Provider{
{ID: "pa", Name: "PA", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},
{ID: "pb", Name: "PB", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
if err := provider.SaveGroup(provider.Group{ID: "mine", Name: "Mine", Members: []string{"pa/luna", "pb/luna"}}); err != nil {
t.Fatal(err)
}
if err := provider.SetOff("pb", true); err != nil {
t.Fatal(err)
}
m := press(t, model{w: 160, h: 40}, "3")
line := func(name string) string {
t.Helper()
for _, l := range strings.Split(m.View(), "\n") {
if strings.Contains(l, name) {
return l
}
}
t.Fatalf("no %s line:\n%s", name, m.View())
return ""
}
if l := line("auto/luna"); strings.Contains(l, "pb/luna") || !strings.Contains(l, "pa/luna") || !strings.Contains(l, "1 model ") || !strings.Contains(l, "1 switched off") {
t.Fatalf("found group's line: %q", l)
}
if l := line("group/mine"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {
t.Fatalf("the user's group's line: %q", l)
}
m.gid, m.mode = "auto-luna", modeGroup
v := m.View()
if !strings.Contains(v, "pb/luna · switched off") || strings.Contains(v, "pa/luna · switched off") {
t.Fatalf("the found group's page:\n%s", v)
}
// on again: listed as before
if err := provider.SetOff("pb", false); err != nil {
t.Fatal(err)
}
m = press(t, model{w: 160, h: 40}, "3")
if l := line("auto/luna"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {
t.Fatalf("pb on again: %q", l)
}
}