GeezerVison is showing github.com — mcpx(testsupport): one parser for MCPX_TEST_REQUIRE, and enforce every listed entry (#6904) by dezren39 · Pull Request #7696 · developing-today/code
mcpx(testsupport): one parser for MCPX_TEST_REQUIRE, and enforce every listed entry (#6904)
#7696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.go
(4)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
mcpx(testsupport): one parser for MCPX_TEST_REQUIRE, and enforce ever…
…y 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
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
repo-worker-code
authored and
repo-worker-code-k
committed
Nov 10, 2026
commit dcbdc277d187183b7258eae442d6276914c56168
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3,7 +3,6 @@ package testsupport
import (
"os"
"path/filepath"
"strings"
"testing"
)
Expand Down
Expand Up
@@ -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)
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -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)
Comment thread
dezren39 marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
}
}
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)
Expand Down
Original file line number
Diff line number
Diff line change
@@ -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, ", "))
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -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)
}
}
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.