Files
magpie/internal/provider/kiro_main_test.go
T
yetone 54a003d48d provider tests: the device sign-ins' fakes poll every 10ms, not the 1s floor a vendor's 0 interval got (#2051)
Copilot, Factory and ZCode's device sign-ins wait at least a second
between polls, whatever interval the vendor gives. The tests' fakes give
0, so each poll in a test cost a full second, and these tests were 56.5s
of the provider package's 399s of test time.

The floor is now devicePollFloor, read through devicePoll(seconds) at the
three call sites, and the provider package's TestMain lowers it to 10ms.
Real sign-ins still wait max(vendor's interval, 1s), as before.
TestDevicePollKeepsItsFloor checks 0, -1 and 1 give 1s and 5 gives 5s.

Run:
- go test ./internal/provider (full, -count=1, load avg ~100): pass,
  403s -> 316s of package time; the Copilot/Factory/ZCode tests 56.5s
  -> 22.5s.
- A/B on -run 'Copilot|Factory|ZCode', base vs this: 45-58s vs 15-16s
  (32s once, under load).
- Removing the floor from devicePoll turns TestDevicePollKeepsItsFloor red.
- gofmt -l clean; go vet darwin, linux (-tags nogui), windows; linux and
  windows builds.

One A/B round failed on both base and this change at load over 200; the
cause wasn't captured, and the next 4 rounds passed on both.

Not done: the other slow causes in the package. The 1.2s sleeps waiting
for the callback port to be let go (signin_test.go:137,
signin_proxy_test.go:92, signin_usage_afresh_test.go:70), Cursor's
linkWait, MoveToPlugin (7-9s) and WarmAtSeveralTimes (6-10s).
2026-10-14 09:29:59 +08:00

36 lines
1.4 KiB
Go

package provider
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/testenv"
)
// TestMain keeps the package's tests off the Kiro and Copilot CLI sign-ins
// of whoever runs them: Accounts() reads them, and asks Kiro who the account is. It also
// gives the package a home of its own (testenv), so what a test leaves
// behind it — a CLI's answer kept by refresh after the test is over —
// never lands in the runner's magpie, nor in APPDATA on Windows. And it
// keeps them off the network (testenv.Offline): a test of a sign-in or a
// key at a vendor's real address asks only what it serves on loopback.
func TestMain(m *testing.M) {
os.Exit(testenv.RunIn(m, func(home string) {
testenv.Offline()
kiroCLIDB = func() string { return filepath.Join(home, "kiro-test", "kiro-cli", "data.sqlite3") }
kiroIDEDir = func() string { return filepath.Join(home, "kiro-test", "sso") }
askKiroIdentity = func(string, string) (string, string) { return "", "" }
// never the runner's keychain: a test that wants the Copilot
// CLI's token there stands one in itself
copilotCLISecret = func(string) string { return "" }
// the fakes of ChatGPT's backend read turns plain; codex_zstd's
// tests send them as the real one is sent
CodexZstdForTests(false)
// the fakes' device sign-ins give an interval of 0: polled at
// once, not a second apart (#2051)
devicePollFloor = 10 * time.Millisecond
}))
}