Files
magpie/internal/agent/context_cap_agents_test.go
T
yetone 52b516da6d agents: a model of no known window is told the default under the longest context too (ul3140773077392 on X, #6259)
settings.ContextCap held every window magpie knew, but fourteen agents
write a default of their own (128000 or 200000) for a model whose window
magpie doesn't know, and that default went out past the cap: Crush, ZCode,
VS Code and its forks (Copilot, Zoo Code, Air), Copilot for JetBrains, Zed,
jcode, Pencil, AtomCode, Kimi, OpenClaw, Snow, WorkBuddy and CodeBuddy.
unknownWindow holds each default to the cap. AtomCode's output clamp used
the constant and now uses the window it is told.

BaoCode (a Claude Code front end) keeps its own context per model and
reads no window from magpie; Claude Code gets the cap through
CLAUDE_CODE_MAX_CONTEXT_TOKENS, which it does follow. Not changed.

Guard: TestEveryAgentFollowsContextCap connects every agent that can be
here to a provider with a 987654 model and a model of no window, under a
cap of 99999, and fails on any agent file holding either window or a
default. Red on the old code in 14 agents' files (checked on mote), green
after.

Run on mote: go test ./internal/agent ./internal/provider ok; go vet
darwin, GOOS=windows, GOOS=linux -tags nogui ok; gofmt clean.
Not tried: a live BaoCode, the full suite (started after the tag), GUI.
2026-11-12 11:53:33 +08:00

65 lines
2.2 KiB
Go

package agent
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// The longest context (settings.ContextCap) is told to every agent that is
// written a context window (ul3140773077392 on X, #6259: dsh followed it,
// another harness kept 200K). Each agent is connected to a provider whose
// model has a 987654-token window under a cap of 99999; no file the agent
// reads may hold the longer one.
func TestEveryAgentFollowsContextCap(t *testing.T) {
const long, capAt = "987654", 99999
home, _ := codexHome(t, "", "")
managed := claudeManaged
claudeManaged = func() string { return filepath.Join(home, "managed-settings.json") }
t.Cleanup(func() { claudeManaged = managed })
startAlma(t)
startShelley(t)
os.MkdirAll(filepath.Join(home, ".hanako", "agents", "hana"), 0o755)
os.WriteFile(filepath.Join(home, ".hanako", "agents", "hana", "config.yaml"), []byte("agent:\n name: Hana\n"), 0o644)
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "https://example.test/v1", Key: "k",
Models: []string{"big", "plain-model-of-no-window"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("v", "https://example.test/v1", []catalog.Model{{ID: "big", Context: 987654}, {ID: "plain-model-of-no-window"}}); err != nil {
t.Fatal(err)
}
if err := settings.Save(settings.Settings{ContextCap: 99999}); err != nil {
t.Fatal(err)
}
catalog.Touched()
for _, a := range All() {
if a.Launch != nil || a.Native != nil || a.WSL != "" || len(a.Fields) == 0 {
continue
}
t.Run(a.ID, func(t *testing.T) {
if _, err := a.ConnectHow(); err != nil {
t.Skip("can't be connected here:", err)
}
if !a.Wired() {
t.Skip("not wired by Connect here")
}
SyncCatalog()
for p, b := range agentFiles(t, home) {
for _, d := range []string{"128000", "128_000", "200000", "250000", "262144", "256000", "131072"} {
if strings.Contains(b, d) {
t.Errorf("%s holds the default window %s past the cap %d", p, d, capAt)
}
}
if strings.Contains(b, long) {
t.Errorf("%s holds the window %s past the cap %d", p, long, capAt)
}
}
})
}
}