From e18a3694d1e3656166d1a03fffad6aeb4fb26d96 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 18 Nov 2026 05:42:56 -0600 Subject: [PATCH] Add ask rounds effect probe --- pkgs/mcpx/internal/e2e/effect_test.go | 76 +++++++++++++++++++ .../e2e/feature_coverage_exemptions.txt | 1 - pkgs/mcpx/internal/settings/effect.go | 5 +- pkgs/mcpx/internal/testsupport/askmcp/main.go | 26 +++++++ 4 files changed, 105 insertions(+), 3 deletions(-) diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index 3ae09b9443..94cf3c3fe3 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -1,6 +1,8 @@ package e2e_test import ( + "encoding/json" + "fmt" "net" "net/http" "net/url" @@ -64,6 +66,7 @@ var implementedEffectProbes = map[string]string{ "tasks.maxAge": "TestTasksMaxAgeIsReachableFromEnvironment", "stats.top": "TestStatsTopLimitsTheRowsTheStatsAPIReports", "proto.askPoll": "TestAskPollCeilingIsReachableFromTheEnvironment", + "proto.askRounds": "TestAskRoundsLimitIsReachableFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", "http.callBodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -117,6 +120,7 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestTasksMaxAgeIsReachableFromEnvironment": TestTasksMaxAgeIsReachableFromEnvironment, "TestStatsTopLimitsTheRowsTheStatsAPIReports": TestStatsTopLimitsTheRowsTheStatsAPIReports, "TestAskPollCeilingIsReachableFromTheEnvironment": TestAskPollCeilingIsReachableFromTheEnvironment, + "TestAskRoundsLimitIsReachableFromTheEnvironment": TestAskRoundsLimitIsReachableFromTheEnvironment, "TestDaemonAddressIsReachableFromTheEnvironment": TestDaemonAddressIsReachableFromTheEnvironment, "TestHTTPBodyLimitsRejectOversizedBodies": TestHTTPBodyLimitsRejectOversizedBodies, "TestHTTPEventStreamSettingsChangeTheStream": TestHTTPEventStreamSettingsChangeTheStream, @@ -302,6 +306,78 @@ func TestAskPollCeilingIsReachableFromTheEnvironment(t *testing.T) { } } +// proto.askRounds limits how many times one MCP request may ask its client +// for input. The fake upstream asks twice in one tool call; default settings +// complete both rounds, while a configured limit of one rejects the second. +// Oracle: the default returns a complete result containing the second answer; +// a limit of one returns the ask-round exhaustion error instead. +func TestAskRoundsLimitIsReachableFromTheEnvironment(t *testing.T) { + call := func(env ...string) string { + t.Helper() + e := askEnv(t) + e.setenv(env...) + e.run("refresh") + ep := e.endpoint(t) + meta := map[string]any{ + "io.modelcontextprotocol/protocolVersion": "2026-07-28", + "io.modelcontextprotocol/clientCapabilities": map[string]any{ + "elicitation": map[string]any{"form": map[string]any{}}, + }, + } + params := map[string]any{ + "name": "mcpx_call", + "arguments": map[string]any{"namespace": "ask", "tool": "need_repo_twice"}, + "_meta": meta, + } + for attempt := 0; attempt < 3; attempt++ { + resp := mcpPost(t, ep, "", map[string]any{ + "jsonrpc": "2.0", "id": attempt + 1, "method": "tools/call", "params": params, + }) + var frame map[string]any + if err := json.NewDecoder(resp.Body).Decode(&frame); err != nil { + _ = resp.Body.Close() + t.Fatal(err) + } + _ = resp.Body.Close() + if frame["error"] != nil { + return dumpJSON(t, frame) + } + result, _ := frame["result"].(map[string]any) + if result["resultType"] == "complete" { + return dumpJSON(t, frame) + } + if result["resultType"] != "input_required" { + t.Fatalf("expected input_required or complete, got %s", dumpJSON(t, frame)) + } + state, _ := result["requestState"].(string) + requests, _ := result["inputRequests"].(map[string]any) + if state == "" || len(requests) != 1 { + t.Fatalf("expected one resumable elicitation request, got %s", dumpJSON(t, result)) + } + responses := map[string]any{} + for id := range requests { + responses[id] = map[string]any{ + "action": "accept", + "content": map[string]any{"repo": fmt.Sprintf("me/round%d", attempt+1)}, + } + } + params["requestState"] = state + params["inputResponses"] = responses + } + t.Fatal("two-round call did not complete or hit its configured limit") + return "" + } + + defaultResult := call() + if !strings.Contains(defaultResult, `"resultType":"complete"`) || !strings.Contains(defaultResult, "me/round2") { + t.Fatalf("default proto.askRounds should complete both rounds, got %s", defaultResult) + } + limitedResult := call("MCPX_PROTO_ASK_ROUNDS=1") + if !strings.Contains(limitedResult, "still asking for input after 1 rounds") { + t.Fatalf("proto.askRounds=1 should stop the second round, got %s", limitedResult) + } +} + // 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 65757a2778..f5134fcc72 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -62,7 +62,6 @@ setting script.runtime no integration-test exercise yet; burn-down #8474 (settin setting script.runtimeOrder no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test 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.askRounds no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.askTTL no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.askTimeout no integration-test exercise yet; burn-down #8473 (settings proto 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 diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index aa42b13b07..94b2224425 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -70,6 +70,7 @@ var EffectProbes = map[string]string{ "script.interpreter": "TestScriptInterpreterIsReachableFromTheEnvironment", "proxy.timeout": "TestProxyUpstreamTimeoutIsReachableFromTheEnvironment", "proto.askPoll": "TestAskPollCeilingIsReachableFromTheEnvironment", + "proto.askRounds": "TestAskRoundsLimitIsReachableFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", "http.callBodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -166,7 +167,6 @@ var EffectExemptions = map[string]string{ "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.askTimeout": "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.askRounds": "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.askTTL": "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", @@ -290,7 +290,8 @@ 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 = 194 // 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. +// Shrunk 2026-11-18 (#8473 chain 2): proto.askRounds gained a two-round MCP e2e probe. +const EffectExemptionPin = 193 // 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, diff --git a/pkgs/mcpx/internal/testsupport/askmcp/main.go b/pkgs/mcpx/internal/testsupport/askmcp/main.go index 016b25eb8a..335f8b6cb8 100644 --- a/pkgs/mcpx/internal/testsupport/askmcp/main.go +++ b/pkgs/mcpx/internal/testsupport/askmcp/main.go @@ -162,6 +162,11 @@ func (s *server) handle(f frame) map[string]any { "description": "Asks which repository, then reports the answer.", "inputSchema": map[string]any{"type": "object", "properties": map[string]any{}}, }, + { + "name": "need_repo_twice", + "description": "Asks which repository twice, then reports both answers.", + "inputSchema": map[string]any{"type": "object", "properties": map[string]any{}}, + }, { "name": "need_model", "description": "Asks the client's model to write something.", @@ -262,6 +267,27 @@ func (s *server) callTool(f frame) map[string]any { return ok(f.ID, text("no repository was chosen ("+e.Action+")")) } return ok(f.ID, text(fmt.Sprintf("using %v", e.Content["repo"]))) + case "need_repo_twice": + var repos []string + for round := 1; round <= 2; round++ { + res, err := s.ask("elicitation/create", map[string]any{ + "message": fmt.Sprintf("Which repository should this go in (round %d)?", round), + "requestedSchema": repoSchema(), + }) + if err != nil { + return fail(f.ID, -32603, err.Error()) + } + var e struct { + Action string `json:"action"` + Content map[string]any `json:"content"` + } + _ = json.Unmarshal(res, &e) + if e.Action != "accept" { + return ok(f.ID, text("no repository was chosen ("+e.Action+")")) + } + repos = append(repos, fmt.Sprint(e.Content["repo"])) + } + return ok(f.ID, text(fmt.Sprintf("using %s and %s", repos[0], repos[1]))) case "need_model": res, err := s.ask("sampling/createMessage", map[string]any{ "maxTokens": 64,