Files
magpie/internal/provider/copilot_limits_test.go
T
yetone 4f38882c4c copilot: the window is the prompt Copilot takes, and Codex's entries say effective_context_window_percent (codealc on X)
Copilot's /models says capabilities.limits.max_prompt_tokens per account
(936000 for gemini-4-carbon); magpie dropped it and told agents models.dev's
1048576 for the id, so Codex sent prompts Copilot answered 400 to. The
window of a Copilot model is now that limit (models whose list says none keep
models.dev's); other vendors are unchanged, the field being read only in
copilotModels.

The model catalog magpie writes for Codex lacked
effective_context_window_percent, which every entry of Codex's own catalog
has (95); Codex 0.166 worked out no limit from such an entry and never
compacted. Magpie's entries now say 95, and a vendor-listed entry that
omitted it gets it.

Run: TestCopilotWindowIsThePromptItTakes, TestCodexCatalogSaysEffectivePercent
and the codexcat/provider tests via mote-run. Broken by hand: window set to 0,
and the percent left out; each new test goes red.
Not tried: Codex 0.166 itself against the catalog (Codex 0.165 is on this
machine; the live config was not touched).
2026-11-12 14:17:12 +08:00

46 lines
1.8 KiB
Go

package provider
import (
"context"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
)
// Copilot's /models says the prompt the account takes for a model
// (capabilities.limits.max_prompt_tokens: 936K for gemini-4-carbon), and
// that is the window, not models.dev's 1048576 for the id: past it Copilot
// answers 400 and Codex, told 1M, never compacted (codealc on X). A model
// whose limits say none keeps the window models.dev gives.
func TestCopilotWindowIsThePromptItTakes(t *testing.T) {
signIn(t)
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `{"data":[
{"id":"gemini-4-carbon","name":"Gemini 4 Carbon","model_picker_enabled":true,"policy":{"state":"enabled"},"supported_endpoints":["/chat/completions"],"capabilities":{"type":"chat","limits":{"max_context_window_tokens":1048576,"max_prompt_tokens":936000,"max_output_tokens":65536}}},
{"id":"gpt-4.1","name":"GPT-4.1","model_picker_enabled":true,"policy":{"state":"enabled"},"supported_endpoints":["/chat/completions"],"capabilities":{"type":"chat"}}]}`)
}))
defer api.Close()
copilotSessions = map[string]copilotSession{"gho_lim": {Token: "sess", ExpiresAt: time.Now().Add(time.Hour).Unix(), Endpoints: struct {
API string `json:"api"`
}{API: api.URL}}}
ms, err := copilotModels(context.Background(), copilotApp{User: "octocat", Token: "gho_lim"})
if err != nil {
t.Fatal(err)
}
p := Provider{ID: "copilot"}
got := map[string]int{}
for _, m := range ms {
got[m.ID] = p.WindowOf(m)
}
if got["gemini-4-carbon"] != 936000 {
t.Errorf("gemini-4-carbon window %d; want 936000", got["gemini-4-carbon"])
}
if got["gpt-4.1"] != catalog.ContextOf("gpt-4.1") {
t.Errorf("gpt-4.1 window %d; want models.dev's %d", got["gpt-4.1"], catalog.ContextOf("gpt-4.1"))
}
}