wsl: a distro's Pi from fnm, mise or an npmrc prefix is found, past a Windows one on PATH

千里不再 on Discord: Pi installed in WSL wasn't detected. The WSL probe
runs `sh -lc`, which reads ~/.profile but not ~/.bashrc, where fnm's
installer puts its PATH, so `command -v pi` missed it and wslbin had no
fnm folder. A Pi not run yet has no ~/.pi either, so nothing found it
(and for fnm users who had run it, its version was lost). Also, WSL
appends Windows' PATH, so a Pi npm installed on Windows answered
`command -v pi` with a /mnt/c path; that stopped the `|| wslbin`
fallback and parseProbe then dropped it as a Windows command (#406), so
the distro's own Pi was hidden.

Now wslcmd takes `command -v` only when it isn't on a Windows drive
(/mnt/X or any drive /proc/mounts lists), else walks PATH past Windows
drives, else wslbin. wslbin gains the folders proc.UserBinDirs has here:
fnm (aliases/default, then the highest version; FNM_DIR,
~/.local/share/fnm, ~/.fnm), mise's installs (highest), ~/.npmrc's
prefix, ~/.npm/bin, cargo, deno, Homebrew. Every WSL kind goes through
it, not only Pi.

Run:
- mote: GOOS=windows/linux/darwin go vet ./internal/agent; go test
  -run "TestWSL|TestOmo|TestPi" ./internal/agent ok. gofmt -l clean.
- wsl-run (magpie-desktop, Ubuntu 24.04): same tests ok.
- Real WSL: in magpie-desktop, a scratch HOME with the real fnm
  installer, `fnm install 22`, `npm i -g @mariozechner/pi-coding-agent`
  (pi 0.73.1), never run. Old probe: no bin:pi. New probe:
  `bin:pi .../fnm/aliases/default/bin/pi`, `ver:pi 0.73.1`, pi@wsl
  listed; a fnm codex was found past a /mnt/c one. Real home still finds
  codex, pi and claude (3.9s). Through proc.CommandContext on Windows
  (win-run) with Detect agents in WSL on, the probe runs (#4872 gates
  only when it is off).

Broken by hand: origin/main's wsl.go with the new tests: all four
subtests of TestWSLProbeFindsNodeManagersBins and
TestWSLProbeLooksPastWindowsCommand red.

Not tried: the reporter's own install (method unknown; fnm with a
never-run Pi is the case reproduced). Asking bash -i for ~/.bashrc's
PATH was tried and dropped: under timeout(1) an interactive bash stops
itself (state T) on WSL and outlived its timeout.

