"cursor" joins retiredBuiltins (migrate.go), so PluginServes("cursor")
holds moved or not, and the built-in's code goes, as Zed's did in
c0605abc2 and Kiro's in the commit before this.
Removed:
- gateway/cursor.go (the Connect/protobuf translator) and its tests
(cursor_test, cursor_conversation_test, cursor_maxmode_test,
cursor_precision_test, cursor_stepusage_test), and gateway.go's
Account.Agent == "cursor" dispatch to serveCursor;
- provider/cursor_usage.go (the usage card, cursorToken, cursorKeychain)
and provider/cursor_picker.go, with their tests;
- from cursor.go: the built-in account (cursorAccount), its model list
through `cursor-agent models` (cursorModels, parseCursorModels,
cursorModelL), its sign-in (startCursorSignIn, cursorLinkWhole,
cursorLoginUUID), the API client version (CursorClientVersion,
cursorVersionFallback, cursorVersionRe) and the token refresh
(CursorToken, cursorRefresh, tokenExpiry);
- StartSignIn's "cursor" case (signin.go), the usage fetch
(subscription_usage.go), the login-list case and quota (login_usage.go)
and the account (account.go);
- "cursor" from Native (provider.go) and asksOwnBackend (modelprefs.go).
Kept, because the mover, the plugin paths or other code need them:
- cursor.go's PLUGIN-SERVED notice (TestMovedBuiltinsSayTheirPlugin);
cursorIdentity, cursorStatus, parseCursorAbout, readCursorToken,
cursorTokenOf, cursorKeychainToken and cursorAuthFile: migrate_side.go
and plugin_accounts.go ask whose account the agent is through them;
- cursorLoginURL (grok.go and claude_signin.go use it), cursorContext and
withCursorContexts (the plugin's model contexts), CursorExecutable and
isCursorAgent (the Cursor agent itself);
- cursor_models.go whole: CursorBase (agent/legacy.go), CursorVariants
(groupfast.go, the plugin's fast pick), cursorPicks and the collapse
(provider.go, models.go);
- accountIDs, builtinOrder, models.go's "cursor" live branch and
servedByCursor, as Zed's and Kiro's commits left theirs. The live
collapse and cursorPicks now only ever meet a built-in list, which a
retired Cursor never has; they are left for a cleanup of their own.
- gateway/cursor_local_models_test.go (the Cursor agent, not the
built-in) and the gateway's plugin_*_test.go parity tests.
Tests changed in meaning:
- cursor_signin_test.go became cli_signin_test.go: its two generic
runCLISignIn tests stay (grok's), TestCursorSignInJoinsAWrappedLink
goes with cursorLinkWhole.
- cursor_test.go keeps parseCursorModels as a test helper (the old
parser, for the collapse tests' fixtures); TestParseCursorModels,
TestCursorClientVersion, TestTokenExpiry and TestCursorLegacyPicks go,
and cursor_names_test.go's TestCursorAvailableNames: they tested the
built-in account's list and picks. Cursor's plugin lists its own
picker models with their efforts (index.mjs), so magpie's collapse
never runs for it; moving the two tests onto the plugin showed that.
- TestFetchNewWaitsForASlowSignIn (#1789) and
TestFetchNewListsAgainForAnAnswerWhileListing (#1147) are gone: both
were about a CLI account whose models `cursor-agent models` lists,
and no built-in left lists its models through its CLI.
- internal/gui/providers_fetching_unix_test.go
(TestProvidersAnswerWhileListsComeIn, #541) is gone: its slow vendor
was the built-in's `cursor-agent models`. The guarantee (the
Providers page answers while an account's list comes in) has no test
now; re-homing it onto an HTTP-listed account (Antigravity, Copilot)
needs exported test hooks and is left as a follow-up.
- TestNative drops its Cursor case; TestLeftAloneRunsNoCLI fakes and
expects claude and devin only; isolate() and
TestAccountDiscoveryOffReadsNoSignIn no longer set cursorKeychain
(cursorTokenOf reads the Keychain on macOS only, as before).
- Dropped as built-in only: the Cursor case of the required-tools test,
TestCodexToolImageCursor, TestCursorSplitParallelCallsKeepTheirResults.
Run at this tree (load ~300, so narrow runs only):
- gofmt -l internal: clean
- go vet -tags nogui ./... ; GOOS=linux and GOOS=windows the same: ok
- staticcheck -tags nogui -checks U1000 ./internal/provider/: clean;
with -tests=false over provider and gateway: nothing Cursor or Kiro
- go test -tags nogui -count=1 -run 'Cursor|Kiro|Migrat|Mov|Retired|
SignIn|AsksOwnBackend|Plugin|HandOver|NoWayBack|Adopt|Hide|
RequiredTools|ToolImage|Split|Discovery|Account|Isolat' over
provider, gateway, cli, gui: gateway ok 446s, cli ok 67s, gui ok 51s;
provider failed TestCursorAvailableNames, TestCursorLegacyPicks,
TestFetchNewWaitsForASlowSignIn (above) and
TestSetUpstreamNameRefusesAnAccountBackend (Kiro's, fixed in that
commit)
- every other test naming "cursor" or cursor-agent, by name, over the
same four packages: gateway and cli ok; TestNative,
TestLeftAloneRunsNoCLI, TestFetchNewListsAgainForAnAnswerWhileListing
and TestProvidersAnswerWhileListsComeIn failed (above)
- after the changes: gofmt clean, vet ok on all three; -run 'Cursor|
Kiro|Migrat|Mov|Retired|SignIn|AsksOwnBackend|Plugin|HandOver|
NoWayBack|Adopt|Hide|Discovery|Account|Native|LeftAlone|SetUpstream|
FetchNew|Hold|DailyCredits|NotSignedIn|ModelTest|Providers': provider
ok 141s, gui ok 21s, cli ok 22s (gateway untouched since its ok run)
Not run: the whole packages, the full suite, the GUI node suite.
151 lines
6.6 KiB
Go
151 lines
6.6 KiB
Go
package provider
|
||
|
||
import (
|
||
"fmt"
|
||
"os"
|
||
"path/filepath"
|
||
"regexp"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/yetone/magpie/internal/catalog"
|
||
"github.com/yetone/magpie/internal/plugin"
|
||
)
|
||
|
||
// parseCursorModels reads `cursor-agent models` as it prints it, the way the
|
||
// retired built-in did: the tests below build their lists from it.
|
||
func parseCursorModels(out string) []catalog.Model {
|
||
line := regexp.MustCompile(`^([A-Za-z0-9][\w.:-]*) - (.+)$`)
|
||
var ms []catalog.Model
|
||
for _, l := range strings.Split(ansi.ReplaceAllString(out, ""), "\n") {
|
||
m := line.FindStringSubmatch(strings.TrimSpace(l))
|
||
if m == nil {
|
||
continue
|
||
}
|
||
name := strings.Join(strings.Fields(strings.ReplaceAll(m[2], "\u200b", "")), " ")
|
||
name = strings.TrimSpace(strings.TrimSuffix(name, "(default)"))
|
||
name = strings.TrimSpace(strings.TrimSuffix(name, "(current)"))
|
||
ms = append(ms, catalog.Model{ID: m[1], Name: name, Context: cursorContext(m[1], name)})
|
||
}
|
||
return ms
|
||
}
|
||
|
||
// cursorListed is some of `cursor-agent models`, as it prints it.
|
||
const cursorListed = "Available models\n\nauto - Auto (default)\n" +
|
||
"gpt-5.3-codex-low - Codex 5.3 Low\ngpt-5.3-codex - Codex 5.3\ngpt-5.3-codex-high - Codex 5.3 High\ngpt-5.3-codex-high-fast - Codex 5.3 High Fast\n" +
|
||
"grok-4.7-low - Grok 4.7 Low\ngrok-4.7-low-fast - Grok 4.7 Low Fast\ngrok-4.7-medium - Grok 4.7 Medium\ngrok-4.7-medium-fast - Grok 4.7 Medium Fast\n" +
|
||
"grok-4.7-xhigh - Grok 4.7 Extra High\ngrok-4.7-xhigh-fast - Grok 4.7 Extra High Fast\n" +
|
||
"claude-opus-4-7-low - Claude Opus 4.7 1M Low\nclaude-opus-4-7-xhigh - Claude Opus 4.7 1M\nclaude-opus-4-7-max - Claude Opus 4.7 1M Max\n" +
|
||
"claude-opus-4-7-thinking-low - Claude Opus 4.7 1M Low Thinking\nclaude-opus-4-7-thinking-xhigh - Claude Opus 4.7 1M Thinking\n" +
|
||
"claude-4.6-opus-high-thinking - Claude Opus 4.6 1M Thinking\nclaude-4.6-opus-max-thinking - Claude Opus 4.6 1M Max Thinking\n" +
|
||
"gpt-5.5-none - GPT-5.5 1M None\ngpt-5.5-medium - GPT-5.5 1M\ngpt-5.5-extra-high - GPT-5.5 1M Extra High\n" +
|
||
"gpt-5.5-medium-fast - GPT-5.5 Fast\ngpt-5.5-extra-high-fast - GPT-5.5 Extra High Fast\n" +
|
||
"claude-4.6-sonnet-medium-thinking - Claude Sonnet 4.6 1M Thinking\ncomposer-2.5 - Composer 2.5\n\nTip: use --model <id>\n"
|
||
|
||
// Each family of Cursor's ids is one model, with the efforts it has; fast
|
||
// and thinking are families of their own, and a family of one keeps its id.
|
||
func TestCollapseCursorModels(t *testing.T) {
|
||
raw := withCursorContexts(parseCursorModels(cursorListed))
|
||
if raw[5].Name != "Grok 4.7 Low" || raw[6].Name != "Grok 4.7 Low Fast" {
|
||
t.Fatalf("%q %q", raw[5].Name, raw[6].Name)
|
||
}
|
||
var got []string
|
||
for _, m := range collapseCursorModels(raw) {
|
||
got = append(got, fmt.Sprintf("%s|%s|%d|%s", m.ID, m.Name, m.Context, strings.Join(m.Efforts, ",")))
|
||
}
|
||
want := []string{
|
||
"auto|Auto|200000|",
|
||
"gpt-5.3-codex|Codex 5.3|200000|low,high",
|
||
"gpt-5.3-codex-high-fast|Codex 5.3 High Fast|200000|",
|
||
"grok-4.7|Grok 4.7|200000|low,medium,xhigh",
|
||
"grok-4.7-fast|Grok 4.7 Fast|200000|low,medium,xhigh",
|
||
"claude-opus-4-7|Claude Opus 4.7 1M|1000000|low,xhigh,max",
|
||
"claude-opus-4-7-thinking|Claude Opus 4.7 1M Thinking|1000000|low,xhigh",
|
||
"claude-4.6-opus-thinking|Claude Opus 4.6 1M Thinking|1000000|high,max",
|
||
"gpt-5.5|GPT-5.5 1M|1000000|none,medium,xhigh",
|
||
"gpt-5.5-fast|GPT-5.5 Fast|200000|medium,xhigh", // Cursor doesn't say 1M of it
|
||
"claude-4.6-sonnet-medium-thinking|Claude Sonnet 4.6 1M Thinking|1000000|",
|
||
"composer-2.5|Composer 2.5|200000|",
|
||
}
|
||
if strings.Join(got, "\n") != strings.Join(want, "\n") {
|
||
t.Fatalf("got\n%s\nwant\n%s", strings.Join(got, "\n"), strings.Join(want, "\n"))
|
||
}
|
||
for _, c := range []struct{ model, effort, want string }{
|
||
{"gpt-5.3-codex", "", "gpt-5.3-codex"},
|
||
{"grok-4.7", "", "grok-4.7-medium"},
|
||
{"claude-opus-4-7", "", "claude-opus-4-7-xhigh"}, // its name doesn't say its effort
|
||
{"claude-opus-4-7-thinking", "low", "claude-opus-4-7-thinking-low"},
|
||
{"claude-4.6-opus-thinking", "max", "claude-4.6-opus-max-thinking"},
|
||
{"gpt-5.5", "xhigh", "gpt-5.5-extra-high"},
|
||
{"gpt-5.5-fast", "", "gpt-5.5-medium-fast"},
|
||
} {
|
||
vs, ok := cursorVariantsIn(raw, c.model)
|
||
if !ok || vs[c.effort] != c.want {
|
||
t.Errorf("%s at %q: %v", c.model, c.effort, vs)
|
||
}
|
||
}
|
||
for _, id := range []string{"composer-2.5", "gpt-5.3-codex-high-fast", "grok-4.7-low", "nope"} {
|
||
if _, ok := cursorVariantsIn(raw, id); ok {
|
||
t.Errorf("%s stands for a family", id)
|
||
}
|
||
}
|
||
}
|
||
|
||
// Cursor's names say which of its models hold 1M; the rest hold its 200K
|
||
func TestCursorContext(t *testing.T) {
|
||
for _, c := range []struct {
|
||
id, name string
|
||
want int
|
||
}{
|
||
{"claude-opus-5-5-high-fast", "Claude Opus 5.5 1M High Fast", 1_000_000},
|
||
{"gpt-5.6-sol-xhigh", "GPT-5.6 Sol 1M Extra High", 1_000_000},
|
||
{"gpt-5.5-medium-fast", "GPT-5.5 Fast", 200_000},
|
||
{"composer-2.5", "Composer 2.5", 200_000},
|
||
{"auto", "Auto", 200_000},
|
||
} {
|
||
if got := cursorContext(c.id, c.name); got != c.want {
|
||
t.Errorf("%s (%s): %d, want %d", c.id, c.name, got, c.want)
|
||
}
|
||
}
|
||
if ms := withCursorContexts(parseCursorModels("x-1 - X 1M\n")); ms[0].Context != 1_000_000 {
|
||
t.Fatalf("%+v", ms)
|
||
}
|
||
}
|
||
|
||
// Cursor's plugin gives each model Cursor's 200K unless the name says 1M;
|
||
// a model known to hold less keeps its own there, as the built-in's list.
|
||
func TestCursorPluginContext(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"))
|
||
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
||
os.WriteFile(catalog.CachePath(), []byte(`{
|
||
"openai":{"id":"openai","models":{"gpt-4o":{"id":"gpt-4o","limit":{"context":128000,"output":16384}}}},
|
||
"moonshotai":{"id":"moonshotai","models":{"kimi-k2":{"id":"kimi-k2","limit":{"context":131072,"output":16384}}}}}`), 0o644)
|
||
catalog.Reset()
|
||
t.Cleanup(catalog.Reset)
|
||
pp := plugin.Provider{ID: "cursor", Models: []plugin.Model{
|
||
{ID: "gpt-4o", Name: "GPT-4o", Context: 200_000},
|
||
{ID: "kimi-k2-high", Name: "Kimi K2", Context: 200_000},
|
||
{ID: "claude-opus-5-5-high", Name: "Claude Opus 5.5", Context: 1_000_000},
|
||
{ID: "composer-2.5", Name: "Composer 2.5", Context: 200_000},
|
||
}}
|
||
got := map[string]int{}
|
||
for _, m := range pluginCatalog(pp) {
|
||
got[m.ID] = m.Context
|
||
}
|
||
want := map[string]int{"gpt-4o": 128_000, "kimi-k2-high": 131_072, "claude-opus-5-5-high": 1_000_000, "composer-2.5": 200_000}
|
||
for id, n := range want {
|
||
if got[id] != n {
|
||
t.Errorf("%s: %d, want %d", id, got[id], n)
|
||
}
|
||
}
|
||
// another plugin's models are its own
|
||
pp.ID = "fakeco"
|
||
if c := pluginCatalog(pp)[0].Context; c != 200_000 {
|
||
t.Fatalf("fakeco gpt-4o: %d", c)
|
||
}
|
||
}
|