Files
magpie/internal/agent/wsl_copilot_test.go
T
yetone 31468ad0ed provider, agent: magpie on Windows finds the Copilot CLI signed in inside a running WSL distro (#723, jia2)
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.
2026-10-11 04:00:27 +08:00

37 lines
1.1 KiB
Go

package agent
import (
"path/filepath"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A distro with no agent magpie sets up, only the Copilot CLI signed in
// (#723, jia2), is kept: provider reads the CLI's sign-in in its home
// while it runs, and never once it is stopped.
func TestWSLCopilotHome(t *testing.T) {
syncHome(t)
root := t.TempDir()
if !strings.Contains(wslProbeScript, `[ -d "$HOME/.copilot" ] && echo dir:.copilot; `) {
t.Fatalf("the probe doesn't look for the Copilot CLI's folder:\n%s", wslProbeScript)
}
t.Cleanup(FakeWSL(
map[string]string{"Ubuntu": "home:/home/jia\ndir:.copilot\n", "Debian": "home:/home/me\n"},
map[string]string{"Ubuntu": root, "Debian": t.TempDir()}))
want := filepath.Join(root, "home", "jia")
if got := provider.CopilotWSLHomes(); !slices.Equal(got, []string{want}) {
t.Fatalf("homes %q, want %q", got, want)
}
if len(wslAgents()) != 0 {
t.Fatalf("the Copilot CLI's folder made an agent row: %v", wslAgents())
}
StopFakeWSL("Ubuntu")
if got := provider.CopilotWSLHomes(); len(got) != 0 {
t.Fatalf("a stopped distro is read: %q", got)
}
}