Reported-by: 千里不再 (Discord)
This commit is contained in:
yetone
2026-11-06 23:47:29 +08:00
parent 1fd0bb9670
commit f9a88c4fbe
8 changed files with 146 additions and 10 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ something else shows up as drift.
| Codex instructions | Each magpie model's entry in Codex's catalog carries the instructions official Codex sends that model, Codex's own text word for word; magpie writes none of its own and never changes the identity line (`codexcat.officialFor`). The model's slug (the id's last path segment, lowercased) is matched as Codex matches one, by the longest prefix of an official slug (`longestPrefix`; `auto/gpt-6.1-sol` takes gpt-6.1-sol's, `s2a/openai/gpt-6-luna-2026-09-14` gpt-6-luna's): first against the entries the user's ChatGPT account handed this Codex (`CacheEntries`, models_cache.json), whose `base_instructions` (else `model_messages.instructions_template`) and `model_messages` go over as sent; then against Codex's bundled catalog (`codex_instructions.json`, each model's `instructions_template` from openai/codex rust-v0.166.0's models-manager/models.json), the text only, as an older Codex may not read that release's `model_messages`. Any other model, and a routing group (`group/`), which may hand a turn to any model, takes Codex's prompt for a model it doesn't know (`Prompt`, models-manager/prompt.md), which is what official Codex sends it (`model_info_from_slug`). An entry Codex was handed with no `base_instructions` (`ownEntry`) takes its `model_messages.instructions_template`, else `Official`, and magpie's own ChatGPT-backend requests fall back to `Official` too (`codexInstructions` in internal/provider). Until 11-01 every third-party model was handed gpt-5.2-codex_prompt.md ("You are Codex, based on GPT-5"), so a magpie GPT-6 model ran on a GPT-5.2-era prompt (#3759, #4008, #4783). The Codex files are in testdata (`testdata/codex-rust-v0.166.0`), and `TestBundledIsCodexOwn` fails when the embedded copies differ from them; on a new Codex release copy its two files there and rebuild `codex_instructions.json`. Real Codex 0.166 against a capturing gateway sends the official text as its first developer message for a GPT-6 model and prompt.md for DeepSeek. `TestThirdPartyModelsTakeCodexOwnInstructions`, `TestThirdPartyModelsTakeCachedEntry`, `TestOwnEntryInstructions`. Not read: the bundled catalog inside the user's installed Codex binary. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
| Codex: DeepSeek models | A DeepSeek model's entry (`codexcat.deepSeek`: deepseek-v4*, -flash, -pro, -chat, -reasoner after any provider or relay prefix; not a routing group, not a distill) takes what DeepSeek's own Codex setup (cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh, its models.json) says of its models: `shell_type` `shell_command` (Codex 0.165 reads it as `unified_exec`, its only shell; older Codex had a one-shot `shell_command` tool), `support_verbosity` with `default_verbosity` low, `default_reasoning_summary` none (no `reasoning.summary` sent), `multi_agent_version` v2, and `supports_image_detail_original` on a model whose entry takes images. Not taken: its `base_instructions`/`model_messages` (magpie never rewrites a Codex prompt), its `auto_compact_token_limit` null (magpie's 272K default stays, from e950eb080's DeepSeek latency report; Full window or the model's Compact at gives the whole window), `supports_search_tool` false on v4-pro (#258), its reasoning levels (the provider's). `default_reasoning_summary` is tagged `keep:"unset"`, so a value the user put in another model's entry stays (`Keep`). Other vendors' entries are unchanged. `TestCodexCatalogDeepSeekAsDeepSeekSays`, `TestCodexCatalogKeepsUsersSummary`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
| Named omp profiles | omp keeps a profile's settings under `~/.omp/profiles/<name>` (or under `PI_CONFIG_DIR`), each with its own `config.yml` and `models.yml`. Every such profile is an agent of its own — `omp#<name>` on Windows, `omp#<name>@wsl:<distro>` in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (`ListsFor`), and the default `omp` row is the folder `ompDir`/`ompIn` already pick, so an `OMP_PROFILE` that row is already pointed at is not listed twice. A name omp refuses is not a row: `default`, a trailing dot, or a Windows reserved device name (`aux`, `nul`, `com1`, `lpt9.x`, `con.work`), on every platform (`ompProfileOK`). A distro's profile names come from its probe and are kept in `wsl.json`; a stopped distro is never started to list them, its profile rows showing what was last seen (`asleep`). | [`omp.go`](../../internal/agent/omp.go), [`wsl.go`](../../internal/agent/wsl.go) |
| WSL twins | On Windows each running distro is probed once, without starting a stopped one. The `wslKinds` agents found there become agents of their own, `<id>@wsl:<distro>`, edited through `\\wsl.localhost\<distro>`. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps `~/.gemini` too. Antigravity CLI is found by its own `~/.gemini/antigravity-cli` or its `agy` command (mimi001234 on Discord). Goose is found by its folder alone, because a `goose` command can be pressly's migration tool. Reasonix also needs the version its command gives (`accept`), because the old npm client is named `reasonix` too. The gateway address and key follow the distro's networking: mirrored or NAT (`place`, `keyAt`). Under NAT the key is the gateway's WSL key (`gateway.WSLKey`, `-<agent>` after it where the agent's key names it), sharing on or off; the gateway listens at that address itself (gateway-routing's WSL under NAT). `ListsFor` keeps a twin's model picks under the Windows twin's id (#927). With Settings' Detect agents in WSL off (`NoWSLAgents`, #1264) magpie starts no wsl.exe at all: `proc.Command`, `CommandContext` and `ProbeContext` refuse one by any name or path with `proc.ErrWSLOff` (`wslOff` in [`proc/wsl.go`](../../internal/proc/wsl.go)), where every command magpie runs is made, so a path past agent's and wslrun's own gates (a request's Claude Code stand-in and classifier, #4872: on a computer without WSL each ask put up Windows' install window) asks nothing either (`TestWSLOffStartsNoWSL`, `TestWSLRunnerRefusedWhenOff`, `TestRunRefusedWhenOff`, `TestWSLStandInAsksNothingWhenOff`). | [`wsl.go`](../../internal/agent/wsl.go), [`gatewaykey.go`](../../internal/agent/gatewaykey.go), [`proc/wsl.go`](../../internal/proc/wsl.go) |
| WSL twins | On Windows each running distro is probed once, without starting a stopped one. The `wslKinds` agents found there become agents of their own, `<id>@wsl:<distro>`, edited through `\\wsl.localhost\<distro>`. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). The probe runs `sh -l`, which reads `~/.profile` but not `~/.bashrc`, so a command off its PATH is looked for where Node's managers and installers keep one, as `proc.UserBinDirs` does here (`wslbin`): bun, `~/.local/bin`, volta, pnpm, nvm's default then the highest, fnm's default then the highest (`FNM_DIR`, `~/.local/share/fnm`, `~/.fnm`), mise's installs and shims, asdf, `~/.npmrc`'s prefix, cargo, deno and Homebrew (千里不再 on Discord: a Pi from fnm, not run yet so with no `~/.pi`, wasn't found). One on a Windows drive, which WSL's PATH reaches first when the distro's isn't on it, is looked past rather than taken as the only one (`wslcmd`, `wslwin`; `TestWSLProbeFindsNodeManagersBins`, `TestWSLProbeLooksPastWindowsCommand`). The shell isn't asked interactively for `~/.bashrc`'s PATH: under `timeout` such a bash stops itself on WSL and outlives the timeout. Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps `~/.gemini` too. Antigravity CLI is found by its own `~/.gemini/antigravity-cli` or its `agy` command (mimi001234 on Discord). Goose is found by its folder alone, because a `goose` command can be pressly's migration tool. Reasonix also needs the version its command gives (`accept`), because the old npm client is named `reasonix` too. The gateway address and key follow the distro's networking: mirrored or NAT (`place`, `keyAt`). Under NAT the key is the gateway's WSL key (`gateway.WSLKey`, `-<agent>` after it where the agent's key names it), sharing on or off; the gateway listens at that address itself (gateway-routing's WSL under NAT). `ListsFor` keeps a twin's model picks under the Windows twin's id (#927). With Settings' Detect agents in WSL off (`NoWSLAgents`, #1264) magpie starts no wsl.exe at all: `proc.Command`, `CommandContext` and `ProbeContext` refuse one by any name or path with `proc.ErrWSLOff` (`wslOff` in [`proc/wsl.go`](../../internal/proc/wsl.go)), where every command magpie runs is made, so a path past agent's and wslrun's own gates (a request's Claude Code stand-in and classifier, #4872: on a computer without WSL each ask put up Windows' install window) asks nothing either (`TestWSLOffStartsNoWSL`, `TestWSLRunnerRefusedWhenOff`, `TestRunRefusedWhenOff`, `TestWSLStandInAsksNothingWhenOff`). | [`wsl.go`](../../internal/agent/wsl.go), [`gatewaykey.go`](../../internal/agent/gatewaykey.go), [`proc/wsl.go`](../../internal/proc/wsl.go) |
| WSL folders that are links | Through `\\wsl.localhost` Windows can't follow a link the distro has: with `~/.codex` a link to `/mnt/c/Users/<user>/.codex`, a mkdir of it says it exists and nothing below it can be made, written, read or listed (#4502, linusxiong). The probe asks `readlink -f` there where each agent folder, its `skills` and the folders beside them lead (`wslLinkPaths`, `distro.Links`; a `$HOME` that is itself through a link is left as it was) and which drive each Windows mount is (`distro.Drives`). `distro.open` opens a path at or below a link where it leads: on a Windows drive the drive's own path (`C:\Users\<user>\.codex`), elsewhere in the distro through its root again; `native` spells such a path back through the link for the agent. A link `readlink -f` couldn't resolve is never guessed at: its agent is unreached (`Agent.Unreached`), says why in its notice and refuses each change and sync. Every writer goes through it: the agents' own files (`place.join`, `place.open`), the library's targets (`wslOpen`, a `wsl` problem per agent), RTK (`rtkAt`, `agent.WSLOpen`), the Sessions page's reads (`sessions.WSLHome.Open`) and the Copilot CLI's sign-in (`provider.CopilotWSLDirs`). Links deeper than the probed paths aren't resolved (`TestWSLOpenThroughLinks`, `TestWSLAgentFolderIsALink`, `TestWSLAgentFolderLinkUnresolved`, `TestWSLProbeLinks`, `TestWSLFolderIsALinkToC`, `TestRTKWSLFolderIsALink`). | [`wsl.go`](../../internal/agent/wsl.go), [`targets.go`](../../internal/library/targets.go), [`rtk_wsl.go`](../../internal/library/rtk_wsl.go) |
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings.<model>.autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`. Where Codex compacts, and Claude Code wherever magpie's own window is what it runs at, is one value with Long conversations in the agents' settings sheet (`settings.CompactAt`/`FullContext`, source `long`; 7eleven on Discord): the card reads it, Use sets it through `provider.SetCompactAt`, and Sync writes it into each agent's config as it does for the sheet; the note says it is Long conversations, shared by Codex and Claude Code (`compact-one-value.test.cjs`). The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated tokens against the setting now (fewer or more, the setting itself marked "Your setting now", hayden4608 on Discord), "Fewest tokens" beside the leanest, and about how many compactions it would have made (`Point.compacts`, from the same replay), and puts the one picked in like Use (#1860). An agent whose files time its compactions also has their wait weighed (HirotaNagai on X): Claude Code's `compact_boundary` line says `compactMetadata.durationMs`, which `sessions` puts on the first call after it, and Codex compacts by a call of its own (the record a `compacted` line names, in rollouts since 2026-09), whose time is the compaction's (`Call.Compact`; an older rollout's compaction has no call and stays untimed). With 3 or more timed for a model (`minTimed`), `Facts.took` is their median seconds, each window says its wait (`Point.wait`, its compactions × `took`), and the row says what a compaction took, the wait at the advice against the window now, and the cheaper window the advice passed over for waiting longer (`Compaction.cheapest`, `wait_cheapest`) when it saves 3% or more; the advice is labelled "Tokens + wait", its caveat says tokens and waiting only, and the picker says each window's wait with "Fewest tokens" on the cheapest (`context-tune.test.cjs`). An agent or model with fewer timed reads and is advised as before. | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
| Agents a plugin adds | A plugin's `magpie.agent` module (or a `*.agent.js` file) says where an agent magpie has no setup of its own keeps its model (`config`, `format`, `model`, `prefix`), and its `connect` returns the other keys to write. One with no `model` is connect only (#2374): its one field is `provider`, magpie or nothing, as an app whose one setting is magpie as its provider; `connect` is called without a model, must return keys, and is called again on a catalog change (`Sync`); `ListsModels` is set, so its list is the models picked for it. One whose agent keeps the model a new session starts on in a file apart from its provider list says so with `startup` (`config`, `format`, `model`, and `keys` written beside the model as they are) and has no `model`: PiG keeps its providers in `models.json` and `defaultProvider`/`defaultModel` in `settings.json` (str_ on Discord: its row only listed models, where Pi's picks the one it starts on). Its field is `model` again; picking one of magpie's writes `connect`'s keys into `config` and the model and `startup.keys` into `startup.config`, each file stashed under its own `plugin:<id>:<path>` (the startup one marked by its first string key, so a model picked in the agent among magpie's, with `defaultProvider` still `magpie`, reads as magpie's). A model of the agent's own picked in it while `connect`'s keys are still in `config` is `Beside`: connected, not drift, and Disconnect leaves that pick and takes the rest out. A magpie without `startup` reads the same module as connect only (`TestPluggedStartupModel`, `TestPluggedStartupOwnPickKept`, `TestPluggedStartupRestoreGone`). `agentplug` compiles each in moejs (via `jsmod`, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. `plugged` makes each an `Agent` with `Plugin` set, listed after magpie's own; an id one of magpie's own agents has is refused (`PluginErrors`). `connect` is given each model as `magpieModels` builds it, with `/v1/models`' `native_endpoints` (`provider.NativeEndpoints`; a routing group's, `provider.GroupEndpoints`, the APIs every member relays as it is; carried as `catalog.Model.Endpoints`) and `pricing` (`catalog.OpenRouterPricing` of the same `EntryPricer` price), each left out when not known ([`plugged_connect_facts_test.go`](../../internal/agent/plugged_connect_facts_test.go)). | [`agentplug.go`](../../internal/agentplug/agentplug.go), [`plugged.go`](../../internal/agent/plugged.go) |
+1 -1
View File
@@ -114,7 +114,7 @@ func TestOmoDir(t *testing.T) {
// The WSL probe asks after OmO too.
func TestWSLProbeFindsOmo(t *testing.T) {
for _, want := range []string{`[ -d "$HOME/.omo" ] && echo dir:.omo`, `p=$(command -v omo 2>/dev/null || wslbin omo) && echo "bin:omo $p"`} {
for _, want := range []string{`[ -d "$HOME/.omo" ] && echo dir:.omo`, `p=$(wslcmd omo) && echo "bin:omo $p"`} {
if !strings.Contains(wslProbeScript, want) {
t.Errorf("probe lacks %q", want)
}
+23 -2
View File
@@ -1641,18 +1641,39 @@ const wslProbeVersion = 2
// highest first. The glob this replaced took them in name order, so a
// command under v18 was found before the default v22's, and v9's after
// both (as proc.UserPath did on a Mac or Linux, 9f407cafa).
//
// The folders are those of proc.UserBinDirs: fnm's default and then its
// versions, mise's installs, ~/.npmrc's prefix and Homebrew's among them
// (千里不再 on Discord: a WSL Pi from fnm, not run yet so with no ~/.pi,
// wasn't found). The shell isn't asked interactively for the PATH ~/.bashrc
// builds: under timeout(1) an interactive bash stops itself on the
// terminal (state T) and outlived its timeout on WSL (Ubuntu 24.04).
//
// A command on Windows' drives isn't the distro's (parseProbe), so one
// there is looked past (wslwin): WSL puts Windows' PATH on the distro's,
// and a Pi npm installed on Windows hid the distro's own from wslbin.
var wslProbeScript = func() string {
s := `nv="${NVM_DIR:-$HOME/.nvm}"; nd=; [ -s "$nv/nvm.sh" ] && command -v bash >/dev/null 2>&1 && nd=$(NVM_DIR="$nv" timeout 10 bash -c '. "$NVM_DIR/nvm.sh" --no-use >/dev/null 2>&1; nvm_version default 2>/dev/null' </dev/null 2>/dev/null); ` +
// Windows' drives, as /proc/mounts has them (C:\ written C:\134)
`wm=$(awk '$1 ~ /^[A-Za-z]:/ {print $2}' /proc/mounts 2>/dev/null); ` +
`wslwin() { case "$1" in /mnt/[A-Za-z]/*) return 0;; esac; for m in $wm; do case "$1/" in "$m"/*) return 0;; esac; done; return 1; }; ` +
`inpath() { o=$IFS; IFS=:; r=; for d in $2; do case "$d" in /*) wslwin "$d" || { [ -f "$d/$1" ] && [ -x "$d/$1" ] && { r="$d/$1"; break; }; };; esac; done; IFS=$o; [ -n "$r" ] && echo "$r"; }; ` +
`np=$(sed -n 's/^[[:space:]]*prefix[[:space:]]*=[[:space:]]*//p' "$HOME/.npmrc" 2>/dev/null | head -n1 | tr -d "\"'\r"); case "$np" in "~/"*) np="$HOME/${np#??}";; /*) ;; *) np=;; esac; ` +
`fr=; for r in "$FNM_DIR" "${XDG_DATA_HOME:-$HOME/.local/share}/fnm" "$HOME/.fnm"; do case "$r" in /*) [ -d "$r/node-versions" ] && { fr=$r; break; };; esac; done; ` +
`vs() { ls "$1" 2>/dev/null | sed 's/^v*\(.*\)$/\1 &/' | sort -t. -k1,1nr -k2,2nr -k3,3nr | cut -d' ' -f2; }; ` +
`wslbin() { for d in "$HOME/.bun/bin" "$HOME/.local/bin" "$HOME/.npm-global/bin" "$HOME/.volta/bin" "$HOME/.local/share/pnpm"; do [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; ` +
`for v in $nd $(ls "$nv/versions/node" 2>/dev/null | sort -t. -k1.2,1nr -k2,2nr -k3,3nr); do d="$nv/versions/node/$v/bin"; [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; ` +
`for d in "$HOME/.local/share/mise/shims" "$HOME/.asdf/shims"; do [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; return 1; }; `
`if [ -n "$fr" ]; then for d in "$fr/aliases/default/bin" $(vs "$fr/node-versions" | sed "s|.*|$fr/node-versions/&/installation/bin|"); do [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; fi; ` +
`for d in $(vs "$HOME/.local/share/mise/installs/node" | sed "s|.*|$HOME/.local/share/mise/installs/node/&/bin|"); do [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; ` +
`for d in "$HOME/.local/share/mise/shims" "$HOME/.asdf/shims" "$HOME/.npm/bin" ${np:+"$np/bin"} "$HOME/.cargo/bin" "$HOME/.deno/bin" /home/linuxbrew/.linuxbrew/bin "$HOME/.linuxbrew/bin"; do [ -x "$d/$1" ] && { echo "$d/$1"; return 0; }; done; return 1; }; ` +
`wslcmd() { p=$(command -v "$1" 2>/dev/null) && case "$p" in /*) wslwin "$p" || { echo "$p"; return 0; };; esac; inpath "$1" "$PATH" || wslbin "$1"; }; `
s += `echo "home:$HOME"; `
for _, k := range wslKinds {
if k.dir != "" {
s += `[ -d "$HOME/` + k.dir + `" ] && echo dir:` + k.dir + `; `
}
if k.bin != "" {
s += `p=$(command -v ` + k.bin + ` 2>/dev/null || wslbin ` + k.bin + `) && echo "bin:` + k.bin + ` $p"`
s += `p=$(wslcmd ` + k.bin + `) && echo "bin:` + k.bin + ` $p"`
if k.version {
// not one on Windows' drives (WSL's /mnt/c), which isn't the distro's
s += ` && case "$p" in /mnt/*) ;; *) echo "ver:` + k.id + ` $(PATH="${p%/*}:$PATH" timeout 10 "$p" --version </dev/null 2>&1 | head -n1)";; esac`
+1 -1
View File
@@ -19,7 +19,7 @@ import (
func TestWSLAgyFound(t *testing.T) {
k := wslKindOf("agy")
if !strings.Contains(wslProbeScript, `[ -d "$HOME/.gemini/antigravity-cli" ] && echo dir:.gemini/antigravity-cli; `) ||
!strings.Contains(wslProbeScript, `command -v agy `) {
!strings.Contains(wslProbeScript, `p=$(wslcmd agy) `) {
t.Fatal("the probe doesn't ask after agy")
}
for _, p := range []string{"dir:.gemini/antigravity-cli\n", "bin:agy /home/me/.local/bin/agy\n"} {
+1 -1
View File
@@ -46,7 +46,7 @@ func noOwnClaude(t *testing.T) {
// The probe asks after Claude Code as after Codex and Pi, and reads what
// it says.
func TestWSLProbeFindsClaude(t *testing.T) {
for _, want := range []string{`[ -d "$HOME/.claude" ] && echo dir:.claude`, `p=$(command -v claude 2>/dev/null || wslbin claude) && echo "bin:claude $p"`,
for _, want := range []string{`[ -d "$HOME/.claude" ] && echo dir:.claude`, `p=$(wslcmd claude) && echo "bin:claude $p"`,
`[ -d "$HOME/.pi" ] && echo dir:.pi`, `[ -d "$HOME/.codex" ] && echo dir:.codex`} {
if !strings.Contains(wslProbeScript, want) {
t.Errorf("probe lacks %q:\n%s", want, wslProbeScript)
+2 -2
View File
@@ -88,7 +88,7 @@ func TestWSLProbeFindsMoreAgents(t *testing.T) {
if k.dir != "" && !strings.HasPrefix(c.file, k.dir+"/") {
t.Errorf("%s: its file %s isn't under %s", c.id, c.file, k.dir)
}
if k.bin != "" && !strings.Contains(wslProbeScript, `command -v `+k.bin+` `) {
if k.bin != "" && !strings.Contains(wslProbeScript, `p=$(wslcmd `+k.bin+`) `) {
t.Errorf("%s: probe lacks its command %s", c.id, k.bin)
}
if p, _, _ := wslFinds(k); k.dir != "" || k.version {
@@ -103,7 +103,7 @@ func TestWSLProbeFindsMoreAgents(t *testing.T) {
}
}
for _, bin := range []string{"fx", "grok", "goose"} {
if strings.Contains(wslProbeScript, `command -v `+bin+` `) {
if strings.Contains(wslProbeScript, `wslcmd `+bin+`)`) {
t.Errorf("probe takes any %s command for the agent", bin)
}
}
+115
View File
@@ -0,0 +1,115 @@
package agent
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/yetone/magpie/internal/testenv"
)
// The WSL probe finds a command in the folders Node's managers keep one
// in, as proc.UserBinDirs does here: sh -l reads only ~/.profile, and
// fnm's installer puts its PATH in ~/.bashrc. 千里不再 on Discord: a WSL
// Pi from fnm, not run yet (no ~/.pi), wasn't found.
func TestWSLProbeFindsNodeManagersBins(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("the probe runs in a Linux distro")
}
sys := t.TempDir() // PATH: nothing of pi's
for _, c := range []struct {
name string
// lay sets home up and says where pi is
lay func(home string) string
}{
{"fnm's default", func(home string) string {
fnm := filepath.Join(home, ".local", "share", "fnm")
for _, v := range []string{"v18.20.4", "v22.23.4"} {
os.MkdirAll(filepath.Join(fnm, "node-versions", v, "installation", "bin"), 0o755)
}
os.MkdirAll(filepath.Join(fnm, "aliases"), 0o755)
os.Symlink(filepath.Join(fnm, "node-versions", "v18.20.4", "installation"), filepath.Join(fnm, "aliases", "default"))
for _, v := range []string{"v18.20.4", "v22.23.4"} {
testenv.Program(t, filepath.Join(fnm, "node-versions", v, "installation", "bin", "pi"), "#!/bin/sh\n")
}
return filepath.Join(fnm, "aliases", "default", "bin")
}},
{"fnm with no default: the highest", func(home string) string {
fnm := filepath.Join(home, ".local", "share", "fnm")
for _, v := range []string{"v9.11.2", "v22.23.4", "v18.20.4"} {
d := filepath.Join(fnm, "node-versions", v, "installation", "bin")
os.MkdirAll(d, 0o755)
testenv.Program(t, filepath.Join(d, "pi"), "#!/bin/sh\n")
}
return filepath.Join(fnm, "node-versions", "v22.23.4", "installation", "bin")
}},
{"mise's installs", func(home string) string {
root := filepath.Join(home, ".local", "share", "mise", "installs", "node")
for _, v := range []string{"9.11.2", "22.12.0", "18.20.4"} {
d := filepath.Join(root, v, "bin")
os.MkdirAll(d, 0o755)
testenv.Program(t, filepath.Join(d, "pi"), "#!/bin/sh\n")
}
return filepath.Join(root, "22.12.0", "bin")
}},
{"~/.npmrc's prefix", func(home string) string {
os.WriteFile(filepath.Join(home, ".npmrc"), []byte("registry=https://registry.npmmirror.com\nprefix = \"~/.npm-packages\"\r\n"), 0o644)
return filepath.Join(home, ".npm-packages", "bin")
}},
} {
t.Run(c.name, func(t *testing.T) {
home := t.TempDir()
bin := c.lay(home)
os.MkdirAll(bin, 0o755)
if _, err := os.Stat(filepath.Join(bin, "pi")); err != nil {
testenv.Program(t, filepath.Join(bin, "pi"), "#!/bin/sh\necho 0.73.1\n")
}
cmd := exec.Command("/bin/sh", "-c", wslProbeScript)
cmd.Env = []string{"HOME=" + home, "PATH=" + sys + ":/usr/bin:/bin"}
out, err := cmd.Output()
if err != nil {
t.Fatalf("%v: %s", err, out)
}
if want := "bin:pi " + filepath.Join(bin, "pi") + "\n"; !strings.Contains(string(out), want) {
t.Fatalf("probe said:\n%s\nwant %q", out, want)
}
})
}
}
// A command on Windows' drives isn't the distro's (#406), and it doesn't
// hide the distro's own: WSL puts Windows' PATH on the distro's, so a Pi
// npm installed on Windows was all `command -v pi` found, and the distro's
// Pi from fnm was never looked for.
func TestWSLProbeLooksPastWindowsCommand(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("the probe runs in a Linux distro")
}
home, root := t.TempDir(), t.TempDir()
win := filepath.Join(root, "winc") // Windows' C: as the distro mounts it
winNpm := filepath.Join(win, "Users", "me", "AppData", "Roaming", "npm")
os.MkdirAll(winNpm, 0o755)
testenv.Program(t, filepath.Join(winNpm, "pi"), "#!/bin/sh\n")
mounts := filepath.Join(root, "mounts")
os.WriteFile(mounts, []byte("/dev/sdc / ext4 rw 0 0\nC:\\134 "+win+" 9p rw 0 0\n"), 0o644)
own := filepath.Join(home, ".local", "share", "fnm", "node-versions", "v22.23.4", "installation", "bin")
os.MkdirAll(own, 0o755)
testenv.Program(t, filepath.Join(own, "pi"), "#!/bin/sh\necho 0.73.1\n")
script := strings.ReplaceAll(wslProbeScript, "/proc/mounts", mounts)
cmd := exec.Command("/bin/sh", "-c", script)
cmd.Env = []string{"HOME=" + home, "PATH=/usr/bin:/bin:" + winNpm}
out, err := cmd.Output()
if err != nil {
t.Fatalf("%v: %s", err, out)
}
if want := "bin:pi " + filepath.Join(own, "pi") + "\n"; !strings.Contains(string(out), want) {
t.Fatalf("probe said:\n%s\nwant %q", out, want)
}
if d := parseProbe("U", string(out)); d == nil || !wslKindOf("pi").found(*d) || d.Versions["pi"] != "0.73.1" {
t.Fatalf("parsed: %+v", d)
}
}
+2 -2
View File
@@ -30,8 +30,8 @@ func piDistroHome(t *testing.T, settings string) (root, home string) {
// The probe asks after Pi as after Codex, and reads what it says.
func TestWSLProbeFindsPi(t *testing.T) {
for _, want := range []string{`[ -d "$HOME/.pi" ] && echo dir:.pi`, `p=$(command -v pi 2>/dev/null || wslbin pi) && echo "bin:pi $p"`,
`[ -d "$HOME/.codex" ] && echo dir:.codex`, `p=$(command -v codex 2>/dev/null || wslbin codex) && echo "bin:codex $p"`} {
for _, want := range []string{`[ -d "$HOME/.pi" ] && echo dir:.pi`, `p=$(wslcmd pi) && echo "bin:pi $p"`,
`[ -d "$HOME/.codex" ] && echo dir:.codex`, `p=$(wslcmd codex) && echo "bin:codex $p"`} {
if !strings.Contains(wslProbeScript, want) {
t.Errorf("probe lacks %q:\n%s", want, wslProbeScript)
}