Title: mcpx testing: e2e inherits the caller's environment -- build it from an allowlist so tests never reach the user's daemon · Issue #1992 · developing-today/code · GitHub
Open Graph Title: mcpx testing: e2e inherits the caller's environment -- build it from an allowlist so tests never reach the user's daemon · Issue #1992 · developing-today/code
X Title: mcpx testing: e2e inherits the caller's environment -- build it from an allowlist so tests never reach the user's daemon · Issue #1992 · developing-today/code
Description: Relocated from dezren39/darwin-nix#138 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/ni...
Open Graph Description: Relocated from dezren39/darwin-nix#138 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc...
X Description: Relocated from dezren39/darwin-nix#138 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refe...
Opengraph URL: https://github.com/developing-today/code/issues/1992
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx testing: e2e inherits the caller's environment -- build it from an allowlist so tests never reach the user's daemon","articleBody":"Relocated from dezren39/nix#138 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #97\n\n## Summary\n\nThe e2e harness starts every test's environment from the developer's own `os.Environ()`, then overrides four variables. Anything else set in the caller's shell reaches the test binary. That includes `MCPX_DAEMON_ENDPOINT`, which the opencode mcpx plugin injects into every shell it opens. So an agent running `go test ./internal/e2e` inside opencode can point the suite at the user's real daemon. Separately, several code paths read `$HOME`/`XDG_*` directly, and the harness does not isolate those.\n\nThe fix: build the child environment from an **allowlist**, not by inheriting and overriding, and add a guard that catches new `MCPX_*` leaks. (The short autostart idle-exit this issue also asked for landed in #182, which fixed #52; the inheritance itself is untouched and is what remains.)\n\nThis is the precondition for \"very few shouldn't work if user has own real daemon running\" (#134): isolation has to be strong enough that \"very few\" is true.\n\n## Original notes\n\n> - testing\n> - a general goal is to ensure all features have one or more integration tests\n> - for both binary && app entrypoint (consider binary a superset)\n> - all tests should pass for nix flake & container\n> - all local also but may need impractical setup\n> - very few shouldn't work if user has own real daemon running\n\n## Current state (written on d0b7e01; re-checked at 05c78b2)\n\n`newEnv` (`internal/e2e/e2e_test.go:35-87` at 05c78b2) sets `envVars: append(os.Environ(), MCPX_REGISTRY_URL=..., MCPX_STATE_DIR=..., MCPX_CACHE_DIR=..., MCPX_CONFIG=..., MCPX_AUTOSTART_IDLE_EXIT=60s)` (`:52-69`). `os/exec` keeps the last value for a duplicated key, so these five win. **Everything else is still inherited** -- #182 added the fifth variable and changed the cleanup to `stop --all` with a logged error (`:71-85`), but did not touch the `os.Environ()` base. A developer's or agent's `MCPX_DAEMON_ENDPOINT`, `MCPX_SOCKET` or any other `MCPX_*` still reaches every test.\n\nThe table below comes from reading the code; the suite was not run for this issue. The first implementation step confirms these reads with a test.\n\n| Inherited from the caller | Effect in a test | Where read |\n| --- | --- | --- |\n| `MCPX_DAEMON_ENDPOINT` | every client command targets that daemon and refuses to start a local one | `daemon.endpoint`, `internal/settings/registry.go:350`. The plugin injects it into every opencode shell: `plugin/opencode/mcpx-session.ts:696-701` |\n| `MCPX_SOCKET` | replaces the socket path outright, for both bind and connect (its precedence over the info file is #88's to decide, #181 collision 8) | `internal/daemon/paths.go:103-105` |\n| any `MCPX_\u003cSETTING>` (derived from each setting's path, `internal/settings/schema.go:220-224`), e.g. `MCPX_SCRIPT_RUNTIME`, `MCPX_DAEMON_INLINE` | the test runs under the developer's settings, not the documented defaults | `settings.ApplyEnv`, `bind.go:163` |\n| `MCPX_SESSION_ID`, `MCPX_PARENT_SESSION_ID`, `MCPX_HARNESS_*` | session scoping and lease keys come from the outer agent session | several `internal/*` |\n| `HOME`, `XDG_CONFIG_HOME` | recipe dirs include the user's (`internal/cli/scripts.go:71-72`, `internal/daemon/consumer.go:141-142`, `internal/recipes/dirs.go:28`), so the user's real recipes can change `TestRecipesAreMatchedDeterministically`-style results. A `--persist user` or `servers add --scope user` test would write the user's real config (`internal/config/write.go:33-40`) | as listed |\n| `XDG_DATA_HOME`, `OPENCODE_DB` | the opencode v1 DB lookup finds the user's real `opencode.db` | `internal/opencode/opencode.go:35-50` |\n| `XDG_RUNTIME_DIR` | the fallback socket dir is shared with the user's daemons. The name is hashed per state dir (`paths.go:115-116`), so there is no collision; leaked test daemons used to accumulate there for hours (#52), and since #182 they idle out after 60 s | `paths.go:141-148` |\n| `XDG_STATE_HOME`/`XDG_CACHE_HOME` | masked, because `MCPX_STATE_DIR`/`MCPX_CACHE_DIR` win (`paths.go:36-45`) | -- |\n\nRelated, from #52 (closed, fixed in #182): `newEnv` now sets `autostart.idleExit` (`internal/settings/wire.go:135`) to 60 s through `MCPX_AUTOSTART_IDLE_EXIT` (`e2e_test.go:68`, `testIdleExit` at `:92`), and cleanup runs `mcpx stop --all` through the `daemon-\u003ckey>.json` info files, logging rather than discarding its error (`:71-85`). That bounds a leak; it does not stop a test from reaching the caller's daemon, which is this issue.\n\nThe **in-process** runner (#133) inherits all of this through `os.Getenv` in the same process. The fix below has to apply to both runners.\n\n## Approaches\n\n### A -- denylist: unset known-dangerous variables (least recommended)\nStrip `MCPX_DAEMON_ENDPOINT` and `MCPX_SOCKET` after `os.Environ()`. It is the smallest diff, and it fixes today's concrete hole. It fails open: every future `MCPX_*` setting, and every new `XDG_*`/`HOME` read, leaks again until someone notices. That is the pattern the history shows (#65 registry, #52 leaks). Not recommended as the end state.\n\n### B -- strip every `MCPX_*` and override `HOME`/`XDG_*`\nDrop every inherited variable that starts with `MCPX_`, and set `HOME`, `XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_STATE_HOME`, `XDG_CACHE_HOME` and `XDG_RUNTIME_DIR` under `e.dir` (short names, for the 100-byte socket cap, `paths.go:75`). This is robust against new settings. It still inherits unrelated variables: `DENO_DIR`, `BUN_INSTALL`, `NODE_OPTIONS`, `OPENCODE_*`, proxies. Some of those are wanted (runtime caches), some are not (`NODE_OPTIONS=--require ...`).\n\n### C -- allowlist plus a guard (recommended)\n- **Child environment** = an explicit allowlist from the parent: `PATH`, `TMPDIR`, `LANG`/`LC_*`, `TERM`, `SYSTEMROOT` (for Windows later, #136), and runtime cache dirs (`DENO_DIR`, `BUN_INSTALL_CACHE_DIR`, npm cache) so runs stay fast. Add B's `HOME`/`XDG_*` under `e.dir`, then the five variables `newEnv` already sets (including #182's `MCPX_AUTOSTART_IDLE_EXIT=60s`).\n- **Opt-in pass-through** for the rare test that needs the outer world: `e.inherit(\"NAME\")`. The tests labelled \"needs the user's default paths\" (#134, `RequireNoUserDaemon`) are the ones that use it.\n- **Guard test**, `TestTheHarnessInheritsNoMCPXVariable`. It sets `MCPX_DAEMON_ENDPOINT=http://127.0.0.1:1`, `MCPX_SOCKET=/nonexistent`, `MCPX_SCRIPT_RUNTIME=bogus` and `HOME=/nonexistent` in its own process (`t.Setenv`), builds an env, runs `mcpx doctor -v`, `mcpx settings list` and `mcpx recipes`, and asserts the output is local, default and home-free. This is the regression test that makes the fix stay fixed (#99: a test per bug, a guard per bug class). Make its variable list *derived*, not typed (from #162): enumerate the settings registry and require every `EnvName()` and `EnvAliases` entry (`internal/settings/schema.go:220-224,284`) to be either set by the harness or on an explicit safe-to-inherit list, so a new setting is covered the day it is added. Undeclared `MCPX_*` reads are not in the registry; take them from #172's allowlist once it lands rather than keeping a second list here.\n- **Backstop**: `TestMain` in `internal/e2e` fails fast, with a clear message, if the *parent* has `MCPX_DAEMON_ENDPOINT` or `MCPX_SOCKET` set and the allowlist is somehow bypassed. That turns a silent \"tests passed against the user's daemon\" into a loud failure.\n- **Machine-level check** (from #162): `TestMain` records `mcpx daemons` for the caller's real environment at start and end and fails on any difference. It is the one assertion of \"the suite does not disturb your machine\" that cannot rot, and it also catches a regression of #182's leak fix.\n\nRecommended because it fails closed. A new setting, or a new read of `$HOME`, is isolated by default, and the guard catches the regression if someone widens the allowlist.\n\n## Implementation steps\n\n1. Write the guard test first, expecting it to fail on main. That confirms the table above.\n2. Replace `append(os.Environ(), ...)` with the allowlist builder in `internal/testsupport` (shared with the plugin harness in #132 and the in-process runner in #133).\n3. ~~Add `MCPX_AUTOSTART_IDLE_EXIT=30s`, and record the `stop` error rather than discarding it (#52 fixes 1 and 2).~~ Done in #182 (60 s; `stop --all`, error logged).\n4. Add the `TestMain` backstop.\n\n## Open questions\n\n- Should a caller's `DENO_DIR`/bun cache be shared with tests (fast) or isolated (hermetic)? Proposal: shared on laptops, isolated in the container entry.\n- Does anything need `SSH_AUTH_SOCK`/git credentials? The `repo`/`worktree` scopes use git (`package.nix` comment), but only locally. (The GIT architect is replacing the `git` subprocess with native resolution in `internal/config/scope.go`; if that lands, `git` may drop out of the allowlist question entirely.)\n- Should the plugin's `shell.env` injection skip `go test` commands? No: the harness must be robust against any caller, and special-casing a command name in the plugin is the wrong layer.\n\n## Ease · Impact · Related\n\n**Ease** S-M · **Impact** high (a correctness hole in every e2e run started from opencode with the plugin, and the foundation for the \"user's daemon\" subset)\n**Depends on / related**: #52 (closed, fixed in #182 -- step 3 is done), #139 (this is the remaining precondition for `t.Parallel` in e2e), #88 (owns `MCPX_SOCKET` precedence, #181 collision 8), #172 (the undeclared `MCPX_*` allowlist the guard should reuse), #134 (the labelled subset; the `inline`/`spawn`/`remote` run modes), #133 (the in-process runner needs the same env), #132 (the plugin harness), #99 (guard-per-bug-class), #65 (the registry precedent for \"never the real thing\").\n\nSecurity/auth deferred; see tracker.\n\n## Acceptance criteria\n\n- The e2e harness builds the child environment from an allowlist (no inherited MCPX_* or caller daemon endpoints), a guard test catches new MCPX_* leaks, and CI is green.\n- The work described in the Summary/Scope above is delivered via a branch + PR (no direct push to main); verification runs in GitHub Actions CI, not on the sandbox.\n- Evidence (CI links, timings, or probe output as applicable) is recorded on this issue before it is closed.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:58:07Z","url":"https://github.com/developing-today/code/issues/1992"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c7132484-13ff-1c52-eec0-c376fa74f08e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAB0:74E58:12CB95:194CD0:6B061037 |
| html-safe-nonce | f96fd95bdb4c24b2f216404ad6b62e55a3c21661f19cea36535236083f0d11c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUIwOjc0RTU4OjEyQ0I5NToxOTRDRDA6NkIwNjEwMzciLCJ2aXNpdG9yX2lkIjoiMzQxMTU3NTI4OTAyODE1MzM5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7f6136b0d14d4da1b53d0aa648003a7bf622e4aa0d39e9150f4a17d7014f7b6b |
| hovercard-subject-tag | issue:6089047135 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1992/issue_layout |
| twitter:image | https://opengraph.githubassets.com/db8528ea607dbd2c51354c47a39c4627bc2f85438ece705f95eca192d90de752/developing-today/code/issues/1992 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/db8528ea607dbd2c51354c47a39c4627bc2f85438ece705f95eca192d90de752/developing-today/code/issues/1992 |
| og:image:alt | Relocated from dezren39/darwin-nix#138 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | e58943f0186bb8d97b217393c2724a49ab47e4aefefc43595a90fa04699066c9 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 23517473abc6d5da019b4958bd421644e98a418b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width