From 3db6800cf40de8009a48186e2bcd74c7106c9dd0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 17:36:17 +0000 Subject: [PATCH] test(mcpx): effect probes for proto.mcpPath and proto.serveMCP An initialize to the daemon shows where MCP is mounted. At the default it answers at /mcp only; MCPX_PROTO_MCP_PATH=/tools/mcp moves it there, and MCPX_PROTO_SERVE_MCP=false leaves /mcp unmounted (404). Drops both exemptions and shrinks the pin to 186. Refs #8473 Co-Authored-By: Claude Opus 5.5 --- pkgs/mcpx/internal/e2e/effect_test.go | 67 +++++++++++++++++++ .../e2e/feature_coverage_exemptions.txt | 2 - pkgs/mcpx/internal/settings/effect.go | 6 +- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index ad56268ca6..dc83d1165d 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -72,6 +72,8 @@ var implementedEffectProbes = map[string]string{ "proto.askTimeout": "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment", "proto.stateTTL": "TestStateTTLExpiresAResumableRequestFromTheEnvironment", "proto.sessionIdle": "TestSessionIdleReapsAnUnusedSessionFromTheEnvironment", + "proto.mcpPath": "TestMCPPathMovesTheEndpointFromTheEnvironment", + "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -131,6 +133,8 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment": TestAskTimeoutReleasesAHeldRequestFromTheEnvironment, "TestStateTTLExpiresAResumableRequestFromTheEnvironment": TestStateTTLExpiresAResumableRequestFromTheEnvironment, "TestSessionIdleReapsAnUnusedSessionFromTheEnvironment": TestSessionIdleReapsAnUnusedSessionFromTheEnvironment, + "TestMCPPathMovesTheEndpointFromTheEnvironment": TestMCPPathMovesTheEndpointFromTheEnvironment, + "TestServeMCPUnmountsTheEndpointFromTheEnvironment": TestServeMCPUnmountsTheEndpointFromTheEnvironment, "TestDaemonAddressIsReachableFromTheEnvironment": TestDaemonAddressIsReachableFromTheEnvironment, "TestDaemonAutostartIsReachableFromTheEnvironment": TestDaemonAutostartIsReachableFromTheEnvironment, "TestHTTPBodyLimitsRejectOversizedBodies": TestHTTPBodyLimitsRejectOversizedBodies, @@ -608,6 +612,69 @@ func TestSessionIdleReapsAnUnusedSessionFromTheEnvironment(t *testing.T) { } } +// initializeStatus posts an initialize to path on the daemon and returns +// the HTTP status, so a probe can tell where MCP is mounted. +func initializeStatus(t *testing.T, ep, path string) int { + t.Helper() + body := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"t","version":"1"}}}` + req, err := http.NewRequest(http.MethodPost, ep+path, strings.NewReader(body)) + if err != nil { + t.Fatal(err) + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Accept", "application/json, text/event-stream") + resp, err := (&http.Client{Timeout: 30 * time.Second}).Do(req) + if err != nil { + t.Fatal(err) + } + _ = resp.Body.Close() + return resp.StatusCode +} + +// proto.mcpPath is where the daemon mounts MCP. +// Oracle: at the default an initialize to /mcp succeeds and one to +// /tools/mcp does not; with MCPX_PROTO_MCP_PATH=/tools/mcp it is the +// other way round. +func TestMCPPathMovesTheEndpointFromTheEnvironment(t *testing.T) { + statuses := func(env ...string) (atMCP, atMoved int) { + t.Helper() + e := newEnv(t, oneServer) + e.setenv(env...) + e.run("ls") + ep := endpointOf(t, e) + return initializeStatus(t, ep, "/mcp"), initializeStatus(t, ep, "/tools/mcp") + } + + if atMCP, atMoved := statuses(); atMCP != http.StatusOK || atMoved == http.StatusOK { + t.Fatalf("at the default proto.mcpPath MCP should answer at /mcp only, got /mcp=%d /tools/mcp=%d", atMCP, atMoved) + } + if atMCP, atMoved := statuses("MCPX_PROTO_MCP_PATH=/tools/mcp"); atMoved != http.StatusOK || atMCP == http.StatusOK { + t.Fatalf("proto.mcpPath=/tools/mcp should move MCP there, got /mcp=%d /tools/mcp=%d", atMCP, atMoved) + } +} + +// proto.serveMCP mounts mcpx's own MCP server on the daemon. +// Oracle: at the default an initialize to /mcp succeeds; with +// MCPX_PROTO_SERVE_MCP=false the daemon still answers /v1 but not /mcp. +func TestServeMCPUnmountsTheEndpointFromTheEnvironment(t *testing.T) { + status := func(env ...string) int { + t.Helper() + e := newEnv(t, oneServer) + e.setenv(env...) + e.run("ls") + got := initializeStatus(t, endpointOf(t, e), "/mcp") + t.Logf("serveMCP env=%v status=%d", env, got) + return got + } + + if got := status(); got != http.StatusOK { + t.Fatalf("at the default proto.serveMCP the daemon should answer MCP at /mcp, got %d", got) + } + if got := status("MCPX_PROTO_SERVE_MCP=false"); got == http.StatusOK { + t.Fatalf("proto.serveMCP=false should leave /mcp unmounted, got %d", got) + } +} + // TestDaemonAddressIsReachableFromTheEnvironment is the effect probe // for daemon.address (#8468 chain 1). The exemption it replaced said // a bind address is a network identity the harness cannot vary diff --git a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt index 1823a4cab9..7f2c63ef1b 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -62,11 +62,9 @@ setting script.runtimeOrder no integration-test exercise yet; burn-down #8474 (s setting script.runtimes no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test setting script.suffix no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test setting proto.elicitationPerMinute no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test -setting proto.mcpPath no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.native no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.samplingPerMinute no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.samplingSessionPerMinute no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test -setting proto.serveMCP no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting protoMessages.listMaxAge no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting protoMessages.readMaxAge no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting protoMessages.taskAfter no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index 5c804bf632..07655ad1a9 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -75,6 +75,8 @@ var EffectProbes = map[string]string{ "proto.askTimeout": "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment", "proto.stateTTL": "TestStateTTLExpiresAResumableRequestFromTheEnvironment", "proto.sessionIdle": "TestSessionIdleReapsAnUnusedSessionFromTheEnvironment", + "proto.mcpPath": "TestMCPPathMovesTheEndpointFromTheEnvironment", + "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -168,8 +170,6 @@ var EffectExemptions = map[string]string{ "catalog.bias": "catalog ranking/truncation: the fake server's tool set is too small for a budget or bias change to alter the listing observably", "catalog.instructions": "the fake MCP server serves no server instructions, so `types` output cannot differ either way until a fixture gains instructions", "proto.native": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", - "proto.serveMCP": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", - "proto.mcpPath": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", "proto.elicitationPerMinute": "daemon proto rate limit: its effect appears only when an upstream server exceeds the per-minute elicitation bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", "proto.samplingPerMinute": "daemon proto rate limit: its effect appears only when an upstream server exceeds the per-minute sampling bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", "proto.samplingSessionPerMinute": "daemon proto rate limit: its effect appears only when one session exceeds the per-minute sampling bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", @@ -290,7 +290,7 @@ var EffectExemptions = map[string]string{ // EffectExemptionPin is the ratchet: the exemption count at the time // the guard landed. It may only ever be lowered, and only in the PR // that removes an exemption by adding the probe that replaces it. -const EffectExemptionPin = 188 // Shrunk 2026-11-18 (#8473 chain 6): proto.sessionIdle gained a reaped-session probe. Earlier shrunk 2026-11-18 (#8473 chain 5): proto.stateTTL gained a late-resume probe. Earlier shrunk 2026-11-18 (#8473 chain 4): proto.askTimeout gained a held-request probe. Earlier shrunk 2026-11-18 (#8473 chain 3): proto.askTTL gained a /v1/ask deadline probe. Earlier shrunk 2026-11-18 (#8473 chain 2): proto.askRounds gained a two-round MCP e2e probe. Earlier shrunk 2026-11-18 (#8468 chain 2): daemon.autostart gained its probe. Earlier shrunk 2026-11-17: (#8467 settings core-paths burn-down) paths.plugins gained its probe. Earlier shrunk 2026-11-17: (#8469) 14 http.* and transport.* settings gained their probes. Earlier shrunk 2026-11-17: (#8470 burn-down) stats.top gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.cache gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.scripts gained its probe. Earlier shrunk 2026-11-17 (#8468 chain 1): daemon.address gained its probe. Earlier shrunk 2026-11-17 (#8473 chain 1): proto.askPoll gained its probe. Deliberate +1 (2026-11-14, #1917 remainder shepherd of PR #7818) for script.language: covered by deterministic internal/runner tests (TestEffectiveScriptLanguage, TestExplicitPythonLanguageRunsInlineSnippet); the e2e harness script fixtures are TypeScript-only. Earlier deliberate +3 (2026-11-09, #2716) for proto.elicitationPerMinute, proto.samplingPerMinute and proto.samplingSessionPerMinute: daemon rate limits whose effect needs an over-limit sampling/elicitation flood no e2e fixture drives deterministically; the limiter is covered by internal/mcpclient and internal/daemon ratelimit tests. Earlier deliberate raises: +1 for daemon.roots and +8 for model.*: model settings are covered by internal/model and daemon unit tests; settings-driven e2e probes are not yet present. Deliberate +1 (2026-11-03, #1925 slice 3) for sampling.answerLocally: same model-layer coverage, daemon unit tests in internal/daemon/sampling_local_test.go. Deliberate +1 (2026-11-03, #5242) for plugin.disabledTools: read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host, the same basis as every other plugin.* exemption. Deliberate +5 (2026-11-04, #1915 stage 2): import graph, missing, dynamic, cross-project and network policies are covered by deterministic internal/preflight tests, but the e2e harness has no isolated Deno graph fixture yet. Deliberate +2 (2026-11-05, #1911): checker error and unsupported-runtime policies are covered by deterministic internal/preflight stub-runtime tests; the e2e harness has no isolated Deno checker fixture. +const EffectExemptionPin = 186 // Shrunk 2026-11-18 (#8473 chain 7): proto.mcpPath and proto.serveMCP gained mount probes. Earlier shrunk 2026-11-18 (#8473 chain 6): proto.sessionIdle gained a reaped-session probe. Earlier shrunk 2026-11-18 (#8473 chain 5): proto.stateTTL gained a late-resume probe. Earlier shrunk 2026-11-18 (#8473 chain 4): proto.askTimeout gained a held-request probe. Earlier shrunk 2026-11-18 (#8473 chain 3): proto.askTTL gained a /v1/ask deadline probe. Earlier shrunk 2026-11-18 (#8473 chain 2): proto.askRounds gained a two-round MCP e2e probe. Earlier shrunk 2026-11-18 (#8468 chain 2): daemon.autostart gained its probe. Earlier shrunk 2026-11-17: (#8467 settings core-paths burn-down) paths.plugins gained its probe. Earlier shrunk 2026-11-17: (#8469) 14 http.* and transport.* settings gained their probes. Earlier shrunk 2026-11-17: (#8470 burn-down) stats.top gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.cache gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.scripts gained its probe. Earlier shrunk 2026-11-17 (#8468 chain 1): daemon.address gained its probe. Earlier shrunk 2026-11-17 (#8473 chain 1): proto.askPoll gained its probe. Deliberate +1 (2026-11-14, #1917 remainder shepherd of PR #7818) for script.language: covered by deterministic internal/runner tests (TestEffectiveScriptLanguage, TestExplicitPythonLanguageRunsInlineSnippet); the e2e harness script fixtures are TypeScript-only. Earlier deliberate +3 (2026-11-09, #2716) for proto.elicitationPerMinute, proto.samplingPerMinute and proto.samplingSessionPerMinute: daemon rate limits whose effect needs an over-limit sampling/elicitation flood no e2e fixture drives deterministically; the limiter is covered by internal/mcpclient and internal/daemon ratelimit tests. Earlier deliberate raises: +1 for daemon.roots and +8 for model.*: model settings are covered by internal/model and daemon unit tests; settings-driven e2e probes are not yet present. Deliberate +1 (2026-11-03, #1925 slice 3) for sampling.answerLocally: same model-layer coverage, daemon unit tests in internal/daemon/sampling_local_test.go. Deliberate +1 (2026-11-03, #5242) for plugin.disabledTools: read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host, the same basis as every other plugin.* exemption. Deliberate +5 (2026-11-04, #1915 stage 2): import graph, missing, dynamic, cross-project and network policies are covered by deterministic internal/preflight tests, but the e2e harness has no isolated Deno graph fixture yet. Deliberate +2 (2026-11-05, #1911): checker error and unsupported-runtime policies are covered by deterministic internal/preflight stub-runtime tests; the e2e harness has no isolated Deno checker fixture. // CheckEffectCoverage returns one violation per way the probe and // exemption maps fail to cover reg exactly: a setting with neither,