Files
magpie/internal/cli/model_ids_space_cli_test.go
T
yetone c4e6abf3cc gui, cli: a model id typed with a space in it stays one model, "Opus 5.5" not Opus and 5.5 (#1976)
elonnzhang on #1976: on a Baidu OneAPI relay, typing `Opus 5.5` in the
provider editor's add box (or the add form's Models field) and pressing
Enter added two models, `Opus` and `5.5`. Both read the box with
split(/[,\s]+/), while their hints say "comma separated".

- app.js: one typedIds() for both, split at commas (and line breaks)
  with each id trimmed. chosenIds() (the add box, and an id left in it
  at Save) and the add form's Models field use it.
- CLI siblings, which split the same way: `magpie provider set
  models=` now splits at commas only. A group's models=, models-=,
  fast= and weight= split at commas, and an item with a space that
  names no model the group can have is still split at its spaces, so
  `models=m,b/x a/m` (TestApplyGroupPairs) still works. levels= and
  `magpie visible` (effort levels and family names) are unchanged.
- Tests: the reporter's two GUI assertions in models-add-and-icons
  (from their fork branch). A new model-id-space.test.cjs covers both
  boxes in en, zh, zh-TW, ja and de, Chromium and WebKit, at 1100 and
  420 wide. TestModelIDsKeepTheirSpace covers the CLI. The fork's change
  to provider-add-models.test.cjs is not taken: filling the Models field
  there replaces the picks it holds, so it failed on its own terms.

Run: on the old split, model-id-space fails (4/4 for en and de at 420
in Chromium) and TestModelIDsKeepTheirSpace fails (models = ["Opus"
"5.5" ...]). With the whole-item check forced off, it fails on members.
With the fix: model-id-space 40/40, models-add-and-icons 4/4 and
provider-add-models 4/4 pass. `go test -tags nogui ./internal/cli` is
ok. gofmt is clean, and go vet passes for darwin, linux (-tags nogui)
and windows.
Not tried: a real relay with a spaced model id served end to end.
2026-10-13 18:16:03 +08:00

40 lines
1.4 KiB
Go

package cli
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A model id can hold a space ("Opus 5.5" on a relay, #1976): models=,
// a group's members and weight= (and fast=) split their lists at commas only,
// so the id stays one model, while a comma list still adds several.
func TestModelIDsKeepTheirSpace(t *testing.T) {
var p provider.Provider
if err := applyPairs(&p, []string{"models=Opus 5.5, gpt-5,Claude Opus 5.5"}); err != nil {
t.Fatal(err)
}
if want := []string{"Opus 5.5", "gpt-5", "Claude Opus 5.5"}; !slices.Equal(p.Models, want) {
t.Fatalf("models = %q, want %q", p.Models, want)
}
groupsHome(t)
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Models: []string{"Opus 5.5"}, Chat: "http://127.0.0.1:1/v1"}); err != nil {
t.Fatal(err)
}
g, err := addGroup("Spaced", []string{"models=relay/Opus 5.5, b/vendor/m", "routing=weighted-round-robin", "weight=relay/Opus 5.5=3"})
if err != nil {
t.Fatal(err)
}
if want := []string{"relay/Opus 5.5", "b/vendor/m"}; !slices.Equal(g.Members, want) {
t.Fatalf("members = %q, want %q", g.Members, want)
}
if g.MemberWeight("relay/Opus 5.5") != 3 {
t.Fatalf("weights %v", g.Weights)
}
if g, err = setGroup("spaced", []string{"models-=relay/Opus 5.5"}); err != nil || !slices.Equal(g.Members, []string{"b/vendor/m"}) {
t.Fatalf("models-= left %q: %v", g.Members, err)
}
}