Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

tests: the middleware tests start fresh, so a rest another test left on "a" no longer skips it (#3273)

yetonecf1498f50655
diff --git a/internal/gateway/middleware_test.go b/internal/gateway/middleware_test.go
index 8984d70d9..41c1431b7 100644
--- a/internal/gateway/middleware_test.go
+++ b/internal/gateway/middleware_test.go
@@ -9,6 +9,7 @@ import (
"path/filepath"
"slices"
"strings"
+ "sync"
"testing"
"github.com/yetone/magpie/internal/middleware"
@@ -38,8 +39,7 @@ func TestMiddlewareThroughGateway(t *testing.T) {
io.WriteString(w, sse(chunk("hello "), chunk(string(last)), `data: {"id":"c1","model":"m1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":2}}`, "data: [DONE]"))
}))
defer up.Close()
- t.Setenv("XDG_CONFIG_HOME", t.TempDir())
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
+ fresh(t) // nothing another test left on "fake" (#3273)
// the plugins' list written below reads as changed, and what that
// tells the plugins' hooks ends with the test
t.Cleanup(plugin.Settle)
@@ -101,6 +101,10 @@ export function onEvent(ev, ctx) {
// sent what the middleware made of it for that member, and the member
// tried next gets the body onRequest left, not the first try's.
func TestMiddlewareOnProviderPerTry(t *testing.T) {
+ // no rest, affinity or turn another test left on "a" sends the group
+ // past it (#3273: TestReplyNamesMember's 529 left "a" resting)
+ fresh(t)
+ var mu sync.Mutex
sent := map[string]string{}
member := func(id string, code int) {
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -109,7 +113,9 @@ func TestMiddlewareOnProviderPerTry(t *testing.T) {
}
raw, _ := io.ReadAll(r.Body)
json.Unmarshal(raw, &b)
+ mu.Lock()
sent[id] = b.System
+ mu.Unlock()
if code != 200 {
http.Error(w, `{"type":"error","error":{"type":"api_error","message":"down"}}`, code)
return
@@ -122,8 +128,6 @@ func TestMiddlewareOnProviderPerTry(t *testing.T) {
t.Fatal(err)
}
}
- t.Setenv("XDG_CONFIG_HOME", t.TempDir())
- t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Cleanup(plugin.Settle)
member("a", 500)
member("b", 200)
@@ -148,6 +152,8 @@ export function onProvider(body, ctx) {
if code != 200 {
t.Fatalf("%d %s", code, body)
}
+ mu.Lock()
+ defer mu.Unlock()
if sent["a"] != "asked for a/A/m1/key" || sent["b"] != "asked" {
t.Fatalf("sent %q", sent)
}