The cause: the test wrote its fake secret-tool with os.WriteFile, so its
first exec paid macOS's check of a newly written program (0.27s here at
load ~10, several seconds while a go test ./... starts its binaries, as
testenv.Program's own doc records). That ran into copilotSecretWait (5s),
which the happy path was held to: both lookups (account, then username)
were killed and the token read as "".
Not a product bug from this cause: copilotSecretTool runs only on Linux,
against the user's installed secret-tool, which has no such check. The 5s
bound is for a keyring prompt nobody answers (#723) and stays.
The fix, in the test only:
- both fakes are testenv.Programs (a file that has already run once);
- the lookups that answer get copilotSecretWait = 10 minutes, since which
attribute is asked is no question of time; only the keyring that never
answers keeps 200ms;
- that case's bound moves from 10s to 30s: bounded it takes 2.4s at most
unloaded, unbounded 60s, so a loaded runner has room on both sides.
Run at the reviewed head (macOS, load ~9-15):
- Injected delay (sleep 6 at the top of the fake): the old test fails with
copilot_cli_test.go:94 token "", want the one under username (12.01s);
the new one passes (27s). Removing only the 10-minute wait by hand, with
the delay, goes red again.
- Broken by hand in copilot_cli.go: asking "account" only fails the test
(token ""), and dropping the timeout fails it on the hang case (63s).
- go test -count=20 -cpu 1,4 -run 'TestCopilotSecretToolUsername$|TestCopilotCLI'
./internal/provider: ok.
- gofmt -l: clean. go vet -tags nogui for darwin, windows, linux: clean.
- go test -p 4 -timeout 40m ./... under a sandbox HOME: 53 packages ok,
no FAIL.
magpie looked the CLI's token up with `secret-tool lookup service
copilot-cli account <host>:<login>`, the attributes keytar wrote before
the CLI 1.0. The CLI 1.0's Rust runtime keeps it through keyring-core's
zbus-secret-service-keyring-store, whose items carry service and
username (cred.rs search_attributes), so a CLI 1.0 signed in with a
keyring (magpie inside WSL or on a Linux desktop) wasn't found.
copilotSecretTool asks for both attributes, account first, and bounds
each lookup at 5s (copilotSecretWait): a keyring waiting on an unlock
prompt nobody answers held the caller for good, including a sign-in's
last step (addCopilotLogin -> copilotOwnUser -> copilotCLILogin).
The service name is still taken to be copilot-cli: the string is in the
1.0.95 runtime, but which call uses it couldn't be read from the binary.
Run: TestCopilotSecretToolUsername (a shell secret-tool answering only
under username, and one that never answers): red with only "account"
asked, green now.
jia2 runs Copilot CLI 1.0.95 inside WSL, signed in, and magpie (on
Windows) never saw it: copilotCLILogin read only Windows'
%USERPROFILE%\.copilot\config.json.
In a distro with no Secret Service (WSL has none unless one is set up),
the CLI asks to keep its token in plaintext and writes it under
copilotTokens["https://github.com:<login>"] in ~/.copilot/config.json
(read from the @github/copilot 1.0.95 package: its Rust runtime's
storeTokenPlaintext / needs-plaintext-DBus path).
- provider: copilotCLILogin falls back to each running distro's
~/.copilot/config.json (plaintext tokens only; a distro's keyring is
out of reach), through a new CopilotWSLHomes hook, cached 20s since
it is read over WSL's file share. The read itself moved into
copilotCLILoginIn(dir, secret).
- agent: the probe looks for $HOME/.copilot, and a distro that has only
it is kept (wslKept) so its home is known; it makes no agent row.
CopilotWSLHomes lists only running distros: reading a stopped one
would start it.
Run: TestCopilotCLIInWSL (provider) and TestWSLCopilotHome (agent),
both red with the fallback / wslKept broken by hand, green with it;
go test ./internal/agent ./internal/sessions green; both tests also
pass on Windows 11. On the Windows box with a real running distro, a
program built from this commit listed \\wsl.localhost\<distro>\home\<user>
and found the copilot account once a CLI-shaped plaintext config.json
was put in the distro's ~/.copilot (removed after), and none before. No
real Copilot CLI sign-in was used.