Commit Graph
2 Commits
Author SHA1 Message Date
yetone 5f01b9d052 agent tests: the WSL probe test has a timeout(1) where macOS has none (#5570)
TestWSLProbeLooksPastWindowsCommand runs the distro probe in the host's
/bin/sh, and the probe asks a command's version under `timeout 10`.
A distro has timeout (coreutils); macOS 26.2 has none (mote's macOS
27.2 has one), so the ver: line was "sh: timeout: command not found", no version,
and the test was red on every macos-latest run since it landed in
f9a88c4fb (42279775186, 42285312651, 42292490462, 42295916081), not
intermittently. The probe itself is right. The test now puts a stand-in
timeout on PATH when /usr/bin/timeout is missing, and its failure prints
the probe's output.

Run (mote, macOS 27): go test -count=3 -run TestWSLProbe ./internal/agent,
ok, with the injection below and the stand-in renamed to match.
Broken by hand: mote has /usr/bin/timeout, so the probe's `timeout 10`
was renamed `timeoutx 10` in the test: with no stand-in it is red as on
CI (Has bin:pi, Versions empty; out shows "timeoutx: command not
found"), green with the stand-in.
Not tried: a macos-latest (macOS 26) runner itself; this Mac is 26.2 and
has no /usr/bin/timeout, which is the cause.

Fixes #5570
2026-11-07 06:13:32 +08:00
yetone f9a88c4fbe 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)
2026-11-06 23:47:29 +08:00