From 02b6933ba04697cb5df11721892f58b97a37442f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 01:34:01 -0600 Subject: [PATCH] test(mcpx): effect probe for plugin.headless (#8472) --- pkgs/mcpx/internal/e2e/effect_test.go | 2 + .../e2e/feature_coverage_exemptions.txt | 1 - pkgs/mcpx/internal/e2e/plugin_test.go | 34 +++ pkgs/mcpx/internal/settings/effect.go | 4 +- .../plugin/opencode/mcpx/headless.test.ts | 211 ++++++++++++++++++ 5 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 pkgs/mcpx/plugin/opencode/mcpx/headless.test.ts diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index e9c6f7d510..ea40fa0b3d 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -74,6 +74,7 @@ var implementedEffectProbes = map[string]string{ "plugin.tools": "TestPluginToolsRegistersTheToolSetFromTheEnvironment", "plugin.toolTiming": "TestPluginToolTimingRecordsToolCallsFromTheEnvironment", "plugin.remember": "TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment", + "plugin.headless": "TestPluginHeadlessSuppressesToastsFromTheEnvironment", "paths.state": "TestStateDirectoryIsReachableAsASetting", "paths.configFile": "TestPathsConfigFileChangesWhichConfigLoads", "paths.scripts": "TestPathsScriptsFindsRecipesThatLiveOnlyThere", @@ -305,6 +306,7 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestPluginToolsRegistersTheToolSetFromTheEnvironment": TestPluginToolsRegistersTheToolSetFromTheEnvironment, "TestPluginToolTimingRecordsToolCallsFromTheEnvironment": TestPluginToolTimingRecordsToolCallsFromTheEnvironment, "TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment": TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment, + "TestPluginHeadlessSuppressesToastsFromTheEnvironment": TestPluginHeadlessSuppressesToastsFromTheEnvironment, "TestPoolDefaultsAreReachableFromTheEnvironment": TestPoolDefaultsAreReachableFromTheEnvironment, "TestRegistryLimitReachesTheCLI": TestRegistryLimitReachesTheCLI, "TestRegistryPageSizeChangesWhatTheCLIAsksFor": TestRegistryPageSizeChangesWhatTheCLIAsksFor, diff --git a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt index a5a673d218..8a08ddb811 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -19,6 +19,5 @@ setting daemon.tsnetUpTimeout no integration-test exercise yet; burn-down #8468 setting http.streamBufferInit allocation-capacity hint only; output and line ceiling are unchanged, so allocation size has no stable e2e behavior oracle setting protoTasks.cancelGrace no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting plugin.disabledTools no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test -setting plugin.headless no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test setting plugin.instructions no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test setting embeddings.wasmPath embeddings backend: needs a compiled wasm model fixture the harness does not provide; no embed-exporting model ships with the repo diff --git a/pkgs/mcpx/internal/e2e/plugin_test.go b/pkgs/mcpx/internal/e2e/plugin_test.go index 88c08efe15..0880ce7aaa 100644 --- a/pkgs/mcpx/internal/e2e/plugin_test.go +++ b/pkgs/mcpx/internal/e2e/plugin_test.go @@ -395,3 +395,37 @@ func TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment(t *testing t.Fatalf("the plugin.remember probe did not report a clean run:\n%s", out) } } + +// TestPluginHeadlessSuppressesToastsFromTheEnvironment is the effect +// probe for plugin.headless (#8472; the effect guard is #1971). +// +// The setting's whole effect lives in the opencode plugin host: when +// discovery cannot settle on one daemon, the session plugin warns +// the user with a toast — unless headless is set (MCPX_PLUGIN_HEADLESS +// or the plugin option), because showToast succeeds whether or not +// anyone is watching and a toast nobody can see is a leak, not a +// notification. No Go caller produces the toast, so the probe drives +// the host the way the plugin suite does — bun, the real session +// plugin, two fake daemons on real sockets so boot discovery is +// ambiguous — and the bun cases in +// plugin/opencode/mcpx/headless.test.ts assert the observable +// with/without difference: the warning toast arrives when headless +// is cleared and never when it is set. A run that skipped the cases +// is a run that did not check what this probe exists to check, so +// skips fail it, as in TestThePluginSuiteRunsAgainstARealDaemon. +func TestPluginHeadlessSuppressesToastsFromTheEnvironment(t *testing.T) { + bun := testsupport.RequireBinary(t, "bun") + recordSettingProbes(t) + cmd := exec.Command(bun, "test", "plugin/opencode/mcpx/headless.test.ts") + cmd.Dir = repoRoot(t) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("bun test plugin/opencode/mcpx/headless.test.ts: %v\n%s", err, out) + } + if strings.Contains(string(out), " skip") && !strings.Contains(string(out), " 0 skip") { + t.Fatalf("the plugin.headless probe cases were skipped:\n%s", out) + } + if !strings.Contains(string(out), " 0 fail") { + t.Fatalf("the plugin.headless probe did not report a clean run:\n%s", out) + } +} diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index a516f97ae0..3101fc99a6 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -60,6 +60,7 @@ var EffectProbes = map[string]string{ "plugin.daemonTools": "TestPluginDaemonToolsAreOfferedFromTheEnvironment", "plugin.discoveryRetry": "TestPluginDiscoveryRetryDelaysRediscoveryFromTheEnvironment", "plugin.env": "TestPluginEnvLevelChangesShellEnvFromTheEnvironment", + "plugin.headless": "TestPluginHeadlessSuppressesToastsFromTheEnvironment", "plugin.tools": "TestPluginToolsRegistersTheToolSetFromTheEnvironment", "plugin.toolTiming": "TestPluginToolTimingRecordsToolCallsFromTheEnvironment", "plugin.remember": "TestPluginRememberScopePersistsTheDaemonChoiceFromTheEnvironment", @@ -282,7 +283,6 @@ var EffectExemptions = map[string]string{ "embeddings.wasmPath": "embeddings backend: needs a compiled wasm model fixture the harness does not provide; the Go wasm runtime (wazero) can compile a module but no embed-exporting model ships with the repo, so the setting's effect (wasm embedder availability) is not observable end to end", "daemon.inlineStartPoll": "daemon lifecycle, binding, or timing: its effect is a bound, an interval, or a network identity the isolated harness cannot vary deterministically", "plugin.instructions": "read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host", - "plugin.headless": "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.cancelGrace": "task-store cancellation timing: covered by internal/tasks store tests, not by a settings with/without probe", } @@ -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 = 9 // Shrunk 2026-11-23 (#8472): plugin.remember now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.toolTiming now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.discoveryRetry now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.tools now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.daemonTools now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.binArgs now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.env now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.bin now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.backend now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.annotate now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-22 (#8474): script.importsOnMissing + script.importsNetwork now have e2e probes. Shrunk 2026-11-22 (#8474): script.importsCrossProject + script.checkOnError. Shrunk 2026-11-21 (#8469): idle connection limits and timeout now assert actual connection reuse/expiry through configured clients. Shrunk 2026-11-21 (#8470): retention.stickyWindow now expires requested tools after its configured window. Earlier shrunk 2026-11-21 (#8470): events.reconnect now asserts retry delay after a dropped connection. Earlier shrunk 2026-11-21 (#8470): deps.autoInstall now asserts Bun's selected install policy. Earlier shrunk 2026-11-19 (#8467): output.color now has a PTY-backed interactive TUI probe. Earlier shrunk 2026-11-18 (#8473 chain 73): script.checkOnUnsupported is now probed under bun. Earlier shrunk 2026-11-18 (#8473 chain 72): daemon.takeoverTimeout gained a probe with a successor whose takeover dial cannot finish. Earlier shrunk 2026-11-18 (#8473 chain 71): daemon.socketProbeTimeout gained a probe with a second daemon started beside a live one. Earlier shrunk 2026-11-18 (#8473 chain 70): logging.maxAge gained a probe with a log file whose first record is two hours old. Earlier shrunk 2026-11-18 (#8473 chain 69): logstore.followBacklog gained a follow probe with a burst between two polls. Earlier shrunk 2026-11-18 (#8473 chain 68): paths.config gained a probe with a config planted only on the named path. Earlier shrunk 2026-11-18 (#8473 chain 67): script.importsOnDynamic and script.imports gained probes with a computed import() in exec source text, which needs no Deno graph. Earlier shrunk 2026-11-18 (#8473 chain 66): prompt.runTimeout gained a probe with a recipe that sleeps past a 1s bound. Earlier shrunk 2026-11-18 (#8473 chain 65): daemon.roots gained a probe through the ask fixture's new need_roots tool. Earlier shrunk 2026-11-18 (#8473 chain 64): prompt.sampleTimeout was orphaned since #2004; it is now the sampling question fallback when model.timeout is unset, and gained a probe. Earlier shrunk 2026-11-18 (#8473 chain 63): prompt.sample and prompt.catalogBudget gained probes on an unmatched prompt, the latter against the fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 62): search.semantic and the remote embeddings settings gained probes against a fake OpenAI-compatible embeddings endpoint. Earlier shrunk 2026-11-18 (#8473 chain 61): proto.samplingPerMinute, proto.samplingSessionPerMinute and proto.elicitationPerMinute gained rate-limit probes driven by the ask fixture. Earlier shrunk 2026-11-18 (#8473 chain 60): sampling.answerLocally gained an upstream-sampling probe against the fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 59): model.provider, baseURL, default, apiKeyEnv, budget, providers, profiles, timeout and prompt.maxTokens gained prompt-hook probes against a fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 58): session.releaseTimeout gained an end-of-run release probe. Earlier shrunk 2026-11-18 (#8473 chain 57): daemon.idleExit gained an idle-daemon probe. Earlier shrunk 2026-11-18 (#8473 chain 56): daemon.port gained a bound-port probe. Earlier shrunk 2026-11-18 (#8473 chain 55): daemon.saveInterval gained a lease-table save probe. Earlier shrunk 2026-11-18 (#8473 chain 54): autostart.pollInterval gained a readiness-poll probe. Earlier shrunk 2026-11-18 (#8473 chain 53): daemon.leaseTTL gained a silent-caller probe. Earlier shrunk 2026-11-18 (#8473 chain 52): elicit.disambiguate and elicit.disambiguateDefault gained probes. Earlier shrunk 2026-11-18 (#8473 chain 51): elicit.ttl and elicit.maxAge gained probes, once upstream questions took their deadline from the broker. Earlier shrunk 2026-11-18 (#8473 chain 50): elicit.pendingLimit gained a probe, once `mcpx elicit list` honoured it. Earlier shrunk 2026-11-18 (#8473 chain 49): elicit.askTimeout gained a held-confirmation probe. Earlier shrunk 2026-11-18 (#8473 chain 48): artifacts.idleTtl and artifacts.maxAge gained touch-on-read probes. Earlier shrunk 2026-11-18 (#8473 chain 47): artifacts.ttl, artifacts.gcInterval, pool.min and autostart.idleExit gained probes. Earlier shrunk 2026-11-18 (#8473 chain 46): daemon.warm, pool.idleTimeout, daemon.reapInterval and daemon.endpoint gained probes. Earlier shrunk 2026-11-18 (#8473 chain 45): upstream.probeTimeout gained a probe, and upstream.eraCache and upstream.protocol were mapped to the era test, whose subtests run each with and without. Earlier shrunk 2026-11-18 (#8473 chain 44): prompt.autonomy, hooks.autonomy and repair.autonomy gained probes. Earlier shrunk 2026-11-18 (#8473 chain 43): policy.write, elicit.confirmDestructive and autonomy.max gained probes. Earlier shrunk 2026-11-18 (#8473 chain 42): daemon.inline, autostart.bin, autostart.args, autostart.logTail and daemon.watchConfig gained probes. Earlier shrunk 2026-11-18 (#8473 chain 41): daemon.inlineStartTimeout and daemon.probeTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 40): daemon.warmTimeout, autostart.connectTimeout and autostart.pingTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 39): pool.callTimeout, pool.startTimeout and daemon.refreshTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 38): doctor.timeout and registry.timeout gained probes that set a bound no request can meet. Earlier shrunk 2026-11-18 (#8473 chain 37): completion.maxValues gained a probe once the fake server could answer completions. Earlier shrunk 2026-11-18 (#8473 chain 36): catalog.instructions gained a probe once the fake server could serve instructions. Earlier shrunk 2026-11-18 (#8473 chain 35): the five plumbing source and launcher switches gained probes. Earlier shrunk 2026-11-18 (#8473 chain 34): artifacts.chunkBytes, script.launcher and paths.placeholders gained probes. Earlier shrunk 2026-11-18 (#8473 chain 33): artifacts.interceptImages and plumbing.indexOnQuery gained probes. Earlier shrunk 2026-11-18 (#8473 chain 32): plumbing.validatePaths and script.language gained probes. Earlier shrunk 2026-11-18 (#8473 chain 31): logging.trace and exec.where gained probes. Earlier shrunk 2026-11-18 (#8473 chain 30): paths.adapters and paths.apis gained declaration-file probes. Earlier shrunk 2026-11-18 (#8473 chain 29): script.runtime, runtimeOrder, permissions, profiles and runtimes gained node-backed probes. Earlier shrunk 2026-11-18 (#8473 chain 28): script.before, onSuccess, onError and suffix gained a run-phase probe. Earlier shrunk 2026-11-18 (#8473 chain 27): hooks, hooks.timeout, daemon.ui and daemon.uiDir gained probes. Earlier shrunk 2026-11-18 (#8473 chain 26): logging.level, format, source, dir, include, maxLines, maxBytes and keep gained durable-log probes. Earlier shrunk 2026-11-18 (#8473 chain 25): artifacts.enabled, maxBytes, quota, delivery, inlineMaxBytes and dir gained script-artifact probes. Earlier shrunk 2026-11-18 (#8473 chain 24): preset and serve.mode gained probes. Earlier shrunk 2026-11-18 (#8473 chain 23): presets gained a --preset probe. Earlier shrunk 2026-11-18 (#8473 chain 22): catalog.budget and catalog.bias gained `mcpx catalog` probes. Earlier 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. +const EffectExemptionPin = 8 // Shrunk 2026-11-23 (#8472): plugin.headless now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.remember now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.toolTiming now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.discoveryRetry now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.tools now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.daemonTools now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.binArgs now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.env now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.bin now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.backend now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-23 (#8472): plugin.annotate now has an e2e probe that drives the plugin host under bun. Shrunk 2026-11-22 (#8474): script.importsOnMissing + script.importsNetwork now have e2e probes. Shrunk 2026-11-22 (#8474): script.importsCrossProject + script.checkOnError. Shrunk 2026-11-21 (#8469): idle connection limits and timeout now assert actual connection reuse/expiry through configured clients. Shrunk 2026-11-21 (#8470): retention.stickyWindow now expires requested tools after its configured window. Earlier shrunk 2026-11-21 (#8470): events.reconnect now asserts retry delay after a dropped connection. Earlier shrunk 2026-11-21 (#8470): deps.autoInstall now asserts Bun's selected install policy. Earlier shrunk 2026-11-19 (#8467): output.color now has a PTY-backed interactive TUI probe. Earlier shrunk 2026-11-18 (#8473 chain 73): script.checkOnUnsupported is now probed under bun. Earlier shrunk 2026-11-18 (#8473 chain 72): daemon.takeoverTimeout gained a probe with a successor whose takeover dial cannot finish. Earlier shrunk 2026-11-18 (#8473 chain 71): daemon.socketProbeTimeout gained a probe with a second daemon started beside a live one. Earlier shrunk 2026-11-18 (#8473 chain 70): logging.maxAge gained a probe with a log file whose first record is two hours old. Earlier shrunk 2026-11-18 (#8473 chain 69): logstore.followBacklog gained a follow probe with a burst between two polls. Earlier shrunk 2026-11-18 (#8473 chain 68): paths.config gained a probe with a config planted only on the named path. Earlier shrunk 2026-11-18 (#8473 chain 67): script.importsOnDynamic and script.imports gained probes with a computed import() in exec source text, which needs no Deno graph. Earlier shrunk 2026-11-18 (#8473 chain 66): prompt.runTimeout gained a probe with a recipe that sleeps past a 1s bound. Earlier shrunk 2026-11-18 (#8473 chain 65): daemon.roots gained a probe through the ask fixture's new need_roots tool. Earlier shrunk 2026-11-18 (#8473 chain 64): prompt.sampleTimeout was orphaned since #2004; it is now the sampling question fallback when model.timeout is unset, and gained a probe. Earlier shrunk 2026-11-18 (#8473 chain 63): prompt.sample and prompt.catalogBudget gained probes on an unmatched prompt, the latter against the fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 62): search.semantic and the remote embeddings settings gained probes against a fake OpenAI-compatible embeddings endpoint. Earlier shrunk 2026-11-18 (#8473 chain 61): proto.samplingPerMinute, proto.samplingSessionPerMinute and proto.elicitationPerMinute gained rate-limit probes driven by the ask fixture. Earlier shrunk 2026-11-18 (#8473 chain 60): sampling.answerLocally gained an upstream-sampling probe against the fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 59): model.provider, baseURL, default, apiKeyEnv, budget, providers, profiles, timeout and prompt.maxTokens gained prompt-hook probes against a fake model endpoint. Earlier shrunk 2026-11-18 (#8473 chain 58): session.releaseTimeout gained an end-of-run release probe. Earlier shrunk 2026-11-18 (#8473 chain 57): daemon.idleExit gained an idle-daemon probe. Earlier shrunk 2026-11-18 (#8473 chain 56): daemon.port gained a bound-port probe. Earlier shrunk 2026-11-18 (#8473 chain 55): daemon.saveInterval gained a lease-table save probe. Earlier shrunk 2026-11-18 (#8473 chain 54): autostart.pollInterval gained a readiness-poll probe. Earlier shrunk 2026-11-18 (#8473 chain 53): daemon.leaseTTL gained a silent-caller probe. Earlier shrunk 2026-11-18 (#8473 chain 52): elicit.disambiguate and elicit.disambiguateDefault gained probes. Earlier shrunk 2026-11-18 (#8473 chain 51): elicit.ttl and elicit.maxAge gained probes, once upstream questions took their deadline from the broker. Earlier shrunk 2026-11-18 (#8473 chain 50): elicit.pendingLimit gained a probe, once `mcpx elicit list` honoured it. Earlier shrunk 2026-11-18 (#8473 chain 49): elicit.askTimeout gained a held-confirmation probe. Earlier shrunk 2026-11-18 (#8473 chain 48): artifacts.idleTtl and artifacts.maxAge gained touch-on-read probes. Earlier shrunk 2026-11-18 (#8473 chain 47): artifacts.ttl, artifacts.gcInterval, pool.min and autostart.idleExit gained probes. Earlier shrunk 2026-11-18 (#8473 chain 46): daemon.warm, pool.idleTimeout, daemon.reapInterval and daemon.endpoint gained probes. Earlier shrunk 2026-11-18 (#8473 chain 45): upstream.probeTimeout gained a probe, and upstream.eraCache and upstream.protocol were mapped to the era test, whose subtests run each with and without. Earlier shrunk 2026-11-18 (#8473 chain 44): prompt.autonomy, hooks.autonomy and repair.autonomy gained probes. Earlier shrunk 2026-11-18 (#8473 chain 43): policy.write, elicit.confirmDestructive and autonomy.max gained probes. Earlier shrunk 2026-11-18 (#8473 chain 42): daemon.inline, autostart.bin, autostart.args, autostart.logTail and daemon.watchConfig gained probes. Earlier shrunk 2026-11-18 (#8473 chain 41): daemon.inlineStartTimeout and daemon.probeTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 40): daemon.warmTimeout, autostart.connectTimeout and autostart.pingTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 39): pool.callTimeout, pool.startTimeout and daemon.refreshTimeout gained probes. Earlier shrunk 2026-11-18 (#8473 chain 38): doctor.timeout and registry.timeout gained probes that set a bound no request can meet. Earlier shrunk 2026-11-18 (#8473 chain 37): completion.maxValues gained a probe once the fake server could answer completions. Earlier shrunk 2026-11-18 (#8473 chain 36): catalog.instructions gained a probe once the fake server could serve instructions. Earlier shrunk 2026-11-18 (#8473 chain 35): the five plumbing source and launcher switches gained probes. Earlier shrunk 2026-11-18 (#8473 chain 34): artifacts.chunkBytes, script.launcher and paths.placeholders gained probes. Earlier shrunk 2026-11-18 (#8473 chain 33): artifacts.interceptImages and plumbing.indexOnQuery gained probes. Earlier shrunk 2026-11-18 (#8473 chain 32): plumbing.validatePaths and script.language gained probes. Earlier shrunk 2026-11-18 (#8473 chain 31): logging.trace and exec.where gained probes. Earlier shrunk 2026-11-18 (#8473 chain 30): paths.adapters and paths.apis gained declaration-file probes. Earlier shrunk 2026-11-18 (#8473 chain 29): script.runtime, runtimeOrder, permissions, profiles and runtimes gained node-backed probes. Earlier shrunk 2026-11-18 (#8473 chain 28): script.before, onSuccess, onError and suffix gained a run-phase probe. Earlier shrunk 2026-11-18 (#8473 chain 27): hooks, hooks.timeout, daemon.ui and daemon.uiDir gained probes. Earlier shrunk 2026-11-18 (#8473 chain 26): logging.level, format, source, dir, include, maxLines, maxBytes and keep gained durable-log probes. Earlier shrunk 2026-11-18 (#8473 chain 25): artifacts.enabled, maxBytes, quota, delivery, inlineMaxBytes and dir gained script-artifact probes. Earlier shrunk 2026-11-18 (#8473 chain 24): preset and serve.mode gained probes. Earlier shrunk 2026-11-18 (#8473 chain 23): presets gained a --preset probe. Earlier shrunk 2026-11-18 (#8473 chain 22): catalog.budget and catalog.bias gained `mcpx catalog` probes. Earlier 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, diff --git a/pkgs/mcpx/plugin/opencode/mcpx/headless.test.ts b/pkgs/mcpx/plugin/opencode/mcpx/headless.test.ts new file mode 100644 index 0000000000..123fcba935 --- /dev/null +++ b/pkgs/mcpx/plugin/opencode/mcpx/headless.test.ts @@ -0,0 +1,211 @@ +/** + * plugin.headless, observed through the real boot toast (#8472). + * + * The headless setting — MCPX_PLUGIN_HEADLESS, or the plugin's + * headless option — decides whether the session plugin may put a + * toast on the user's screen. mcpx-session.ts reads it once at load + * (option, then environment, then a process-shape default: a server + * running on the main thread has no TUI attached) and the toast + * helper returns before touching the client when it is set, because + * `showToast` succeeds whether or not anyone is watching — an + * unbounded toast in CI is a silent leak, not a visible one. + * + * The cases make the boot toast fire on purpose: two fake daemons + * on real unix sockets both match the directory and neither has a + * resolve route, so discovery ends at rung 6 — a guess, announced + * with a warning toast (the daemon.test.ts arrangement). The setting + * is then the only thing that differs, and the stub client's + * showToast calls are the observable: with headless set, none; with + * it cleared, the warning arrives. The Go effect probe for the + * setting (TestPluginHeadlessSuppressesToastsFromTheEnvironment in + * internal/e2e) runs this file. + * + * bun test plugin/opencode/mcpx/headless.test.ts + */ +import { afterEach, describe, expect, mock, test } from "bun:test"; +import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +import { OPERATION_FINGERPRINT } from "../../core/ops.gen.ts"; +import type { DaemonInfo } from "../../core/daemon.ts"; + +// The plugin package has no installed node_modules in the repo +// checkout; only the `tool` helper is needed to build the hooks. +const schemaStub: any = new Proxy(function () {}, { + get: () => schemaStub, + apply: () => schemaStub, +}); +mock.module("@opencode-ai/plugin", () => ({ + tool: Object.assign((x: unknown) => x, { schema: schemaStub }), +})); +// @ts-ignore: the session plugin exports only its default (loader glob). +const plugin = (await import("../mcpx-session.ts")).default; + +// Captured before any test runs: tmpdir() reads TMPDIR, and the +// environment restore below must not strand it. +const REAL_TMP = tmpdir(); +const scratch: string[] = []; +const stopAll: Array<() => void> = []; +const savedEnv = { ...process.env }; +afterEach(() => { + while (stopAll.length) stopAll.pop()!(); + // Restore in place, on the original process.env object (the + // env.test.ts pattern): replacing process.env wholesale does not + // restore the native environment other code reads. + for (const key of Object.keys(process.env)) { + if (!(key in savedEnv)) delete process.env[key]; + } + Object.assign(process.env, savedEnv); + for (const dir of scratch.splice(0)) rmSync(dir, { recursive: true, force: true }); +}); + +const tempRoot = (): string => { + const dir = mkdtempSync(join(REAL_TMP, "mcpxt-headless-")); + scratch.push(dir); + return dir; +}; + +/** A fake daemon on a real unix socket: health and status, no resolve route. */ +const serveFake = (socket: string, config: string, servers: number): void => { + const server = Bun.serve({ + unix: socket, + fetch(req) { + const url = new URL(req.url); + if (url.pathname === "/v1/health") { + return Response.json({ + status: "ok", + version: "test", + pid: 1, + operationFingerprint: OPERATION_FINGERPRINT, + }); + } + if (url.pathname === "/v1/status") { + return Response.json({ + version: "test", + operationFingerprint: OPERATION_FINGERPRINT, + pid: 1, + socket, + config, + servers: Array.from({ length: servers }, (_, i) => ({ + name: `s${i}`, + live: 1, + instances: [{ key: `ses-${i}` }], + })), + }); + } + return new Response("not found", { status: 404 }); + }, + }); + stopAll.push(() => server.stop(true)); +}; + +const writeInfo = (state: string, key: string, info: DaemonInfo): void => { + writeFileSync(join(state, `daemon-${key}.json`), JSON.stringify(info, null, 2)); +}; + +type ToastCall = { body?: { title?: string; message?: string; variant?: string } }; + +/** + * Load the session plugin over a state directory holding two live + * daemons that both match the session directory, so boot discovery + * is ambiguous and the boot warning toast is due. `setEnv` runs + * before the load (the setting is read from the environment at load + * time); `options` are the plugin options. Returns every showToast + * call the stub client received. + */ +const loadWithAmbiguousBoot = async ( + setEnv: () => void, + options: Record, +): Promise => { + const root = tempRoot(); + const state = join(root, "state"); + mkdirSync(state); + const proj = join(root, "proj"); + const dir = join(proj, "sub"); + mkdirSync(dir, { recursive: true }); + + const mine = join(state, "d-mine.sock"); + const other = join(state, "d-other.sock"); + serveFake(mine, join(proj, ".mcpx.json"), 1); + serveFake(other, join(root, "elsewhere", ".mcpx.json"), 9); + writeInfo(state, "mine", { + socket: mine, + configPath: join(proj, ".mcpx.json"), + startedAt: new Date(Date.now() - 86_400_000).toISOString(), + }); + writeInfo(state, "other", { + socket: other, + configPath: join(root, "elsewhere", ".mcpx.json"), + startedAt: new Date().toISOString(), + }); + + // Isolate discovery: this state directory and temp root only, no + // named endpoint, and no binary for the ladder's CLI rung to ask. + process.env.MCPX_STATE_DIR = state; + process.env.TMPDIR = root; + delete process.env.MCPX_DAEMON_ENDPOINT; + delete process.env.MCPX_ENDPOINT; + delete process.env.MCPX_SOCKET; + process.env.MCPX_PLUGIN_BIN = ""; + setEnv(); + + const toasts: ToastCall[] = []; + const client = { + session: { + get: async () => ({ data: { id: "ses_1", directory: dir, time: { created: Date.now() } } }), + }, + tui: { + showToast: async (arg: ToastCall) => { + toasts.push(arg); + }, + }, + }; + await (plugin as any)({ directory: dir, worktree: proj, project: { id: "p1" }, client }, options); + // The boot toast is fire-and-forget; let it land before counting. + await new Promise((resolve) => setTimeout(resolve, 25)); + return toasts; +}; + +describe("plugin.headless and the boot toast", () => { + test("MCPX_PLUGIN_HEADLESS=1 suppresses the boot warning toast", async () => { + const toasts = await loadWithAmbiguousBoot(() => { + process.env.MCPX_PLUGIN_HEADLESS = "1"; + }, {}); + expect(toasts).toHaveLength(0); + }); + + test("the headless option suppresses the boot warning toast", async () => { + const toasts = await loadWithAmbiguousBoot(() => { + delete process.env.MCPX_PLUGIN_HEADLESS; + }, { headless: true }); + expect(toasts).toHaveLength(0); + }); + + test("headless cleared by option lets the boot warning toast through", async () => { + const toasts = await loadWithAmbiguousBoot(() => { + delete process.env.MCPX_PLUGIN_HEADLESS; + }, { headless: false }); + expect(toasts.length).toBeGreaterThanOrEqual(1); + expect(toasts[0].body?.message).toContain("2 daemons"); + }); + + test("MCPX_PLUGIN_HEADLESS=0 lets the boot warning toast through", async () => { + const toasts = await loadWithAmbiguousBoot(() => { + process.env.MCPX_PLUGIN_HEADLESS = "0"; + }, {}); + expect(toasts.length).toBeGreaterThanOrEqual(1); + expect(toasts[0].body?.message).toContain("2 daemons"); + }); + + test("unset everywhere defaults to headless in this process shape", async () => { + // No option and no environment: the default is the process + // shape, and a test runner's server thread has no TUI attached, + // so the default reads headless and the toast stays down. This + // is the CI case the setting exists for. + const toasts = await loadWithAmbiguousBoot(() => { + delete process.env.MCPX_PLUGIN_HEADLESS; + }, {}); + expect(toasts).toHaveLength(0); + }); +});