Files
magpie/internal/agent/wsl_copilot_test.go
T
yetone 6287385f91 perf: Codex's bundled instructions and the WSL probe are built on first use
Two package-level values were built on every launch, `magpie
statusline` on each Claude Code message included, for paths it never
takes:
- codexcat's bundled: json.Unmarshal of the 231 KB
  codex_instructions.json into a map (~0.48 MB). Now sync.OnceValue,
  read the first time a model's instructions are looked up.
- agent's wslProbeScript: the WSL probe's shell script, grown with `s +=`
  over every WSL agent, so each step copied the whole string (~0.5 MB),
  on macOS and Linux too. Now sync.OnceValue, built the first time a
  distro is probed. Callers and tests call it.

Measured on mote, sandbox HOME, t44 (v0.1.3519) against t45 (this):
- GODEBUG=inittrace=1 sum: 3.94 MB -> 2.98 MB
- `magpie statusline`, 3 runs: instructions retired ~156M -> ~137M

Run: go vet ./internal/agent ./internal/codexcat (darwin, GOOS=linux,
GOOS=windows) ok; go test ./internal/codexcat ok, ./internal/agent ok
(290s); root go vet ./... after rebase below.
2026-11-10 13:11:19 +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", ".copilot")
if got := provider.CopilotWSLDirs(); !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.CopilotWSLDirs(); len(got) != 0 {
t.Fatalf("a stopped distro is read: %q", got)
}
}