diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index 1fd91c09b8..923e548c2b 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -95,6 +95,9 @@ var implementedEffectProbes = map[string]string{ "recipes.limit": "TestRecipesLimitBoundsTheRankingFromTheEnvironment", "tasks.ttl": "TestTasksTTLSetsAnExecTasksRetentionFromTheEnvironment", "tasks.resultWait": "TestTasksResultWaitBoundsCollectingAResultFromTheEnvironment", + "protoTasks.maxTTL": "TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment", + "protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment", + "protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment", "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", @@ -177,6 +180,9 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestRecipesLimitBoundsTheRankingFromTheEnvironment": TestRecipesLimitBoundsTheRankingFromTheEnvironment, "TestTasksTTLSetsAnExecTasksRetentionFromTheEnvironment": TestTasksTTLSetsAnExecTasksRetentionFromTheEnvironment, "TestTasksResultWaitBoundsCollectingAResultFromTheEnvironment": TestTasksResultWaitBoundsCollectingAResultFromTheEnvironment, + "TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment": TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment, + "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment": TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment, + "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment": TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment, "TestServeMCPUnmountsTheEndpointFromTheEnvironment": TestServeMCPUnmountsTheEndpointFromTheEnvironment, "TestDaemonAddressIsReachableFromTheEnvironment": TestDaemonAddressIsReachableFromTheEnvironment, "TestDaemonAutostartIsReachableFromTheEnvironment": TestDaemonAutostartIsReachableFromTheEnvironment, @@ -1264,6 +1270,104 @@ func TestTasksResultWaitBoundsCollectingAResultFromTheEnvironment(t *testing.T) } } +// tasksClient is a 2026-07-28 client that declared the tasks extension, +// against a daemon that hands any call over 100ms a task. +func tasksClient(t *testing.T, env ...string) func(method string, params map[string]any) map[string]any { + t.Helper() + e := newEnv(t, oneServer) + e.setenv(append([]string{"MCPX_PROTO_MESSAGES_TASK_AFTER=100ms"}, env...)...) + e.run("refresh") + ep := e.endpoint(t) + id := 0 + return func(method string, params map[string]any) map[string]any { + t.Helper() + id++ + params["_meta"] = map[string]any{ + "io.modelcontextprotocol/protocolVersion": "2026-07-28", + "io.modelcontextprotocol/clientCapabilities": map[string]any{ + "extensions": map[string]any{"io.modelcontextprotocol/tasks": map[string]any{}}, + }, + } + resp := mcpPost(t, ep, "", map[string]any{"jsonrpc": "2.0", "id": id, "method": method, "params": params}) + defer func() { _ = resp.Body.Close() }() + return decodeJSON(t, resp.Body) + } +} + +// startSlowTask calls a two-second script, which the 100ms threshold +// turns into a task, and returns the reply. +func startSlowTask(t *testing.T, rpc func(string, map[string]any) map[string]any) map[string]any { + t.Helper() + return rpc("tools/call", map[string]any{"name": "mcpx_exec", + "arguments": map[string]any{"source": "await new Promise((r) => setTimeout(r, 2000))"}}) +} + +// protoTasks.maxTTL clamps the retention of a task mcpx hands out. +// Oracle: the task carries ttlMs 600000 at the default and 5000 with +// MCPX_PROTO_TASKS_MAX_TTL=5s. +func TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment(t *testing.T) { + ttl := func(env ...string) any { + t.Helper() + doc := startSlowTask(t, tasksClient(t, env...)) + res, _ := doc["result"].(map[string]any) + if res["resultType"] != "task" { + t.Fatalf("a two-second call past a 100ms threshold should be a task:\n%s", dumpJSON(t, doc)) + } + return res["ttlMs"] + } + + if got := ttl(); got != float64(600000) { + t.Fatalf("at the default protoTasks.maxTTL a task should carry ttlMs 600000, got %v", got) + } + if got := ttl("MCPX_PROTO_TASKS_MAX_TTL=5s"); got != float64(5000) { + t.Fatalf("protoTasks.maxTTL=5s should clamp a task to ttlMs 5000, got %v", got) + } +} + +// protoTasks.maxPerRequestor caps one requestor's unfinished tasks. +// Oracle: two slow calls both become tasks at the default; with +// MCPX_PROTO_TASKS_MAX_PER_REQUESTOR=1 the second is refused. +func TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment(t *testing.T) { + second := func(env ...string) string { + t.Helper() + rpc := tasksClient(t, env...) + startSlowTask(t, rpc) + return dumpJSON(t, startSlowTask(t, rpc)) + } + + if got := second(); !strings.Contains(got, `"resultType":"task"`) { + t.Fatalf("at the default protoTasks.maxPerRequestor a second slow call should still become a task:\n%s", got) + } + if got := second("MCPX_PROTO_TASKS_MAX_PER_REQUESTOR=1"); !strings.Contains(got, "per-requestor task cap reached") { + t.Fatalf("protoTasks.maxPerRequestor=1 should refuse a second unfinished task:\n%s", got) + } +} + +// protoTasks.perMinute is the per-requestor admission window for tasks/* +// calls. A task is started and then read twice with tasks/get. +// Oracle: both reads succeed at the default; with +// MCPX_PROTO_TASKS_PER_MINUTE=1 the second is refused. +func TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment(t *testing.T) { + secondRead := func(env ...string) string { + t.Helper() + rpc := tasksClient(t, env...) + res, _ := startSlowTask(t, rpc)["result"].(map[string]any) + id, _ := res["taskId"].(string) + if id == "" { + t.Fatalf("no task was started: %v", res) + } + rpc("tasks/get", map[string]any{"taskId": id}) + return dumpJSON(t, rpc("tasks/get", map[string]any{"taskId": id})) + } + + if got := secondRead(); !strings.Contains(got, `"taskId"`) || strings.Contains(got, "admission window") { + t.Fatalf("at the default protoTasks.perMinute a second tasks/get should succeed:\n%s", got) + } + if got := secondRead("MCPX_PROTO_TASKS_PER_MINUTE=1"); !strings.Contains(got, "admission window") { + t.Fatalf("protoTasks.perMinute=1 should refuse a second tasks/get:\n%s", 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 27866d5aaf..f8ce06b99a 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -65,9 +65,6 @@ setting proto.elicitationPerMinute no integration-test exercise yet; burn-down # 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 protoTasks.cancelGrace no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test -setting protoTasks.maxPerRequestor no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test -setting protoTasks.maxTTL no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test -setting protoTasks.perMinute no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting plugin.annotate no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test setting plugin.backend no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test setting plugin.bin no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index 493423f067..4bca370425 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -97,6 +97,9 @@ var EffectProbes = map[string]string{ "recipes.limit": "TestRecipesLimitBoundsTheRankingFromTheEnvironment", "tasks.ttl": "TestTasksTTLSetsAnExecTasksRetentionFromTheEnvironment", "tasks.resultWait": "TestTasksResultWaitBoundsCollectingAResultFromTheEnvironment", + "protoTasks.maxTTL": "TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment", + "protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment", + "protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment", "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", @@ -275,9 +278,6 @@ var EffectExemptions = map[string]string{ "plugin.headless": "read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host", "plugin.daemonTools": "read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host", "plugin.disabledTools": "read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host", - "protoTasks.maxTTL": "task-store limits: covered by internal/tasks store tests (TTL clamp), not by a settings with/without probe", - "protoTasks.maxPerRequestor": "task-store limits: covered by internal/tasks store tests (per-requestor cap), not by a settings with/without probe", - "protoTasks.perMinute": "task-store limits: covered by internal/tasks store tests (admission window), not by a settings with/without probe", "protoTasks.cancelGrace": "task-store cancellation timing: covered by internal/tasks store tests, not by a settings with/without probe", "upstream.protocol": "upstream protocol detection: its effect needs a peer whose era must be probed, beyond what the fake server presents", "upstream.probeTimeout": "upstream protocol detection: its effect needs a peer whose era must be probed, beyond what the fake server presents", @@ -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 = 165 // Shrunk 2026-11-18 (#8473 chain 17): tasks.ttl and tasks.resultWait gained /v1 task probes. Earlier shrunk 2026-11-18 (#8473 chain 16): recipes.minScore, matchMargin and limit gained recipe probes. Earlier shrunk 2026-11-18 (#8473 chain 15): logstore.queryLimit gained a /v1/log probe. Earlier shrunk 2026-11-18 (#8473 chain 14): completion.perMinute and completion.serverPerMinute gained 429 probes. Earlier shrunk 2026-11-18 (#8473 chain 13): mcp.pageSize and mcp.passthrough gained tools/list probes. Earlier shrunk 2026-11-18 (#8473 chain 12): exec.timeout (now read by local runs), exec.maxOutputBytes and exec.output gained probes. Earlier shrunk 2026-11-18 (#8473 chain 11): spec.first and spec.lenient mapped to their existing revision-policy probes, spec.precedence gained one. Earlier shrunk 2026-11-18 (#8473 chain 10): protoMessages.taskAfter and protoTasks.pollInterval gained task probes. Earlier shrunk 2026-11-18 (#8473 chain 9): protoMessages.listMaxAge and readMaxAge gained cache-hint probes. Earlier shrunk 2026-11-18 (#8473 chain 8): proto.native gained an asked-client probe. Earlier 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. +const EffectExemptionPin = 162 // Shrunk 2026-11-18 (#8473 chain 18): protoTasks.maxTTL, maxPerRequestor and perMinute gained task-store probes. Earlier shrunk 2026-11-18 (#8473 chain 17): tasks.ttl and tasks.resultWait gained /v1 task probes. Earlier shrunk 2026-11-18 (#8473 chain 16): recipes.minScore, matchMargin and limit gained recipe probes. Earlier shrunk 2026-11-18 (#8473 chain 15): logstore.queryLimit gained a /v1/log probe. Earlier shrunk 2026-11-18 (#8473 chain 14): completion.perMinute and completion.serverPerMinute gained 429 probes. Earlier shrunk 2026-11-18 (#8473 chain 13): mcp.pageSize and mcp.passthrough gained tools/list probes. Earlier shrunk 2026-11-18 (#8473 chain 12): exec.timeout (now read by local runs), exec.maxOutputBytes and exec.output gained probes. Earlier shrunk 2026-11-18 (#8473 chain 11): spec.first and spec.lenient mapped to their existing revision-policy probes, spec.precedence gained one. Earlier shrunk 2026-11-18 (#8473 chain 10): protoMessages.taskAfter and protoTasks.pollInterval gained task probes. Earlier shrunk 2026-11-18 (#8473 chain 9): protoMessages.listMaxAge and readMaxAge gained cache-hint probes. Earlier shrunk 2026-11-18 (#8473 chain 8): proto.native gained an asked-client probe. Earlier 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,