diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index ae28c374e1..f14e45d473 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "os" + "os/exec" "path/filepath" "sort" "strings" @@ -99,6 +100,8 @@ var implementedEffectProbes = map[string]string{ "protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment", "protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment", "events.history": "TestEventsHistoryBoundsTheReplay", + "catalog.pinnedTools": "TestCatalogPinnedToolsAlwaysListInReactiveMode", + "retention.maxTools": "TestRetentionMaxToolsCapsTheReactiveWorkingSet", "diagnose.history": "TestDiagnoseHistoryCapsRecordedSchemaChanges", "diagnose.preflight": "TestDiagnosePreflightStopsAMismatchedScript", "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", @@ -187,6 +190,8 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment": TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment, "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment": TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment, "TestEventsHistoryBoundsTheReplay": TestEventsHistoryBoundsTheReplay, + "TestCatalogPinnedToolsAlwaysListInReactiveMode": TestCatalogPinnedToolsAlwaysListInReactiveMode, + "TestRetentionMaxToolsCapsTheReactiveWorkingSet": TestRetentionMaxToolsCapsTheReactiveWorkingSet, "TestDiagnoseHistoryCapsRecordedSchemaChanges": TestDiagnoseHistoryCapsRecordedSchemaChanges, "TestDiagnosePreflightStopsAMismatchedScript": TestDiagnosePreflightStopsAMismatchedScript, "TestServeMCPUnmountsTheEndpointFromTheEnvironment": TestServeMCPUnmountsTheEndpointFromTheEnvironment, @@ -1490,6 +1495,113 @@ console.log("script ran");` } } +// reactiveTools opens one `mcpx serve --mode reactive` stdio session, +// optionally asks request_tools for query first, and returns the names the +// session then lists. Frames go one at a time and each waits for its own +// answer: the server handles requests concurrently, so a pipelined +// tools/list could be answered before the request_tools it follows. +func reactiveTools(t *testing.T, e *env, query string) map[string]bool { + t.Helper() + cmd := exec.Command(e.mcpx, "serve", "--mode", "reactive") + cmd.Dir = e.dir + cmd.Env = e.envVars + stdin, err := cmd.StdinPipe() + if err != nil { + t.Fatal(err) + } + stdout, err := cmd.StdoutPipe() + if err != nil { + t.Fatal(err) + } + if err := cmd.Start(); err != nil { + t.Fatal(err) + } + defer func() { _ = cmd.Process.Kill(); _ = cmd.Wait() }() + dec := json.NewDecoder(bufio.NewReaderSize(stdout, 1<<20)) + id := 0 + rpc := func(method string, params any) json.RawMessage { + t.Helper() + id++ + b, _ := json.Marshal(map[string]any{"jsonrpc": "2.0", "id": id, "method": method, "params": params}) + if _, err := stdin.Write(append(b, '\n')); err != nil { + t.Fatal(err) + } + for { + var f struct { + ID *int `json:"id"` + Result json.RawMessage `json:"result"` + Error json.RawMessage `json:"error"` + } + if err := dec.Decode(&f); err != nil { + t.Fatalf("read %s: %v", method, err) + } + if f.ID != nil && *f.ID == id { + if len(f.Error) > 0 { + t.Fatalf("%s failed: %s", method, f.Error) + } + return f.Result + } + } + } + rpc("initialize", map[string]any{}) + if query != "" { + rpc("tools/call", map[string]any{"name": "request_tools", + "arguments": map[string]any{"query": query, "limit": 5}}) + } + var list struct { + Tools []struct { + Name string `json:"name"` + } `json:"tools"` + } + if err := json.Unmarshal(rpc("tools/list", map[string]any{}), &list); err != nil { + t.Fatal(err) + } + names := map[string]bool{} + for _, tool := range list.Tools { + names[tool.Name] = true + } + return names +} + +// TestCatalogPinnedToolsAlwaysListInReactiveMode is the effect probe for +// catalog.pinnedTools: a fresh reactive session lists only its meta tools, +// and a tool pinned from the environment is listed from the start. +func TestCatalogPinnedToolsAlwaysListInReactiveMode(t *testing.T) { + e := newEnv(t, oneServer) + e.run("ls") + if got := reactiveTools(t, e, ""); got["mcpx_status"] { + t.Errorf("a fresh reactive session should not list mcpx_status unpinned: %v", got) + } + e.setenv("MCPX_CATALOG_PINNED_TOOLS=mcpx_status") + if got := reactiveTools(t, e, ""); !got["mcpx_status"] { + t.Errorf("catalog.pinnedTools=mcpx_status should list it from the start: %v", got) + } +} + +// TestRetentionMaxToolsCapsTheReactiveWorkingSet is the effect probe for +// retention.maxTools: request_tools activates five tools, all of which the +// default working set keeps; capped at two, only two stay listed. +func TestRetentionMaxToolsCapsTheReactiveWorkingSet(t *testing.T) { + retained := func(names map[string]bool) int { + n := 0 + for name := range names { + if name != "request_tools" && name != "batch_call" { + n++ + } + } + return n + } + e := newEnv(t, oneServer) + e.run("ls") + if n := retained(reactiveTools(t, e, "echo")); n != 5 { + t.Errorf("the default retention.maxTools should keep all 5 activated tools, kept %d", n) + } + e.setenv("MCPX_RETENTION_MAX_TOOLS=2") + if n := retained(reactiveTools(t, e, "echo")); n != 2 { + t.Errorf("retention.maxTools=2 should keep 2 activated tools, kept %d", n) + } +} + // 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 b48a20c38e..3336535d4b 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -147,7 +147,6 @@ setting autostart.pollInterval no integration-test exercise yet; burn-down #8470 setting catalog.bias no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting catalog.budget no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting catalog.instructions no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test -setting catalog.pinnedTools no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting completion.maxValues no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting deps.autoInstall no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting doctor.timeout no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test @@ -168,7 +167,6 @@ setting preset no integration-test exercise yet; burn-down #8470 (settings long- setting presets no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting registry.timeout no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting repair.autonomy no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test -setting retention.maxTools no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting retention.stickyWindow no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting sampling.answerLocally no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test setting search.semantic no integration-test exercise yet; burn-down #8470 (settings long-tail families); needs an EffectProbes entry + e2e test diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index 3171b1ac1e..e277dd8034 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -101,6 +101,8 @@ var EffectProbes = map[string]string{ "protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment", "protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment", "events.history": "TestEventsHistoryBoundsTheReplay", + "catalog.pinnedTools": "TestCatalogPinnedToolsAlwaysListInReactiveMode", + "retention.maxTools": "TestRetentionMaxToolsCapsTheReactiveWorkingSet", "diagnose.history": "TestDiagnoseHistoryCapsRecordedSchemaChanges", "diagnose.preflight": "TestDiagnosePreflightStopsAMismatchedScript", "proto.serveMCP": "TestServeMCPUnmountsTheEndpointFromTheEnvironment", @@ -245,8 +247,6 @@ var EffectExemptions = map[string]string{ "events.reconnect": "daemon event buffer/reconnect behaviour: needs disconnect/reconnect timing the harness does not drive", "daemon.idleExit": "daemon lifecycle, binding, or timing: its effect is a bound, an interval, or a network identity the isolated harness cannot vary deterministically", "serve.mode": "serve mode selection: needs a client driving the alternate mode end-to-end, which no fixture does", - "catalog.pinnedTools": "catalog ranking/truncation: the fake server's tool set is too small for a budget or bias change to alter the listing observably", - "retention.maxTools": "retention window: its effect appears across call history and time, not within one run", "retention.stickyWindow": "retention window: its effect appears across call history and time, not within one run", "embeddings.backend": "embeddings backend: needs a live embeddings service or a wasm model fixture the harness does not provide", "embeddings.url": "embeddings backend: needs a live embeddings service or a wasm model fixture the harness does not provide", @@ -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 = 159 // Shrunk 2026-11-18 (#8473 chain 20): diagnose.history and diagnose.preflight gained schema-churn probes. Earlier shrunk 2026-11-18 (#8473 chain 19): events.history gained a trimmed-replay probe. Earlier 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. +const EffectExemptionPin = 157 // Shrunk 2026-11-18 (#8473 chain 21): catalog.pinnedTools and retention.maxTools gained reactive-session probes. Earlier shrunk 2026-11-18 (#8473 chain 20): diagnose.history and diagnose.preflight gained schema-churn probes. Earlier shrunk 2026-11-18 (#8473 chain 19): events.history gained a trimmed-replay probe. Earlier 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,