Files
magpie/internal/provider/decide_list_test.go
T
yetone 71d96e28e8 system one: a decision provider's own models-list URL is asked as given, and its models can each be tested (Discord, ARNO: OpenRouter added as a System One provider with the list https://openrouter.ai/api/v1/models?limit=500&output_modalities=decisions didn't get its models, and a model typed in by hand couldn't be tested from its right-click) — a System One-only provider went to fetchDecide before its ModelsURL was read, so magpie asked …/models, which at OpenRouter lists the 466 chat models, and kept only Jev's ids of those: typesafe/jev-router alone. With a ModelsURL, fetchDecide now asks it as written, query included, and keeps every id in it, since that list is of decision models already (OpenRouter's answers 13: pplx-decider, liquid/d1, cloudflare/clef, respan/span-01, typesafe/jev-1.13 …). Without one nothing changes, Bailian included. Testing a decision model was refused outright (the chip's Test this model off, Test models leaving them out); where the API takes System One's own body (System One, TypeSafe, OpenRouter, Vercel's TypeSafe API) each model is now sent AskSystemOne's yes-or-no question, the one Detect already asks, and the editor offers Test for it (providerJSON.decideTest); Vercel's evaluation models and Workers AI, which wrap it their own way, still say why not. TestDecideModelsURLAndModelTest (a fake OpenRouter: the plain list, the decisions list, a hand-added model through /systemone, an unknown one failing) and TestModelTest's Workers AI case fail on the old code; model-test-why.test.cjs gains a hand-added System One model tested from its chip and Test models, and a Workers AI one still off (WebKit en and zh pass, with model-test-one and model-copy-id; Chromium doesn't launch in this sandbox). OpenRouter's live decisions list returns the 13 models. Not tried with an OpenRouter key: the /systemone question itself. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-04 18:40:13 +08:00

76 lines
2.6 KiB
Go

package provider
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"slices"
"sync"
"testing"
)
// A System One provider at OpenRouter (ARNO on Discord): its /models lists
// chat models, Jev's router among them, and its decision models are at
// /models?output_modalities=decisions, the URL the user gave. Every model
// in that list is fetched, and a model typed in by hand is tested with a
// System One question of its own.
func TestDecideModelsURLAndModelTest(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
var mu sync.Mutex
var asked []string
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/models":
if r.URL.Query().Get("output_modalities") == "decisions" && r.URL.Query().Get("limit") == "500" {
w.Write([]byte(`{"data":[{"id":"perplexity/pplx-decider-v1-27b","architecture":{"output_modalities":["decisions"]}},{"id":"liquid/d1"},{"id":"~typesafe/jev-latest"},{"id":"typesafe/jev-1.13"}],"total_count":4}`))
return
}
w.Write([]byte(`{"data":[{"id":"openai/gpt-5"},{"id":"typesafe/jev-router"}]}`))
case "/api/v1/systemone":
var q struct{ Model string }
json.NewDecoder(r.Body).Decode(&q)
mu.Lock()
asked = append(asked, q.Model)
mu.Unlock()
if q.Model == "nobody/none" {
http.Error(w, `{"error":{"message":"No such model"}}`, 404)
return
}
w.Write([]byte(`{"answers":{"ok":{"answer":true}}}`))
default:
http.NotFound(w, r)
}
}))
defer up.Close()
p := Provider{ID: "openrouter-s1", Name: "OpenRouter", Key: "k", Decide: up.URL + "/api/v1",
ModelsURL: up.URL + "/api/v1/models?limit=500&output_modalities=decisions", Models: []string{"respan/span-01"}}
if err := Save(p); err != nil {
t.Fatal(err)
}
ms, err := p.Fetch(context.Background())
if err != nil {
t.Fatal(err)
}
var ids []string
for _, m := range ms {
ids = append(ids, m.ID)
}
if !slices.Equal(ids, []string{"perplexity/pplx-decider-v1-27b", "liquid/d1", "~typesafe/jev-latest", "typesafe/jev-1.13"}) {
t.Fatalf("decision models: %v", ids)
}
if why := p.ModelTest(); why != "" {
t.Fatalf("models not testable: %s", why)
}
r := p.TestModels(context.Background(), []string{"respan/span-01", "nobody/none"})
if !r[0].OK || r[0].Protocol != "decide" || r[0].Model != "respan/span-01" || r[1].OK || r[1].Error == "" {
t.Fatalf("model tests: %+v", r)
}
if !slices.Equal(asked, []string{"respan/span-01", "nobody/none"}) && !slices.Equal(asked, []string{"nobody/none", "respan/span-01"}) {
t.Fatalf("asked: %v", asked)
}
}