Files
magpie/internal/agent/claude_compact_test.go
T
yetone 531dc0aa33 claude: a Claude model runs to its own window in Claude Code, not 272K, and magpie model compact on|off is the Long conversations switch from the terminal (Max on Discord: a [1m] model's context stopped at 272K, magpie wrote CLAUDE_CODE_AUTO_COMPACT_WINDOW back when it was taken out, and there seemed to be no way to change it) — on magpie, Claude Code was told CLAUDE_CODE_AUTO_COMPACT_WINDOW=272000 whatever its model, so a [1m] Claude model compacted at 272K, though Anthropic runs it to 1M (the cap was meant for other vendors' long windows: Chen's DeepSeek turns of ~550K). Now a main model that is one of Anthropic's Claude models, from whichever provider, has the env left out (magpie's own value taken away), and Claude Code compacts at the model's own window; another vendor's model of a longer window keeps the 272K cap unless Settings → Long conversations is on Full window. A value the user writes there is still kept. The switch was only in the app's Settings; magpie model compact [on|off] (alias full-context) shows and sets it, and the Settings row's description says how Claude models are treated (en, zh, ja, de). TestClaudeCompactWindow (a Claude [1m] model gets no 272000, set and synced; another vendor's after it is capped again) and TestModelCompactCmd fail on the old code. The Long conversations row read right in WebKit, en and zh. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass (TestClaudeFailureKeepsClaudeCodesStatus flaked once under load, passes alone).
2026-10-05 00:09:49 +08:00

87 lines
2.8 KiB
Go

package agent
import (
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// TestClaudeCompactWindow: on magpie Claude Code compacts at the working
// window (CLAUDE_CODE_AUTO_COMPACT_WINDOW), another vendor's [1m] model too, so a 1M model's
// conversation isn't run to 1M with every turn sending all of it (X: Chen);
// settings.FullContext takes it away, a Claude model runs to its own, a value the user set is theirs, and
// Claude Code as installed has none.
func TestClaudeCompactWindow(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "https://example.test/v1", Key: "k",
Models: []string{"big", "claude-opus-5-5"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("v", "https://example.test/v1", []catalog.Model{{ID: "big", Context: 1000000}, {ID: "claude-opus-5-5", Context: 1000000}}); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, ".claude", "settings.json")
writeFile(t, path, `{}`)
a := claude(home)
compact := func() string { v, _ := edit.GetJSON(path, "env."+claudeCompactEnv); return v }
must := func(err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
}
must(a.Field("model").Set("v/big[1m]"))
if compact() != "272000" {
t.Fatalf("on magpie: %q", compact())
}
must(settings.Save(settings.Settings{FullContext: true}))
must(a.Sync())
if compact() != "" {
t.Fatalf("full context: %q", compact())
}
must(settings.Save(settings.Settings{}))
must(a.Sync())
if compact() != "272000" {
t.Fatalf("back to the working window: %q", compact())
}
// a Claude model runs to its whole window, as Anthropic runs a [1m]
// one (Max on Discord: a [1m] model stopped at 272K), and another
// vendor's is capped again after it
must(a.Field("model").Set("v/claude-opus-5-5[1m]"))
if compact() != "" {
t.Fatalf("a Claude model: %q", compact())
}
must(a.Sync())
if compact() != "" {
t.Fatalf("a Claude model, synced: %q", compact())
}
must(a.Field("model").Set("v/big[1m]"))
if compact() != "272000" {
t.Fatalf("after a Claude model: %q", compact())
}
must(a.Field("model").Set(""))
if compact() != "" {
t.Fatalf("Claude Code as installed: %q", compact())
}
// the user's own is left as it is
must(edit.SetJSON(path, edit.KV{Path: "env." + claudeCompactEnv, Value: "500000"}))
must(a.Field("model").Set("v/big[1m]"))
must(a.Sync())
if compact() != "500000" {
t.Fatalf("the user's own: %q", compact())
}
must(a.Field("model").Set(""))
if compact() != "500000" {
t.Fatalf("reset took the user's own: %q", compact())
}
}