Files
magpie/internal/provider/commandcode_plan_test.go
T
yetone be62bcf79e provider: Command Code's built-in is retired; its plugin serves it
commandcode-plan joins retiredBuiltins (migrate.go): PluginServes is true
for it moved or not, and @magpie-community/opencode-commandcode-auth does
its sign-in, models, requests and usage.

Removed
- Sign-in: the StartSignIn case (startCommandCodeSignIn, the Studio
  callback, cmdOrigins, cmdWhoamiWait, commandCodeCallback/Keep) and the
  pasted-key branch (commandCodeKey, cmdSignedIn).
- Accounts: commandCodeAccount, cmdProvider, cmdSide, cmdLoginList,
  switch/on/forget (switchCommandCodeLogin, setCommandCodeLoginOn,
  forgetCommandCodeLogin, commandCodeAlsoOn), the Logins case, and the
  per-login usage (cmdLoginQuota, cmdQuota, the perLogin fetch). The
  Logins("") list keeps {CommandCodePlanID, nil} so its order holds.
- The Go plan's path: CommandCodeGenerate, cmdGoModels/cmdGoFetch/
  cmdGoRefused, cmdModels, cmdFree/cmdMarkFree, cmdPlansSeen's built-in
  users (cmdRemember, cmdPlanKnown, cmdPlanNow), CommandCodeOutputOf, and
  the account's generate field.
- asksOwnBackend's Command Code case.
- Gateway: the cmdGenerate/serveCommandCode dispatch and countOn's
  cmdGoing clause; internal/gateway/commandcode.go (the /alpha/generate
  translator) deleted.
- Built-in-only tests: gateway commandcode_test.go and
  commandcode_place_test.go, TestBillingLineLeftOutOnCommandCode;
  provider commandcode_go_test.go, commandcode_go_models_test.go,
  commandcode_free_test.go, TestCommandCodePlan,
  TestCommandCodeSignInWhoamiDown, TestCommandCodeSignInAgainToRemovedOwn,
  TestCommandCodeSignInPastedKey.
- Docs: Command Code out of gateway-routing.md's bridge lists (the
  2xx check, structured output, tool images, the billing line).

Kept, and why
- The mover and what it reads: cmdAuth, cmdOwn, cmdWho, cmdLogin,
  cmdSaved, cmdLogins (migrate_side.go, plugin_accounts.go).
- cmdAPI/cmdStudio (plugin_usage.go's moved card), cmdKeysURL
  (pluginsignin_paste.go), the plan and credit readers (cmdPlans,
  cmdPlanOf, cmdPlanName, cmdWindows, cmdLeft, cmdQuotaOf, cmdTime,
  cmdSubscription, cmdKeyWindows, cmdKeyPlanID): the keyed preset
  "commandcode", planquota.go, balance.go and qoder_usage.go use them.
- CommandCodeMaxOutput (models.go caps the plugin's "commandcode-plan"
  models with it), estimatedMoved, chat.go's plugin host cases, the
  gateway parity tests, and the PLUGIN-SERVED notice in
  commandcode_plan.go, now in the retired wording.

Tests whose meaning changed
- TestLoopbackSignInsTakePastedAddress no longer starts Command Code's
  built-in sign-in; the plugin's (TestLoopbackPorts) says its key is
  posted, never pasted as an address.
- The Go plan's free-model marks (TestCommandCodeFreeModels) were the
  built-in's alone; the keyed preset never marked them.

Run (worktree magpie-wt-rt-a, on top of 9a64c4025)
- gofmt -l internal: clean
- go vet -tags nogui ./... (darwin, GOOS=linux, GOOS=windows): clean
- staticcheck U1000 on ./internal/...: no declaration unused that wasn't
  unused at HEAD
- go test -tags nogui -count=1 ./internal/provider/ -run
  'CommandCode|commandcode|Migrat|Move|Moved|Retir|SignIn|AsksOwnBackend|
  SideLogin|Logins|Unmoved|Paste|Loopback|Account|PlanQuota|Balance|
  FetchNew|FetchingNew|LeftAlone|Identit|Order': ok (100s)
- same, -run 'Usage|Card|Quota|Discovery|Exposed|Models|Output': ok
- ./internal/gateway/ -run 'CommandCode|commandcode|Plugin|Parity|Moved|
  BillingLine|Search|ShapeFallback|GroupFails|CountTokens|Count|Format|
  ToolImage|Cursor|Connect': ok (117s)
- ./internal/cli/ ./internal/gui/ -run 'CommandCode|commandcode|Plugin|
  Retired|Moved|SignIn|Login': ok
- Not run: whole packages, the full suite, the GUI node suite (the
  machine is loaded; the parent runs those).
2026-10-17 23:11:01 +08:00

59 lines
2.2 KiB
Go

package provider
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/settings"
)
func TestCommandCodePlanName(t *testing.T) {
for id, want := range map[string]string{
"individual-go": "Go", "individual-goat": "GOAT", "individual-pro-v1": "Pro", "individual_ultra": "Ultra",
"teams-pro": "Teams Pro", "individual-provider": "Provider", "enterprise": "",
} {
if got := cmdPlanName(id); got != want {
t.Errorf("%s: %q, want %q", id, got, want)
}
}
if tm := cmdTime(float64(1_900_000_000_000)); tm == nil || tm.Unix() != 1_900_000_000 {
t.Fatalf("ms: %v", tm)
}
}
// Command Code answers a 200 with success false when it couldn't read the
// subscription ("write CONNECTION_CLOSED …"): the plan is unread, not none.
func TestCommandCodeSubscriptionUnread(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]any{"success": false, "error": "write CONNECTION_CLOSED db.local:5432"})
}))
defer srv.Close()
oldAPI := cmdAPI
cmdAPI = srv.URL
defer func() { cmdAPI = oldAPI }()
if _, plan, _, _, ok := cmdSubscription(context.Background(), cmdAuth{APIKey: "k"}); ok || plan != "" {
t.Fatalf("plan %q, ok %v: want it unread", plan, ok)
}
}
// A Command Code model is told to the agents with a reply limit within the
// 200000 Command Code takes: models.dev gives DeepSeek V4 384000, and an
// agent asking for that was refused. Another provider's is left as it is.
func TestCommandCodeOutputCapped(t *testing.T) {
m := catalog.Model{ID: "deepseek/deepseek-v4-pro", Context: 1_000_000, Output: 384_000}
if got := entryFor(Provider{ID: CommandCodePlanID}, m, settings.Settings{}).Output; got != CommandCodeMaxOutput {
t.Errorf("Command Code: output %d, want %d", got, CommandCodeMaxOutput)
}
if got := entryFor(Provider{ID: "deepseek"}, m, settings.Settings{}).Output; got != 384_000 {
t.Errorf("deepseek: output %d, want 384000", got)
}
m.Output = 64_000
if got := entryFor(Provider{ID: CommandCodePlanID}, m, settings.Settings{}).Output; got != 64_000 {
t.Errorf("Command Code, within: output %d, want 64000", got)
}
}