The root held 89 .go files (30 commands, 59 tests). They move as they are to internal/cli (package cli), with git mv so history follows them. The only code change is main() becoming cli.Main(version): the root's new main.go keeps `var version` in package main, so -ldflags "-X main.version=…" in the Makefile, the Dockerfile and magpie-releases, and every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land next to package main in the root. Tests that read testdata by a root-relative path now go up one level (../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links point at internal/cli/. Run: - go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui) - builds with tags production, dev, "production nogui"; windows -H windowsgui; linux CGO_ENABLED=0 - make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64 android/arm64" VERSION=9.9.9-tidy: all four built, binary prints "magpie 9.9.9-tidy" - docker build --build-arg VERSION=7.7.7-tidy: container prints "magpie 7.7.7-tidy" - go test ./internal/cli (default and nogui): 152 tests, the same count as the root on main - go test ./...: all packages pass (agent, gateway, library, provider timed out at 10m under other sessions' load and passed rerun alone with -timeout 40m; none of them changed) - the built binary in a sandbox HOME: version, help, ls, providers, claude, and an unknown command's error
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/agentenv"
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A provider no longer known to LoginUsage has no quota, but its remembered
|
|
// account still has to be listed. Fast empty results also exercise the same
|
|
// concurrent writes as cached usage, without a vendor or a real sign-in.
|
|
func TestAccountRowsConcurrentUsage(t *testing.T) {
|
|
home := t.TempDir()
|
|
for _, key := range agentenv.Vars {
|
|
t.Setenv(key, "")
|
|
}
|
|
for key, dir := range map[string]string{
|
|
"HOME": home, "USERPROFILE": home,
|
|
"XDG_CONFIG_HOME": filepath.Join(home, ".config"),
|
|
"XDG_CACHE_HOME": filepath.Join(home, ".cache"),
|
|
"XDG_DATA_HOME": filepath.Join(home, ".local", "share"),
|
|
"APPDATA": filepath.Join(home, "AppData", "Roaming"),
|
|
"LOCALAPPDATA": filepath.Join(home, "AppData", "Local"),
|
|
} {
|
|
t.Setenv(key, dir)
|
|
}
|
|
plugin.UseCached([]plugin.Provider{})
|
|
t.Cleanup(func() { plugin.UseCached(nil) })
|
|
now := time.Date(2026, time.October, 3, 12, 0, 0, 0, time.UTC)
|
|
|
|
for _, tc := range []struct {
|
|
name string
|
|
accounts int
|
|
providers int
|
|
reads int
|
|
}{
|
|
{"single-provider", 1, 1, 1},
|
|
{"multiple-providers", 256, 256, 8},
|
|
{"same-provider-accounts", 256, 1, 8},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
logins := make([]provider.Login, tc.accounts)
|
|
want := make([]accountRow, tc.accounts)
|
|
for i := range logins {
|
|
l := provider.Login{
|
|
Agent: fmt.Sprintf("contribution-race-%03d", i%tc.providers),
|
|
User: fmt.Sprintf("account-%03d@example.test", i),
|
|
Plan: "Synthetic", Seen: now, On: true,
|
|
}
|
|
logins[i] = l
|
|
want[i] = accountRow{Agent: l.Agent, User: l.User, Plan: l.Plan, On: l.On, Windows: []quotaSpan{}}
|
|
}
|
|
for i := range tc.reads {
|
|
got := accountRows(logins, now)
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("read %d: account rows = %+v, want %+v", i, got, want)
|
|
}
|
|
}
|
|
t.Logf("listed %d accounts across %d providers with empty usage on %d reads", tc.accounts, tc.providers, tc.reads)
|
|
})
|
|
}
|
|
}
|