From dcbdc277d187183b7258eae442d6276914c56168 Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Sun, 8 Nov 2026 07:08:39 -0600 Subject: [PATCH 1/2] mcpx(testsupport): one parser for MCPX_TEST_REQUIRE, and enforce every listed entry (#6904) require.go and realserver.go parsed MCPX_TEST_REQUIRE with two divergent parsers: RequiredBinaries lower-cased and knew exact names, realRequired did not lower-case and added the realsoftware/real/* spellings. So MCPX_TEST_REQUIRE=RealSoftware demanded a runtime binary named "realsoftware" while demanding no real server at all. - parseRequireList is now the one parser; the label and wildcard rules are stated once there and realRequired uses it. Case is insignificant for binaries and real servers alike. - MissingRequiredBinaries checks every listed entry against PATH, and TestRequiredBinariesAreOnPath fails the suite when one is absent. CI's list names python3, which no test passes to RequireBinary; per-test enforcement covered nothing for it, so a missing python3 narrowed the run silently. Closes #6904 --- pkgs/mcpx/internal/testsupport/realserver.go | 13 +-- pkgs/mcpx/internal/testsupport/require.go | 81 +++++++++++++++++-- .../testsupport/require_suite_test.go | 20 +++++ .../mcpx/internal/testsupport/require_test.go | 50 ++++++++++++ 4 files changed, 147 insertions(+), 17 deletions(-) create mode 100644 pkgs/mcpx/internal/testsupport/require_suite_test.go diff --git a/pkgs/mcpx/internal/testsupport/realserver.go b/pkgs/mcpx/internal/testsupport/realserver.go index 6ff3601dc1..dd7f6d4c9a 100644 --- a/pkgs/mcpx/internal/testsupport/realserver.go +++ b/pkgs/mcpx/internal/testsupport/realserver.go @@ -3,7 +3,6 @@ package testsupport import ( "os" "path/filepath" - "strings" "testing" ) @@ -60,13 +59,9 @@ func realServerPath(dir, name string) (string, bool) { // realRequired reports whether a MCPX_TEST_REQUIRE comma list demands the // named server: an entry naming the server itself, the subset label, or -// the wildcard demands it. +// the wildcard demands it. Case is insignificant; the parsing and the +// label/wildcard rules live in requireList (require.go), the one parser +// for the variable (#6904). func realRequired(requireList, name string) bool { - for _, entry := range strings.Split(requireList, ",") { - switch strings.TrimSpace(entry) { - case name, "realsoftware", "real", "*": - return true - } - } - return false + return parseRequireList(requireList).demandsRealServer(name) } diff --git a/pkgs/mcpx/internal/testsupport/require.go b/pkgs/mcpx/internal/testsupport/require.go index 2ce9413abb..80ef66e666 100644 --- a/pkgs/mcpx/internal/testsupport/require.go +++ b/pkgs/mcpx/internal/testsupport/require.go @@ -3,35 +3,100 @@ package testsupport import ( "os" "os/exec" + "sort" "strings" "testing" ) -// RequiredBinaries returns the external binaries a test run must have, as named by MCPX_TEST_REQUIRE. +// requireList is MCPX_TEST_REQUIRE parsed once (#6904). // -// MCPX_TEST_REQUIRE names the external binaries a test run must have, as a +// MCPX_TEST_REQUIRE names the external things a test run must have, as a // comma-separated list (e.g. MCPX_TEST_REQUIRE=deno,bun,node,python3). +// Runtime binaries and real-software servers share the one variable, so +// there is exactly one parser for it: entries are trimmed and lower-cased, +// and the three non-binary spellings are stated here and nowhere else: +// +// - "realsoftware" and "real" name the real-server subset: every real +// server is demanded. +// - "*" is the wildcard: every real server is demanded. It does not +// demand runtime binaries, which have no wildcard meaning. +// - any other entry names a runtime binary (checked on PATH) and, when a +// real server has the same name, that server too. +// +// Case is insignificant in every position: "RealSoftware", "REALSOFTWARE" +// and "realsoftware" mean the same thing, for binaries and servers alike. +type requireList struct { + binaries map[string]bool // lower-cased runtime binary names demanded + realAll bool // a subset label or the wildcard demands every real server +} + +// parseRequireList is the single parser for MCPX_TEST_REQUIRE. +func parseRequireList(raw string) requireList { + l := requireList{binaries: map[string]bool{}} + for _, entry := range strings.Split(raw, ",") { + switch entry = strings.ToLower(strings.TrimSpace(entry)); entry { + case "": + case "realsoftware", "real", "*": + l.realAll = true + default: + l.binaries[entry] = true + } + } + return l +} + +// demandsBinary reports whether the list names name as a runtime binary. +func (l requireList) demandsBinary(name string) bool { + return l.binaries[strings.ToLower(strings.TrimSpace(name))] +} + +// demandsRealServer reports whether the list demands the named real server: +// an entry naming the server itself, a subset label, or the wildcard. +func (l requireList) demandsRealServer(name string) bool { + return l.realAll || l.demandsBinary(name) +} + +// RequiredBinaries returns the external binaries a test run must have, as +// named by MCPX_TEST_REQUIRE. // // A missing runtime normally skips the tests that need it, which is right // on a laptop and wrong in CI: a leg that skips is a green leg that tested // nothing (developing-today/code#1983, the #35 lesson). CI and container // runs set MCPX_TEST_REQUIRE so a missing required binary fails the test // instead of silently narrowing what the suite covered. +// +// The real-server subset labels and the wildcard are not binaries and are +// not returned here; see requireList for the rules. func RequiredBinaries() map[string]bool { - out := map[string]bool{} - for _, name := range strings.Split(os.Getenv("MCPX_TEST_REQUIRE"), ",") { - if name = strings.ToLower(strings.TrimSpace(name)); name != "" { - out[name] = true - } + parsed := parseRequireList(os.Getenv("MCPX_TEST_REQUIRE")) + out := make(map[string]bool, len(parsed.binaries)) + for name := range parsed.binaries { + out[name] = true } return out } +// MissingRequiredBinaries returns the required binaries that are not on +// PATH, sorted. It is the suite-level check (#6904): per-test enforcement +// only covers entries that some test happens to pass to RequireBinary, so +// an entry with no consumer -- python3 in CI's list -- would otherwise be +// enforced by nothing and narrow the run silently. +func MissingRequiredBinaries() []string { + var missing []string + for name := range RequiredBinaries() { + if _, err := exec.LookPath(name); err != nil { + missing = append(missing, name) + } + } + sort.Strings(missing) + return missing +} + // MissingRequired reports whether name is missing from PATH while // MCPX_TEST_REQUIRE names it -- the one case where a test that cannot run // must fail rather than skip or continue past the gap. func MissingRequired(name string) bool { - if !RequiredBinaries()[strings.ToLower(name)] { + if !parseRequireList(os.Getenv("MCPX_TEST_REQUIRE")).demandsBinary(name) { return false } _, err := exec.LookPath(name) diff --git a/pkgs/mcpx/internal/testsupport/require_suite_test.go b/pkgs/mcpx/internal/testsupport/require_suite_test.go new file mode 100644 index 0000000000..95a07c78c8 --- /dev/null +++ b/pkgs/mcpx/internal/testsupport/require_suite_test.go @@ -0,0 +1,20 @@ +package testsupport + +import ( + "strings" + "testing" +) + +// TestRequiredBinariesAreOnPath is the suite-level enforcement for +// MCPX_TEST_REQUIRE (#6904). +// +// Per-test enforcement only covers an entry that some test passes to +// RequireBinary: an entry with no consumer -- python3 in CI's list -- was +// checked by nothing, so a missing python3 narrowed the run silently. +// This test walks the whole list, so every entry in CI's list is enforced +// even when no individual test names it. +func TestRequiredBinariesAreOnPath(t *testing.T) { + if missing := MissingRequiredBinaries(); len(missing) > 0 { + t.Fatalf("MCPX_TEST_REQUIRE lists binaries that are not on PATH: %s", strings.Join(missing, ", ")) + } +} diff --git a/pkgs/mcpx/internal/testsupport/require_test.go b/pkgs/mcpx/internal/testsupport/require_test.go index 72fe79a10a..c8d945e2b9 100644 --- a/pkgs/mcpx/internal/testsupport/require_test.go +++ b/pkgs/mcpx/internal/testsupport/require_test.go @@ -88,3 +88,53 @@ func TestMissingRequired(t *testing.T) { t.Error("with MCPX_TEST_REQUIRE unset, nothing is missing-required") } } + +// TestRequireListCaseIsInsignificantEverywhere pins #6904: the one parser +// lower-cases every entry, so a spelling that works for a runtime binary +// means the same thing for a real server. Before the shared parser, +// MCPX_TEST_REQUIRE=RealSoftware demanded a binary named "realsoftware" +// (failing a missing runtime) while demanding no real server at all. +func TestRequireListCaseIsInsignificantEverywhere(t *testing.T) { + for _, raw := range []string{"RealSoftware", "REALSOFTWARE", "realsoftware", " Real , * "} { + parsed := parseRequireList(raw) + if !parsed.demandsRealServer("mcp-server-time") { + t.Errorf("%q should demand every real server", raw) + } + } + for _, tc := range []struct{ raw, binary string }{{"NODE", "node"}, {" Node ,BUN ", "node"}, {" Node ,BUN ", "bun"}} { + if !parseRequireList(tc.raw).demandsBinary(tc.binary) { + t.Errorf("%q should demand %q", tc.raw, tc.binary) + } + } + if got := parseRequireList("RealSoftware"); got.demandsBinary("realsoftware") { + t.Error("a subset label is not a runtime binary name") + } + if got := parseRequireList("*"); got.demandsBinary("*") { + t.Error("the wildcard is not a runtime binary name") + } +} + +// TestRequiredBinariesExcludesLabelsAndWildcard pins that the label and +// wildcard spellings never leak into the PATH check as binary names. +func TestRequiredBinariesExcludesLabelsAndWildcard(t *testing.T) { + t.Setenv("MCPX_TEST_REQUIRE", "realsoftware,real,*,deno") + got := RequiredBinaries() + if len(got) != 1 || !got["deno"] { + t.Errorf("want only deno as a binary, got %v", got) + } +} + +// TestMissingRequiredBinariesIsTheSuiteLevelCheck pins the enforcement +// that #6904 found missing: every listed binary is checked against PATH, +// whether or not a test happens to pass it to RequireBinary. +func TestMissingRequiredBinariesIsTheSuiteLevelCheck(t *testing.T) { + t.Setenv("MCPX_TEST_REQUIRE", "go,mcpx-no-such-binary-5584,realsoftware") + got := MissingRequiredBinaries() + if len(got) != 1 || got[0] != "mcpx-no-such-binary-5584" { + t.Errorf("want the absent binary named and the present one not, got %v", got) + } + t.Setenv("MCPX_TEST_REQUIRE", "") + if got := MissingRequiredBinaries(); len(got) != 0 { + t.Errorf("with MCPX_TEST_REQUIRE unset nothing is missing, got %v", got) + } +} From bed8f2734c4cab3dfc9957ddab597a3ad077b0a3 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Tue, 10 Nov 2026 15:20:30 -0600 Subject: [PATCH 2/2] mcpx(testsupport): suite check honors real-server resolution from MCPX_REAL_SERVERS_DIR (#6904) --- pkgs/mcpx/internal/testsupport/require.go | 33 +++++++++++++++---- .../testsupport/require_suite_test.go | 2 +- .../mcpx/internal/testsupport/require_test.go | 21 ++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/pkgs/mcpx/internal/testsupport/require.go b/pkgs/mcpx/internal/testsupport/require.go index 80ef66e666..17f1d84bce 100644 --- a/pkgs/mcpx/internal/testsupport/require.go +++ b/pkgs/mcpx/internal/testsupport/require.go @@ -76,15 +76,21 @@ func RequiredBinaries() map[string]bool { return out } -// MissingRequiredBinaries returns the required binaries that are not on -// PATH, sorted. It is the suite-level check (#6904): per-test enforcement -// only covers entries that some test happens to pass to RequireBinary, so -// an entry with no consumer -- python3 in CI's list -- would otherwise be -// enforced by nothing and narrow the run silently. +// MissingRequiredBinaries returns the required entries that are not +// available, sorted. It is the suite-level check (#6904): per-test +// enforcement only covers entries that some test happens to pass to +// RequireBinary, so an entry with no consumer -- python3 in CI's list -- +// would otherwise be enforced by nothing and narrow the run silently. +// +// An entry is available when it is on PATH, or when it names a real +// server that resolves under MCPX_REAL_SERVERS_DIR: entries name real +// servers as well as runtime binaries (see requireList), and RealServer +// resolves those from the configured directory, not from PATH, so +// demanding PATH presence for them would reject a valid configuration. func MissingRequiredBinaries() []string { var missing []string for name := range RequiredBinaries() { - if _, err := exec.LookPath(name); err != nil { + if !requiredEntryAvailable(name) { missing = append(missing, name) } } @@ -92,6 +98,21 @@ func MissingRequiredBinaries() []string { return missing } +// requiredEntryAvailable reports whether a required entry can be +// satisfied in this environment: on PATH as a runtime binary, or under +// MCPX_REAL_SERVERS_DIR as a real server (realServerPath's layouts). +func requiredEntryAvailable(name string) bool { + if _, err := exec.LookPath(name); err == nil { + return true + } + if dir := os.Getenv("MCPX_REAL_SERVERS_DIR"); dir != "" { + if _, ok := realServerPath(dir, name); ok { + return true + } + } + return false +} + // MissingRequired reports whether name is missing from PATH while // MCPX_TEST_REQUIRE names it -- the one case where a test that cannot run // must fail rather than skip or continue past the gap. diff --git a/pkgs/mcpx/internal/testsupport/require_suite_test.go b/pkgs/mcpx/internal/testsupport/require_suite_test.go index 95a07c78c8..3efdb9d4a9 100644 --- a/pkgs/mcpx/internal/testsupport/require_suite_test.go +++ b/pkgs/mcpx/internal/testsupport/require_suite_test.go @@ -15,6 +15,6 @@ import ( // even when no individual test names it. func TestRequiredBinariesAreOnPath(t *testing.T) { if missing := MissingRequiredBinaries(); len(missing) > 0 { - t.Fatalf("MCPX_TEST_REQUIRE lists binaries that are not on PATH: %s", strings.Join(missing, ", ")) + t.Fatalf("MCPX_TEST_REQUIRE lists entries that are not available (on PATH or under MCPX_REAL_SERVERS_DIR): %s", strings.Join(missing, ", ")) } } diff --git a/pkgs/mcpx/internal/testsupport/require_test.go b/pkgs/mcpx/internal/testsupport/require_test.go index c8d945e2b9..e0002793fe 100644 --- a/pkgs/mcpx/internal/testsupport/require_test.go +++ b/pkgs/mcpx/internal/testsupport/require_test.go @@ -1,6 +1,7 @@ package testsupport import ( + "path/filepath" "strings" "testing" ) @@ -138,3 +139,23 @@ func TestMissingRequiredBinariesIsTheSuiteLevelCheck(t *testing.T) { t.Errorf("with MCPX_TEST_REQUIRE unset nothing is missing, got %v", got) } } + +// TestMissingRequiredBinariesHonorsRealServersDir pins the other half of +// the availability rule: an entry naming a real server is satisfied by +// the server resolving under MCPX_REAL_SERVERS_DIR, because RealServer +// looks there, not on PATH. Only an entry available in neither place is +// missing. +func TestMissingRequiredBinariesHonorsRealServersDir(t *testing.T) { + dir := t.TempDir() + writeExecutable(t, filepath.Join(dir, "bin", "mcp-server-time")) + t.Setenv("MCPX_REAL_SERVERS_DIR", dir) + t.Setenv("MCPX_TEST_REQUIRE", "mcp-server-time,mcp-server-absent-5584") + got := MissingRequiredBinaries() + if len(got) != 1 || got[0] != "mcp-server-absent-5584" { + t.Errorf("want only the server available in neither place named, got %v", got) + } + t.Setenv("MCPX_REAL_SERVERS_DIR", "") + if got := MissingRequiredBinaries(); len(got) != 2 { + t.Errorf("with no servers dir both entries are missing, got %v", got) + } +}