What changed
- fnm puts its Node on a terminal's PATH from the shell profile
(`fnm env | Invoke-Expression`), never in the registry, so magpie
started from the Start menu had no node: a Library MCP server run by
bare npx was "notfound", and one run by npx.cmd's full path (the
reporter's C:\Users\...\fnm\aliases\default\npx.cmd, alone or under
`cmd /c`) exited 1 with cmd's "'node' is not recognized", since the
package npx fetched runs node by name.
- Windows UserPath (no-op before) adds the folder fnm's default alias
names, after what PATH has. UserBinDirs (FindTool) gets each fnm
Node: the default alias first, then installations newest by number.
- fnm's Windows layout, checked against Schniz/fnm master (config.rs,
directories.rs, version.rs, fs.rs, commands/env.rs): root FNM_DIR,
else etcetera's Windows data_dir\fnm (home\AppData\Roaming, APPDATA),
else legacy ~\.fnm; versions in node-versions\<v>\installation with
node.exe/npx.cmd directly in it (no bin on Windows); aliases\default
a junction to an installation folder; the "system" alias points at
Z:\_fnm_\..., read as none. XDG vars on Windows only move fnm's
multishell links, not its versions. LOCALAPPDATA isn't used for them.
- The shared node-version helpers (nodeVersions, parseNodeVersion,
nodeVersionLess, isDir) and addPath moved from the !windows files to
nodever.go unchanged; fnmWin* there take home/APPDATA/FNM_DIR as
arguments so the tests run them on every OS.
- The Library check (checkStdioAt, this machine only) starts a bare
command PATH lacks from where proc.FindTool finds it and puts that
folder on the child's PATH (stdioProgram, withPath), as the owner's
plan on the issue said. Docs: agent-wiring.md, library.md.
Run
- macOS: go test -count=1 ./internal/proc/ ./internal/library/ ok
(TestNoCommandBypassesProc and the other proc guards included);
gofmt -l clean; go vet GOOS=windows/darwin for proc, library, cli,
daemon; GOOS=linux vet proc, library and (-tags nogui) cli, daemon;
GOOS=windows test binaries for proc and library build.
- Windows box (Win 11 x64), cross-compiled amd64 test binaries:
TestUserPathFnmNode (real junction via mklink /J, npx.cmd that runs
node by name) red on origin/main 4a1cd7765's code ("PATH after
UserPath = [C:\windows\System32], want fnm's default alias"), green
here; TestFnmWin* green.
- Real fnm 1.39.0 + Node v24.22.1 installed into a sandbox
(USERPROFILE/APPDATA under C:\Users\yeton\fnm-2685, no FNM_DIR,
registry PATH without node). A throwaway probe calling UserPath then
library.CheckServer on chrome-devtools-mcp@latest:
4a1cd7765: npx -> notfound; ...\aliases\default\npx.cmd -> exited 1;
cmd /c ...npx.cmd -> exited 1 (the reporter's case).
This commit: all three ok, 32 tools.
- Broken by hand: stdioProgram without FindTool ->
TestStdioProgramFindsWhatPathLacks red; fnmWinBins without the
default alias -> TestFnmWinBins red; Windows UserPath as before ->
TestUserPathFnmNode red (above).
- Windows full proc/library binaries: TestNoCommandBypassesProc,
TestGoneAgentListedToTakeOut, TestCheckMixedServerEachSide,
TestCheckKeepsToolNames and TestRTKNoHookIssuesAreEachAgents fail
the same with 4a1cd7765's binaries run the same way; the guard and
two of them read the source tree, which a binary run outside a
checkout doesn't have; the other two are in #1827.
Not tried
- The desktop GUI on Windows with the reporter's fnm (the probe runs
the same UserPath and CheckServer calls the app does).
- magpie serve/web/tui on Windows don't call UserPath (as on macOS), so
there an absolute npx.cmd still lacks node on PATH; a bare npx is
covered by the check's FindTool.
- Agents magpie starts get the new PATH only from the GUI/daemon.
Refs #2685
Co-authored-by: Edward4226 <234070868+Edward4226@users.noreply.github.com>
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package library
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/proc"
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// #2685: a bare npx the check's PATH lacks is the one a terminal would run
|
|
// (proc.FindTool, the folders a user's tools are installed in, fnm's
|
|
// Nodes on Windows among them), and its folder goes on the child's PATH,
|
|
// where the node it runs by name is. A path, and a name PATH has, are
|
|
// started as they are.
|
|
func TestStdioProgramFindsWhatPathLacks(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("PATH", t.TempDir())
|
|
proc.Forget()
|
|
bin := filepath.Join(home, ".local", "bin")
|
|
name := "magpie-fake-npx"
|
|
file := name
|
|
if runtime.GOOS == "windows" {
|
|
file += ".cmd"
|
|
}
|
|
testenv.Program(t, filepath.Join(bin, file), "#!/bin/sh\necho hi\n")
|
|
prog, found := stdioProgram(name)
|
|
if !strings.EqualFold(prog, filepath.Join(bin, file)) || !strings.EqualFold(found, bin) {
|
|
t.Fatalf("stdioProgram(%q) = %q, %q; want %q found in %q", name, prog, found, filepath.Join(bin, file), bin)
|
|
}
|
|
abs := filepath.Join(home, "elsewhere", file)
|
|
if prog, found := stdioProgram(abs); prog != abs || found != "" {
|
|
t.Fatalf("a path: stdioProgram = %q, %q; want it as it is", prog, found)
|
|
}
|
|
if prog, found := stdioProgram("magpie-no-such-tool"); prog != "magpie-no-such-tool" || found != "" {
|
|
t.Fatalf("nowhere: stdioProgram = %q, %q; want the name, for notfound", prog, found)
|
|
}
|
|
t.Setenv("PATH", bin)
|
|
proc.Forget()
|
|
if prog, found := stdioProgram(name); prog != name || found != "" {
|
|
t.Fatalf("on PATH: stdioProgram = %q, %q; want the name as it is", prog, found)
|
|
}
|
|
}
|
|
|
|
func TestWithPath(t *testing.T) {
|
|
sep := string(os.PathListSeparator)
|
|
key := "PATH"
|
|
if runtime.GOOS == "windows" {
|
|
key = "Path" // as os.Environ spells it there
|
|
}
|
|
got := withPath([]string{"A=1", key + "=x" + sep + "y"}, "z")
|
|
if want := []string{"A=1", key + "=x" + sep + "y" + sep + "z"}; !slices.Equal(got, want) {
|
|
t.Fatalf("withPath = %q, want %q", got, want)
|
|
}
|
|
if got := withPath([]string{"A=1"}, "z"); !slices.Equal(got, []string{"A=1", "PATH=z"}) {
|
|
t.Fatalf("no PATH: withPath = %q", got)
|
|
}
|
|
}
|