Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions pkgs/mcpx/internal/runner/runtimes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Loading