Files
magpie/internal/cli/model_compact_cli_test.go
T
yetone 6b47bce670 cli: magpie model compact <agent> sets an agent's own Long conversations
3eb2bda4f added POST /api/settings/agent-compact with no command, and
internal/cli's TestEveryRouteHasACommandOrIsNamed went red in the full
suite run after the push (settings_parity_test.go:437). Rather than
park the route in notYet, the command it names is here:

  magpie model compact <codex|claude|grok>            says the agent's
  magpie model compact <agent> every|off|<size>       sets it

every takes the agent's own away (it follows the value for every
agent), off is Full window, a size such as 300k compacts there; another
word is refused and nothing is written. A first word that isn't one of
settings.CompactAgents goes to the command as before (on|off|<size>).
cliForRoute names it; the usage text and agent-wiring.md say it.

Run at this tree (3eb2bda4f + this), on mote: go vet ./internal/cli,
GOOS=windows go vet ./internal/cli, go test ./internal/cli: ok.
TestModelCompactAgentCmd broken by hand (the command setting the shared
value instead): red, "codex 300000, claude 300000".
Not tried: the command against a real agent's files (catalog.Changed is
nil in the test, as in TestModelCompactCmd).
2026-11-04 16:35:16 +08:00

69 lines
2.4 KiB
Go

package cli
import (
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/settings"
)
// magpie model compact off runs Codex's and Claude Code's conversations to
// the model's whole window, on compacts them at the working window again
// (Max on Discord found no way to it but the app's Settings); anything else
// is refused.
func TestModelCompactCmd(t *testing.T) {
groupsHome(t)
catalog.Changed = nil // no agent's files are rewritten here
if err := modelCmd([]string{"compact"}); err != nil {
t.Fatal(err)
}
if err := modelCmd([]string{"compact", "off"}); err != nil || !settings.Load().FullContext {
t.Fatal(err, settings.Load().FullContext)
}
if err := modelCmd([]string{"compact"}); err != nil {
t.Fatal(err)
}
if err := modelCmd([]string{"compact", "on"}); err != nil || settings.Load().FullContext {
t.Fatal(err, settings.Load().FullContext)
}
if err := modelCmd([]string{"full-context", "full"}); err != nil || !settings.Load().FullContext {
t.Fatal(err, settings.Load().FullContext)
}
if err := modelCmd([]string{"compact", "maybe"}); err == nil {
t.Fatal("took maybe")
}
}
// magpie model compact codex 300k gives Codex a Long conversations of its
// own, which Claude Code doesn't take; every takes it away, and an agent
// that writes no compaction window is refused (molianyin4227 on Discord).
func TestModelCompactAgentCmd(t *testing.T) {
groupsHome(t)
catalog.Changed = nil
if err := modelCmd([]string{"compact", "codex", "300k"}); err != nil {
t.Fatal(err)
}
s := settings.Load()
if s.ForAgent("codex").Compact() != 300000 || s.ForAgent("claude").Compact() == 300000 {
t.Fatalf("codex %d, claude %d", s.ForAgent("codex").Compact(), s.ForAgent("claude").Compact())
}
if err := modelCmd([]string{"compact", "grok", "off"}); err != nil || !settings.Load().ForAgent("grok").FullContext || settings.Load().FullContext {
t.Fatal(err, settings.Load().AgentCompacts)
}
if err := modelCmd([]string{"compact", "codex"}); err != nil {
t.Fatal(err)
}
if err := modelCmd([]string{"compact", "codex", "every"}); err != nil {
t.Fatal(err)
}
if _, has := settings.Load().AgentCompacts["codex"]; has {
t.Fatal("every kept Codex's own")
}
if err := modelCmd([]string{"compact", "codex", "lots"}); err == nil {
t.Fatal("took lots")
}
if len(settings.Load().AgentCompacts) != 1 {
t.Fatal(settings.Load().AgentCompacts)
}
}