agent: a provider named magpie at another machine's address is not this magpie's Alma wiring

Alex on Discord: any provider named magpie in Alma, one pointing at a
magpie on a VPS included, was taken as this magpie's own, and the Agents
page said "Alma no longer goes through magpie, its config was changed".
almaMagpie now takes a provider by the name magpie only when its base URL
is on this machine (onAnotherMachine, as ZCode's check does). One at
another machine's address is the user's own provider and left alone; the
second match, an OpenAI-shaped provider at this gateway, is unchanged.

Run (mote), at base f1a4de736; rebased onto 4f94b8a82, which changes two internal/agent files, and the Alma tests run again there: ok.
- go test -count=1 ./internal/agent/: ok (225.9s)
- GOOS=linux and GOOS=windows go vet ./internal/agent/: ok; gofmt -l clean.
Broken by hand: without the onAnotherMachine check,
TestAlmaMagpieOnAServer FAILs ("a magpie on a server taken for this one").
Not tried: a real Alma with a remote magpie provider; the test uses the
reporter's shape (id vps, name magpie, https URL, set as default).
This commit is contained in:
yetone
2026-11-17 20:39:31 +08:00
parent 4f94b8a829
commit d67ccbd3c7
2 changed files with 38 additions and 2 deletions
+4 -2
View File
@@ -286,10 +286,12 @@ var almaSeen struct {
}
// almaMagpie is magpie's provider among Alma's: the one named magpie, or
// an OpenAI-shaped one at the gateway. Nil if there is none.
// an OpenAI-shaped one at the gateway. Nil if there is none. One named
// magpie at another machine's address is the user's own, a magpie on a
// server say (Alex on Discord), and never this magpie's.
func almaMagpie(ps []almaProvider) *almaProvider {
for i := range ps {
if ps[i].Name == magpieID && (ps[i].Type == "openai" || ps[i].Type == "custom") {
if ps[i].Name == magpieID && (ps[i].Type == "openai" || ps[i].Type == "custom") && !onAnotherMachine(ps[i].BaseURL) {
return &ps[i]
}
}
+34
View File
@@ -880,3 +880,37 @@ func TestAlmaOneMagpie(t *testing.T) {
}
})
}
// A provider the user named magpie in Alma, at a magpie on a server, is
// theirs (Alex on Discord): this magpie neither takes it for its own nor
// tells drift when Alma's model is on it.
func TestAlmaMagpieOnAServer(t *testing.T) {
syncHome(t)
f := startAlma(t)
a := alma()
if err := os.MkdirAll(a.Dir, 0o755); err != nil {
t.Fatal(err)
}
vps := map[string]any{"id": "vps", "name": magpieID, "type": "openai", "apiKey": "sk-vps",
"baseURL": "https://magpie.example.com/v1", "enabled": true, "models": []any{"m"}}
f.mu.Lock()
f.providers = append(f.providers, vps)
f.settings["chat"].(map[string]any)["defaultModel"] = "vps:m"
f.mu.Unlock()
if p := almaMagpie([]almaProvider{{ID: "vps", Name: magpieID, Type: "openai", BaseURL: "https://magpie.example.com/v1"}}); p != nil {
t.Fatalf("a magpie on a server taken for this one: %+v", p)
}
if c := a.Check(); c != "" {
t.Fatalf("Alma on the user's server magpie told as drift: %q", c)
}
if a.Wired() {
t.Fatal("Alma on the user's server magpie reads as on this magpie")
}
// this magpie's own, named magpie at the gateway, is still found
if p := almaMagpie([]almaProvider{{ID: "x", Name: magpieID, Type: "openai", BaseURL: gatewayV1()}}); p == nil {
t.Fatal("magpie's own provider not found")
}
if p := almaMagpie([]almaProvider{{ID: "x", Name: magpieID, Type: "openai", BaseURL: "http://127.0.0.1:1/v1"}}); p == nil {
t.Fatal("magpie's own provider at an old local port not found, to be pointed back")
}
}