Files
magpie/internal/gui/tune_gateway_mode_test.go
T
yetone f78d6b0d95 tune: gateway mode leaves Tuned for you out
/api/tune replays this computer's Claude Code and Codex files, and a
~/.claude folder alone makes a Claude Code card. In gateway mode the agents
are on other computers, so the card said Claude Code made 0 requests while
the harness card counted the gateway's. /api/tune now says gateway: true
with no agents, Use and Undo answer 409, and context.js draws no section.

Run (mote): go test ./internal/gui -run 'TestTune|TestGatewayMode' ok;
node --test context-tune-gateway, context-tune, context-tune-shapes 334/334
(Chromium and WebKit, en and zh, 900 and 420 wide); vet both OSes and gofmt
clean.
Broken by hand: with the ownSessionsOff checks taken out the Go test shows
the reported Claude card with 0 calls; the GUI test fails 20 of 30 (every
gateway-mode case) on the old context.js.
Not tried: a real Docker magpie; the full suite (mote rebooted mid-run).

Reported-by: linkaww on Discord
2026-11-08 02:37:09 +08:00

73 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/edit"
)
// linkaww on Discord, a magpie in Docker in gateway mode: Usage › Context's
// Tuned for you said Claude Code made 0 calls, while Through magpie below
// counted its requests. Tuned for you replays this computer's agents'
// session files and changes their settings; in gateway mode the agents are
// on other computers, so it has nothing to replay and nothing of theirs to
// change. /api/tune says so and gives no card, and Use and Undo are
// refused. Gateway mode off, as before.
func TestTuneInGatewayModeIsLeftOut(t *testing.T) {
h := sandboxHome(t)
tuneForget()
t.Cleanup(func() {
webPage.Store(false)
ownWas.Store(0)
tuneForget()
})
settingsPath := filepath.Join(h, ".claude", "settings.json")
if err := edit.SetJSON(settingsPath, edit.KV{Path: "promptCacheTtl", Value: "1h"}); err != nil {
t.Fatal(err)
}
mux := http.NewServeMux()
tuneRoutes(mux)
gatewayModeRoutes(mux)
call := func(method, path, body string) (int, string) {
t.Helper()
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest(method, path, strings.NewReader(body)))
return w.Code, w.Body.String()
}
tuned := func() tuneState {
t.Helper()
code, b := call("GET", "/api/tune?days=7", "")
var st tuneState
if err := json.Unmarshal([]byte(b), &st); code != 200 || err != nil {
t.Fatalf("GET /api/tune: %d %s %v", code, b, err)
}
return st
}
if st := tuned(); st.Gateway || len(st.Agents) != 1 || st.Agents[0].Agent != "claude" {
t.Fatalf("gateway mode off: %+v; want Claude Code's card", st)
}
webPage.Store(true)
if code, b := call("POST", "/api/settings/gateway-mode", `{"mode":"on"}`); code != 200 {
t.Fatalf("gateway mode on: %d %s", code, b)
}
if st := tuned(); !st.Gateway || len(st.Agents) != 0 || st.Days != 7 {
t.Fatalf("gateway mode: %+v; want no card, said to be gateway mode", st)
}
use := `{"agent":"claude","knob":"` + agent.TuneCache + `","value":"5m"}`
for _, path := range []string{"/api/tune/apply", "/api/tune/undo"} {
if code, b := call("POST", path, use); code != http.StatusConflict {
t.Fatalf("gateway mode: %s: %d %s; want it refused", path, code, b)
}
}
if v, _ := edit.GetJSON(settingsPath, "promptCacheTtl"); v != `"1h"` && v != "1h" {
t.Fatalf("gateway mode: promptCacheTtl %q; want it left at 1h", v)
}
}