Settings > Models > Routing has a Longest context field (magpie model context-cap [<size>|off], POST /api/settings/context-cap). It lowers every model's window to it, so a user need not set each model. A window the user set on a model, or on its provider with "*", wins and is not capped; a model whose window is unknown stays unknown. It is applied where the window is derived, provider.windowIn, so /v1/models, every agent's catalog, group windows and the compaction thresholds that follow the window all agree. Codex's own models take it through CodexNativeWindow, CodexWindow and codexcat.Cap on the list the gateway serves; the list's ETag carries the cap so Codex asks again. The provider editor's Listed value stays the vendor's. Run (mote): provider, codexcat, cli, settings, settingsapi, gateway tests; GUI context-cap, model-load, settings-places, i18n-keys, settings-general in chromium and webkit (en, zh); TestCoreScriptBudget; gofmt; vet on darwin, linux nogui and windows. Broken by hand: windowIn without the cap turns TestContextCapHoldsEveryModelButTheOnesTheUserSet and TestModelsListContextCap red. Not tried: the whole GUI suite (one row added to an existing list, no new API read on page load), a real Codex reading the capped list, Windows run. Not covered: Claude Code's own [1m] choice (claudeRunName) and agent/claude.go's fallback when a ref has no window.
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// magpie model context-cap 200k holds every model's window to 200K, off
|
|
// takes it away, and a value that is not a length is refused with the cap
|
|
// as it was (WJaunita45604 on X).
|
|
func TestModelContextCapCmd(t *testing.T) {
|
|
groupsHome(t)
|
|
catalog.Changed = nil // no agent's files are rewritten here
|
|
if err := modelCmd([]string{"context-cap", "200k"}); err != nil || settings.Load().ContextCap != 200000 {
|
|
t.Fatal(err, settings.Load().ContextCap)
|
|
}
|
|
if err := modelCmd([]string{"context-cap"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, bad := range []string{"maybe", "-5", "0k"} {
|
|
if err := modelCmd([]string{"context-cap", bad}); err == nil || settings.Load().ContextCap != 200000 {
|
|
t.Fatalf("took %q: %v, cap %d", bad, err, settings.Load().ContextCap)
|
|
}
|
|
}
|
|
if err := modelCmd([]string{"context-cap", "off"}); err != nil || settings.Load().ContextCap != 0 {
|
|
t.Fatal(err, settings.Load().ContextCap)
|
|
}
|
|
}
|