From 8b2bfe0c5152596f37fbdbe504f2343b4d146c83 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Fri, 30 Oct 2026 00:15:06 -0500 Subject: [PATCH] =?UTF-8?q?test(mcpx/runner):=20Resolve(auto)=20against=20?= =?UTF-8?q?a=20stub=20PATH=20=E2=80=94=20deno/bun/node/none=20(#1911=20col?= =?UTF-8?q?lision=2011)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/mcpx/internal/runner/runtimes_test.go | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/pkgs/mcpx/internal/runner/runtimes_test.go b/pkgs/mcpx/internal/runner/runtimes_test.go index 2ef92e1f25..71575d8074 100644 --- a/pkgs/mcpx/internal/runner/runtimes_test.go +++ b/pkgs/mcpx/internal/runner/runtimes_test.go @@ -58,3 +58,65 @@ func TestNodeRunsNonErasableTypeScript(t *testing.T) { t.Errorf("unexpected output %q, want %q", out, "enum ok 0") } } + +// #1911 collision 11: what `auto` picks was asserted nowhere at the +// resolution level -- the issue's snapshot noted the only test caller just +// needed *a* runtime. These are the four stub-PATH cases the collision +// decision calls for: a PATH holding only a stub deno, only bun, only +// node, and none, with no real runtime involved. Permissions are "all" so +// no profile refusal can skew the pick; the stub executables from +// fakeRuntimes are never executed, only found by LookPath. +func TestAutoResolvesAgainstAStubPath(t *testing.T) { + cases := []struct { + name string + stubs []string + want string + }{ + {"deno only", []string{"deno"}, "deno"}, + {"bun only", []string{"bun"}, "bun"}, + {"node only", []string{"node"}, "node"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + fakeRuntimes(t, c.stubs...) + got, err := Resolve("auto", "all", Setup{}) + if err != nil { + t.Fatalf("auto with only %s on PATH: %v", c.want, err) + } + if got.Name != c.want || got.Kind != c.want { + t.Errorf("auto with only %s on PATH picked %q (kind %q)", c.want, got.Name, got.Kind) + } + if filepath.Base(got.Bin) != c.want { + t.Errorf("auto picked bin %q, want the stub %s", got.Bin, c.want) + } + }) + } + + t.Run("none", func(t *testing.T) { + fakeRuntimes(t) + _, err := Resolve("auto", "all", Setup{}) + if err == nil { + t.Fatal("auto with no runtime on PATH should fail") + } + // The refusal names every runtime it tried, in default order. + for _, want := range []string{"no usable JavaScript runtime", "deno, bun, node"} { + if !strings.Contains(err.Error(), want) { + t.Errorf("auto with no runtime: %q does not mention %q", err, want) + } + } + }) + + // Default order prefers deno when several are present, and a declared + // script.runtimeOrder (Setup.Order) overrides it. + t.Run("order", func(t *testing.T) { + fakeRuntimes(t, "deno", "bun", "node") + got, err := Resolve("auto", "all", Setup{}) + if err != nil || got.Name != "deno" { + t.Errorf("auto default order should pick deno first: %v %v", got, err) + } + got, err = Resolve("auto", "all", Setup{Order: []string{"node", "deno"}}) + if err != nil || got.Name != "node" { + t.Errorf("auto with runtimeOrder node,deno should pick node: %v %v", got, err) + } + }) +}