GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mcpx(testsupport): one parser for MCPX_TEST_REQUIRE, and enforce ever… · developing-today/code@4a1382f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/mcpx/internal/testsupport
    • realserver.go
    • require.go
    • require_suite_test.go
    • require_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/mcpx/internal/testsupport/realserver.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/testsupport/realserver.go
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package testsupport
33
import (
44
"os"
55
"path/filepath"
6-
"strings"
76
"testing"
87
)
98

@@ -60,13 +59,9 @@ func realServerPath(dir, name string) (string, bool) {
6059

6160
// realRequired reports whether a MCPX_TEST_REQUIRE comma list demands the
6261
// named server: an entry naming the server itself, the subset label, or
63-
// the wildcard demands it.
62+
// the wildcard demands it. Case is insignificant; the parsing and the
63+
// label/wildcard rules live in requireList (require.go), the one parser
64+
// for the variable (#6904).
6465
func realRequired(requireList, name string) bool {
65-
for _, entry := range strings.Split(requireList, ",") {
66-
switch strings.TrimSpace(entry) {
67-
case name, "realsoftware", "real", "*":
68-
return true
69-
}
70-
}
71-
return false
66+
return parseRequireList(requireList).demandsRealServer(name)
7267
}
Collapse file

‎pkgs/mcpx/internal/testsupport/require.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/testsupport/require.go
+73-8Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,100 @@ package testsupport
33
import (
44
"os"
55
"os/exec"
6+
"sort"
67
"strings"
78
"testing"
89
)
910

10-
// RequiredBinaries returns the external binaries a test run must have, as named by MCPX_TEST_REQUIRE.
11+
// requireList is MCPX_TEST_REQUIRE parsed once (#6904).
1112
//
12-
// MCPX_TEST_REQUIRE names the external binaries a test run must have, as a
13+
// MCPX_TEST_REQUIRE names the external things a test run must have, as a
1314
// comma-separated list (e.g. MCPX_TEST_REQUIRE=deno,bun,node,python3).
15+
// Runtime binaries and real-software servers share the one variable, so
16+
// there is exactly one parser for it: entries are trimmed and lower-cased,
17+
// and the three non-binary spellings are stated here and nowhere else:
18+
//
19+
// - "realsoftware" and "real" name the real-server subset: every real
20+
// server is demanded.
21+
// - "*" is the wildcard: every real server is demanded. It does not
22+
// demand runtime binaries, which have no wildcard meaning.
23+
// - any other entry names a runtime binary (checked on PATH) and, when a
24+
// real server has the same name, that server too.
25+
//
26+
// Case is insignificant in every position: "RealSoftware", "REALSOFTWARE"
27+
// and "realsoftware" mean the same thing, for binaries and servers alike.
28+
type requireList struct {
29+
binaries map[string]bool // lower-cased runtime binary names demanded
30+
realAll bool // a subset label or the wildcard demands every real server
31+
}
32+
33+
// parseRequireList is the single parser for MCPX_TEST_REQUIRE.
34+
func parseRequireList(raw string) requireList {
35+
l := requireList{binaries: map[string]bool{}}
36+
for _, entry := range strings.Split(raw, ",") {
37+
switch entry = strings.ToLower(strings.TrimSpace(entry)); entry {
38+
case "":
39+
case "realsoftware", "real", "*":
40+
l.realAll = true
41+
default:
42+
l.binaries[entry] = true
43+
}
44+
}
45+
return l
46+
}
47+
48+
// demandsBinary reports whether the list names name as a runtime binary.
49+
func (l requireList) demandsBinary(name string) bool {
50+
return l.binaries[strings.ToLower(strings.TrimSpace(name))]
51+
}
52+
53+
// demandsRealServer reports whether the list demands the named real server:
54+
// an entry naming the server itself, a subset label, or the wildcard.
55+
func (l requireList) demandsRealServer(name string) bool {
56+
return l.realAll || l.demandsBinary(name)
57+
}
58+
59+
// RequiredBinaries returns the external binaries a test run must have, as
60+
// named by MCPX_TEST_REQUIRE.
1461
//
1562
// A missing runtime normally skips the tests that need it, which is right
1663
// on a laptop and wrong in CI: a leg that skips is a green leg that tested
1764
// nothing (developing-today/code#1983, the #35 lesson). CI and container
1865
// runs set MCPX_TEST_REQUIRE so a missing required binary fails the test
1966
// instead of silently narrowing what the suite covered.
67+
//
68+
// The real-server subset labels and the wildcard are not binaries and are
69+
// not returned here; see requireList for the rules.
2070
func RequiredBinaries() map[string]bool {
21-
out := map[string]bool{}
22-
for _, name := range strings.Split(os.Getenv("MCPX_TEST_REQUIRE"), ",") {
23-
if name = strings.ToLower(strings.TrimSpace(name)); name != "" {
24-
out[name] = true
25-
}
71+
parsed := parseRequireList(os.Getenv("MCPX_TEST_REQUIRE"))
72+
out := make(map[string]bool, len(parsed.binaries))
73+
for name := range parsed.binaries {
74+
out[name] = true
2675
}
2776
return out
2877
}
2978

79+
// MissingRequiredBinaries returns the required binaries that are not on
80+
// PATH, sorted. It is the suite-level check (#6904): per-test enforcement
81+
// only covers entries that some test happens to pass to RequireBinary, so
82+
// an entry with no consumer -- python3 in CI's list -- would otherwise be
83+
// enforced by nothing and narrow the run silently.
84+
func MissingRequiredBinaries() []string {
85+
var missing []string
86+
for name := range RequiredBinaries() {
87+
if _, err := exec.LookPath(name); err != nil {
88+
missing = append(missing, name)
89+
}
90+
}
91+
sort.Strings(missing)
92+
return missing
93+
}
94+
3095
// MissingRequired reports whether name is missing from PATH while
3196
// MCPX_TEST_REQUIRE names it -- the one case where a test that cannot run
3297
// must fail rather than skip or continue past the gap.
3398
func MissingRequired(name string) bool {
34-
if !RequiredBinaries()[strings.ToLower(name)] {
99+
if !parseRequireList(os.Getenv("MCPX_TEST_REQUIRE")).demandsBinary(name) {
35100
return false
36101
}
37102
_, err := exec.LookPath(name)
Collapse file

‎pkgs/mcpx/internal/testsupport/require_suite_test.go‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testsupport
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
// TestRequiredBinariesAreOnPath is the suite-level enforcement for
9+
// MCPX_TEST_REQUIRE (#6904).
10+
//
11+
// Per-test enforcement only covers an entry that some test passes to
12+
// RequireBinary: an entry with no consumer -- python3 in CI's list -- was
13+
// checked by nothing, so a missing python3 narrowed the run silently.
14+
// This test walks the whole list, so every entry in CI's list is enforced
15+
// even when no individual test names it.
16+
func TestRequiredBinariesAreOnPath(t *testing.T) {
17+
if missing := MissingRequiredBinaries(); len(missing) > 0 {
18+
t.Fatalf("MCPX_TEST_REQUIRE lists binaries that are not on PATH: %s", strings.Join(missing, ", "))
19+
}
20+
}
Collapse file

‎pkgs/mcpx/internal/testsupport/require_test.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/testsupport/require_test.go
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,53 @@ func TestMissingRequired(t *testing.T) {
8888
t.Error("with MCPX_TEST_REQUIRE unset, nothing is missing-required")
8989
}
9090
}
91+
92+
// TestRequireListCaseIsInsignificantEverywhere pins #6904: the one parser
93+
// lower-cases every entry, so a spelling that works for a runtime binary
94+
// means the same thing for a real server. Before the shared parser,
95+
// MCPX_TEST_REQUIRE=RealSoftware demanded a binary named "realsoftware"
96+
// (failing a missing runtime) while demanding no real server at all.
97+
func TestRequireListCaseIsInsignificantEverywhere(t *testing.T) {
98+
for _, raw := range []string{"RealSoftware", "REALSOFTWARE", "realsoftware", " Real , * "} {
99+
parsed := parseRequireList(raw)
100+
if !parsed.demandsRealServer("mcp-server-time") {
101+
t.Errorf("%q should demand every real server", raw)
102+
}
103+
}
104+
for _, tc := range []struct{ raw, binary string }{{"NODE", "node"}, {" Node ,BUN ", "node"}, {" Node ,BUN ", "bun"}} {
105+
if !parseRequireList(tc.raw).demandsBinary(tc.binary) {
106+
t.Errorf("%q should demand %q", tc.raw, tc.binary)
107+
}
108+
}
109+
if got := parseRequireList("RealSoftware"); got.demandsBinary("realsoftware") {
110+
t.Error("a subset label is not a runtime binary name")
111+
}
112+
if got := parseRequireList("*"); got.demandsBinary("*") {
113+
t.Error("the wildcard is not a runtime binary name")
114+
}
115+
}
116+
117+
// TestRequiredBinariesExcludesLabelsAndWildcard pins that the label and
118+
// wildcard spellings never leak into the PATH check as binary names.
119+
func TestRequiredBinariesExcludesLabelsAndWildcard(t *testing.T) {
120+
t.Setenv("MCPX_TEST_REQUIRE", "realsoftware,real,*,deno")
121+
got := RequiredBinaries()
122+
if len(got) != 1 || !got["deno"] {
123+
t.Errorf("want only deno as a binary, got %v", got)
124+
}
125+
}
126+
127+
// TestMissingRequiredBinariesIsTheSuiteLevelCheck pins the enforcement
128+
// that #6904 found missing: every listed binary is checked against PATH,
129+
// whether or not a test happens to pass it to RequireBinary.
130+
func TestMissingRequiredBinariesIsTheSuiteLevelCheck(t *testing.T) {
131+
t.Setenv("MCPX_TEST_REQUIRE", "go,mcpx-no-such-binary-5584,realsoftware")
132+
got := MissingRequiredBinaries()
133+
if len(got) != 1 || got[0] != "mcpx-no-such-binary-5584" {
134+
t.Errorf("want the absent binary named and the present one not, got %v", got)
135+
}
136+
t.Setenv("MCPX_TEST_REQUIRE", "")
137+
if got := MissingRequiredBinaries(); len(got) != 0 {
138+
t.Errorf("with MCPX_TEST_REQUIRE unset nothing is missing, got %v", got)
139+
}
140+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.