Files
magpie/internal/cli/model_id_cli_test.go
yetone 7b09d2c951 provider: a model can be listed by an id of the user's at its provider, asked for by its own
zeewell on X (tweet 2116404121930432888): relays serve one model under
ids of their own (deepseek-v4.1-flash-1017, grok-4.6@500k). They want to
give each one their own id at the provider layer. magpie then lists,
routes, groups and finds groups by that id, and the upstream request
still carries the vendor's id.

Choice: a new per-model map, settings' ModelIDs
("<pid>/<local>": "<own id>"), served through the wire names that
already exist. ModelSameAs was not widened. It means "same as another
vendor's model": it lends specs and joins found groups. Making it rename
models everywhere would change every existing user's ids and refs.
ModelWires was not reinterpreted either, for the same reason. ModelIDs is
ModelWires turned round: a wire keeps magpie's id and changes the one
sent, and this keeps the one sent and changes magpie's. Settings.Wires()
merges each entry in as a wire name (wrapped by a "<pid>/*" wire). Every
place that sent a ModelWires name (gateway, usage ledger, request page,
UpstreamName, UpstreamNameAs) reads Wires(), so the upstream id needs no
new path. An explicit ModelWires entry for the same id wins.

- Listed by the local id: Available, liveIDs/liveByID, Serving and
  ListPrice translate through OwnModelID. /v1/models, agents' lists,
  Resolve, routing groups and found groups (auto/<local>, merged with
  every other provider serving that id) all see the local id.
- Only a provider of the user's own (Account == nil) takes one. An
  account's or a plugin's request is built from its list's id, which no
  wire reaches.
- Two variants of one provider given one id: the latest given it wins,
  and the earlier one is listed by its own id again. The CLI names it.
  The editor refuses two rows given one id in one save. A model of the
  provider's own id that a variant is listed by (plain grok-4.6 beside
  grok-4.6@500k) is not listed while the variant has it.
- The user's values are never overridden. SetModelID moves picks,
  contexts, fallbacks, groups' members/rules/fast/placed/off/weights/
  classifier/pick, the pickers' lists, every per-model setting
  (Settings.MoveModel) and gateway keys' models (provider.ModelMoved,
  set by access) to the new id, but only where nothing is under the new
  id yet. Agents' own files are not rewritten: an old provider/<own id>
  still resolves and is sent as it is. Group match patterns and key
  patterns stay as written.
- Key limits: a key held to either id passes for both (modelAllowed:
  the ref, OwnModelID, ListedModelID). Group members use the same check.
- Usage: model = the listed id, served = the vendor's id from its reply.
  The price is the own id's first.

CLI: magpie model id <provider/model> [<id>|--reset], magpie model ids.
GUI: Providers > a provider's editor > Names & levels > "Listed as",
beside Same as. It is staged with the editor's Save and taken back by
Restore default, in zh, zh-TW, ja and de. Accounts have no box.
Docs: providers-accounts.md, gateway-routing.md, and site start.html in
en, zh and ja.

Run (mote-run, at this tree rebased on 841326709):
- go test -tags nogui of internal/gateway, provider, settings, access,
  usage and cli: ok. internal/gui: ok but for
  TestSettingsSaveKeepsWhatItDoesNotSend's SearchAll, red on main since
  b09349d17 (#4514, yiqiui's patch); its ModelIDs case passes.
- TestAutoVisionDoesNotBuildListsAgain: 457 allocations with 4 models,
  458 with 400 (main 459), searcherModel within its 50. Reading
  Shared() per list cost 3041; SharedModelIDs parses only modelIDs once
  per file change, the settings path is built again only when what it is
  built from changes, and Serving looks up the own id only when a key is
  listed to some model.
- TestCoreScriptBudget: raised by 1,178 bytes for the Listed as box,
  with a note.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet ok.
- GUI: provider-listed-as (en, zh, zh-TW, ja, de), provider-same-as,
  provider-detect in Chromium on mote and WebKit on the Linux box (mote's
  WebKit launch hangs, #4125): 9 of 9.
Broken by hand, each red: the wire name (wires), the list (list), a key
held to the own id (keyown), the key move hook (hook), liveIDs, liveByID,
moving refs (moverefs) and moving per-model settings (movemodel).
Not tried: a red for ListPrice's or Serving's own-id lookup; a real relay
with variant ids; Match patterns are not rewritten to the new id. The
full Go suite and the whole GUI suite are still running and their reds
get their own issues.
2026-10-31 15:04:44 +08:00

67 lines
2.4 KiB
Go

package cli
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// magpie model id lists a provider's model by an id of the user's, shows
// it, lists every one under ids and takes it off with --reset; it refuses
// a flag or a bad id taken as one, and a model the provider doesn't have.
func TestModelIDCmd(t *testing.T) {
groupsHome(t)
out, err := runOut(t, "model", "ids")
if err != nil || !strings.Contains(out, "no model is listed by an id of yours yet") {
t.Fatalf("empty list: %q %v", out, err)
}
if out, err = runOut(t, "model", "id", "a/only-a", "solo"); err != nil || !strings.Contains(out, "a/solo") || !strings.Contains(out, "still asked for only-a") {
t.Fatalf("set: %q %v", out, err)
}
if got := settings.Load().ModelIDs; got["a/solo"] != "only-a" || len(got) != 1 {
t.Fatalf("settings: %v", got)
}
p, err := provider.Find("a")
if err != nil {
t.Fatal(err)
}
if got := provider.UpstreamName(*p, "solo"); got != "only-a" {
t.Fatalf("a/solo is asked for as %s", got)
}
for _, ref := range []string{"a/solo", "a/only-a"} {
if out, err = runOut(t, "model", "id", ref); err != nil || !strings.Contains(out, "a/solo") || !strings.Contains(out, "asked for only-a") {
t.Fatalf("show %s: %q %v", ref, out, err)
}
}
if out, err = runOut(t, "model", "ids"); err != nil || !strings.Contains(out, "a/solo") || !strings.Contains(out, "only-a") {
t.Fatalf("list: %q %v", out, err)
}
for _, bad := range [][]string{
{"model", "id", "a/solo", "--force"},
{"model", "id", "a/solo", "two words"},
{"model", "id", "a/nope", "x"},
{"model", "id", "solo", "x"},
} {
if _, err := runOut(t, bad...); err == nil {
t.Fatalf("took %v", bad)
}
}
if out, err = runOut(t, "model", "id", "--help"); err != nil || !strings.Contains(out, "magpie model id <provider/model> <id>") {
t.Fatalf("--help: %q %v", out, err)
}
if got := settings.Load().ModelIDs; len(got) != 1 {
t.Fatalf("a refused id was written: %v", got)
}
if out, err = runOut(t, "model", "id", "a/solo", "--reset"); err != nil || !strings.Contains(out, "its own id again") {
t.Fatalf("reset: %q %v", out, err)
}
if got := settings.Load().ModelIDs; got != nil {
t.Fatalf("after reset: %v", got)
}
if out, err = runOut(t, "model", "id", "a/only-a"); err != nil || !strings.Contains(out, "listed by its own id") {
t.Fatalf("show after reset: %q %v", out, err)
}
}