Title: mcpx testing: an in-process app entrypoint beside the binary suite, and a scriptable mock MCP server · Issue #1980 · developing-today/code · GitHub
Open Graph Title: mcpx testing: an in-process app entrypoint beside the binary suite, and a scriptable mock MCP server · Issue #1980 · developing-today/code
X Title: mcpx testing: an in-process app entrypoint beside the binary suite, and a scriptable mock MCP server · Issue #1980 · developing-today/code
Description: Relocated from dezren39/darwin-nix#133 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#133 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#133 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/1980
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx testing: an in-process app entrypoint beside the binary suite, and a scriptable mock MCP server","articleBody":"Relocated from dezren39/nix#133 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\nToday every e2e test runs `mcpx` as a subprocess. This issue proposes an in-process entrypoint alongside it: move the dispatch in `cmd/mcpx/main.go` into `cli.Run(ctx, args, env, stdio) int`. Then run most integration tests in-process, which is faster, gives coverage, and lets you set breakpoints. Keep a binary suite as a superset that also covers what only a real process has: signals, exit codes, argv parsing, the detached daemon, and the nix wrapper. Let the binary suite point at a **prebuilt** binary (the nix `result`, a container image), not only at a fresh `go build`. Separately, replace the fixed-behaviour `fakemcp` with a scriptable mock so each test states the server behaviour it needs.\n\n## Original notes\n\n> - testing\n> - a general goal is to ensure all features have one or more integration tests\n> - the mcp servers can be specialized mocks but the app entrypoint or binary is used and config is passed in or config path set to appropriate test\n> - for both binary && app entrypoint (consider binary a superset)\n> - all tests should pass for nix flake & container\n\n## Current state (main d0b7e01)\n\n**Binary.**\n- `testsupport.MCPXBinary` always runs `go build -o \u003ctmp>/mcpx ./cmd/mcpx` once per test binary (`internal/testsupport/build.go:54-73`).\n- **No override exists** to test a prebuilt binary. So in CI \"the binary\" means a fresh plain `go build`, never the artifact users install. The installed artifact is `result/bin/mcpx`: a `makeBinaryWrapper` C wrapper that puts nix-pinned git/deno/bun/node on PATH (`package.nix` `postInstall`) in front of `.mcpx-wrapped`. There is now a second shipped artifact, the binary inside #182's `pkgs/mcpx/Containerfile` image.\n- So there are three drivers, not two (from #160): in-process ⊂ built binary ⊂ installed output. Only the installed output exercises the wrapper's PATH pinning, the ldflags version (`internal/testsupport/build.go:63` builds without `-ldflags`, so `mcpx --version` differs between the test binary and the package -- #178), the generated man page and the completions. That rung should be a small suite -- a dozen assertions, not the whole e2e run -- and it is where #134's nix-build leg and #178's assertions run.\n- The temp dirs from `os.MkdirTemp` (`build.go:28,56`) are never removed.\n\n**Entrypoint.** `main()` (`cmd/mcpx/main.go:52-204`) does all of the following, and none of it is reachable from a test:\n- reads `os.Args`;\n- handles global flags inline (`--json`, `--profile`, `--config`, `--tui`, ...);\n- builds `&cli.App{Version, Paths: daemon.ResolvePaths()}`;\n- sets the package global `cli.SetPlumbingSource(app)` (`internal/cli/scripts.go:95`);\n- dispatches through a local `handlers` map (`main.go:119-162`);\n- exits through `os.Exit` at five sites (`main.go:74,103,179,188,202`).\n\nProcess-global state that an in-process runner would share between tests:\n- `daemon.ResolvePaths` reads `os.Getenv` (`internal/daemon/paths.go:34-52`);\n- `settings.Environ()` is `os.Environ()` (`internal/settings/bind.go:218`);\n- `internal/cli` non-test files reference `os.Stdout/Stderr/Stdin/Exit/Getenv` 86 times.\n\n**Autostart re-executes itself.** `EnsureDaemon` spawns `autostart.bin` or, if that is unset, `os.Executable()` (`internal/cli/client.go:281-287`). In-process, `os.Executable()` is the **test binary**, which would be started as a \"daemon\". An in-process runner must set `autostart.bin` to the built mcpx, or use `daemon.inline=true` (`internal/settings/registry.go:379`).\n\n**Mocks.**\n- `fakemcp` (`internal/testsupport/fakemcp/main.go`, 321 lines) answers from compiled-in behaviour, with two knobs: `FAKEMCP_FAIL_START` and `FAKEMCP_START_DELAY` (`main.go:35,39`).\n- `askmcp` (272 lines) exists separately for elicitation (`build_proto.go:19-39`).\n- A new behaviour means editing a shared binary that every test uses.\n\n**Config.** Each test writes `.mcpx.json` into its temp dir, with `FAKE` replaced by the fakemcp path, and sets `MCPX_CONFIG` (`internal/e2e/e2e_test.go:41-60`). That already matches \"config path set to appropriate test\". \"Config passed in\" (`--config`, `main.go:88-94`) is a separate path that nothing tests specifically.\n\n**Coverage.** e2e contributes nothing to coverage, because the binary is built without `-cover`. Since Go 1.20, `go build -cover` produces a binary that writes coverage data to `$GOCOVERDIR` on exit. `go tool covdata percent|textfmt -i=\u003cdir>` reads it, and `go test -cover ./... -args -test.gocoverdir=\u003cdir>` writes unit coverage into the same directory so the two merge. Source: https://go.dev/doc/build-cover. A process killed by a signal writes nothing, so a detached daemon killed by `stop` must exit through its normal path for its coverage to count.\n\n## Approaches -- entrypoint\n\n### A -- in-process only (least recommended)\nReplace the subprocess with `cli.Run` everywhere. This is the fastest option, and it loses exactly what an integration test is for:\n- real exit codes and signal handling (`signal.NotifyContext`, `main.go:53`);\n- argv parsing as the shell delivers it;\n- the detached daemon (`Setsid`, `client.go:312`);\n- the process-group kill of runtimes (`runner.go:413-432`);\n- the nix wrapper's PATH;\n- environment inheritance: #138 is a bug that exists *only* in the subprocess path.\n\nShared process globals would also make in-process tests interfere with each other. Not recommended.\n\n### B -- binary only, instrumented\nKeep today's suite and add two things: a `-cover` build of the binary under `$GOCOVERDIR`, and an override (`MCPX_TEST_BINARY=/path/to/mcpx`, name to be decided) so the same suite runs against `result/bin/mcpx` or inside a container. It needs almost no code change, gives coverage, and makes \"tests pass for nix flake & container\" mean the shipped artifact (#134). It does not help speed (each call still pays a fork+exec plus daemon start) or debugging (a breakpoint in a subprocess needs `dlv attach`).\n\n### C -- both, with the binary suite as a superset (recommended)\n1. **Refactor**: `func Run(ctx context.Context, args []string, env Env, stdio Stdio) int` in `internal/cli`, where `Env` is an environ slice or lookup function and `Stdio` is `{In io.Reader; Out, Err io.Writer}`. `main()` shrinks to signal setup plus `os.Exit(cli.Run(ctx, os.Args[1:], os.Environ(), cli.Stdio{...}))`. Global-flag parsing, `looksRunnable` and the `handlers` table move with it. The table becomes an exported `cli.Commands()`, which #132's guard needs.\n2. **Thread the environment in stages.** Stage 1: `Run` takes `env` but internals still read `os.Getenv`, so in-process tests use `t.Setenv` and cannot use `t.Parallel`. Stage 2: `ResolvePaths`, `settings.Environ` and `plumbingApp` take their inputs from `Run`, so in-process tests can run in parallel. That is the real speed gain, and it pairs with the CI time budget in #95.\n3. **Harness**: `newEnv` gets a `runner` interface with `binary` and `inproc` implementations. A test says what it needs, for example `e := newEnv(t, cfg, needsProcess)`. The **binary suite runs every test** (the superset). The in-process suite runs the ones that do not need a process. The daemon stays a real process in both, via `autostart.bin` set to the built binary. An in-process daemon in a goroutine would leak goroutines and listeners between tests, which is the in-process version of #52 (fixed for the subprocess path in #182).\n4. **Binary override and `-cover`** from B, so the binary suite can target the nix result or a container image and produce coverage.\n\nRecommended because it matches the notes (binary a superset) and makes the fast path the default for day-to-day agent runs (#99). It also avoids building a second harness. Its risk is the size of the refactor. Stage 1 is small; stage 2 touches every `os.Getenv` in `internal/cli` and `internal/daemon`.\n\nThe user's framing is right. One refinement: \"app entrypoint\" should mean `cli.Run`, **not** `cli.App` methods called directly. Calling `app.CmdExec` directly skips global-flag parsing and `SettingsErr` (`main.go:183-189`), so it would test a code path users never take.\n\n## Approaches -- mock MCP servers\n\n### A -- ad-hoc mocks per test (least recommended)\nEach test that needs an unusual server writes its own Go program or `httptest` server. It is flexible, but it multiplies binaries to build (each is a `go build`, about 1 s) and duplicates the protocol plumbing each time.\n\n### B -- more knobs on fakemcp\nKeep adding `FAKEMCP_*` environment variables. This is the path today. It stays cheap until the knobs interact, and then the fake becomes a second product with its own bugs.\n\n### C -- one scriptable mock (recommended)\n`fakemcp` reads an optional behaviour file (`--script \u003cpath>` or `FAKEMCP_SCRIPT`), which declares:\n- tools and their schemas and results;\n- delays and failures, per call number;\n- server-initiated requests (elicitation, sampling, `list_changed` notifications);\n- the protocol revision to claim.\n\nWith no file it behaves exactly as it does today, so the existing e2e tests (199 at d0b7e01, 209 at 05c78b2) are unchanged. `askmcp` folds into it later, or stays if its opposite-behaviour rationale (`build_proto.go:19-22`) still holds. The script sits next to the test that uses it. The same file format can drive a **remote** mock (#134): the fake is baked into a container and gets its script over a mounted path. A behaviour that randomises (for example \"fail 1 call in N\") takes the run seed (#93).\n\nConfig: keep `MCPX_CONFIG` as the default and add one test each for `--config \u003cpath>` and for `.mcpx.json` found by the directory walk (`internal/config/config.go:549-565`), so all three ways config reaches the binary are covered once. When `MCPX_CONFIG` is unset, the walk also reads user-level files, so the walk test needs `HOME`/`XDG_CONFIG_HOME` isolated (#138).\n\n## Open questions\n\n- Which runner is the default for a new test: in-process, with the binary run in CI only? Policy for agents belongs to #99.\n- What should the override be named (`MCPX_TEST_BINARY`, or a `-mcpx.binary` test flag)? A test flag does not leak into child processes, which is an argument for it.\n- `--tui` and bare `mcpx` need a TTY. They are binary-only, or run under a pty via `github.com/creack/pty` (a new test-only dependency).\n- Should the in-process suite count toward coverage at all, given that `-cover` on the binary already covers the same code?\n- Does a `-cover` binary run slowly enough to trip the daemon-start timeouts that `internal/testsupport/build.go` warns about? Measure before making it the CI default (from #160).\n- Where do the `GOCOVERDIR` artifacts go in CI, and is there a coverage floor? That belongs to #95 and #99.\n\n## Ease · Impact · Related\n\n**Ease** L (stage 1 plus override plus `-cover`: M; stage 2 env threading: L; scriptable fake: M) · **Impact** high\n**Depends on / related**: #132 (exported command table), #134 (prebuilt-binary runs per environment), #138 (env isolation is a subprocess-path property), #79 (faster CLI/exec; the same `main.go` code), #178 (the ldflags version the installed-output rung checks), #52 (closed, fixed in #182), #93 (seeded mock behaviour), #95 (coverage artifacts, parallel shards), #99 (which runner agents use).\n\nSecurity/auth deferred; see tracker.\n\n## Acceptance criteria\n\n- An in-process entrypoint exists beside the binary suite: the dispatch in `cmd/mcpx/main.go` is reachable as `cli.Run(ctx, args, env, stdio) int` (or the equivalent shape the implementer pins on this issue), and most integration tests can run in-process against it.\n- The binary suite is retained as the superset (signals, exit codes, argv parsing, detached daemon, nix wrapper) and can target a **prebuilt** binary (nix `result`, container image), not only a fresh `go build`.\n- The fixed-behaviour `fakemcp` is replaced or supplemented by a scriptable mock MCP server whose behaviour each test states.\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:54:07Z","url":"https://github.com/developing-today/code/issues/1980"}
| 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:2c23fb17-34ab-d9a1-ddf3-6cacb44dd7db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94C6:1D2D33:182136:1FF9C2:6B0610C6 |
| html-safe-nonce | 37f9915e17b9e984aa2461d06f1f0cf45bbf157b0aa162c2c0599b90308a2c2d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEM2OjFEMkQzMzoxODIxMzY6MUZGOUMyOjZCMDYxMEM2IiwidmlzaXRvcl9pZCI6IjI3OTc1NDcyNjA5NDU1MDI0MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c13ae669a319d4b267021477b2d5a71cea712b2f9ffefa67b346f5c7fc1375d6 |
| hovercard-subject-tag | issue:6088997786 |
| 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/1980/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d36799dfbc9cf436c014bef05a07d595cc0fc72925ffbcb2a96b7d058c877d9a/developing-today/code/issues/1980 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d36799dfbc9cf436c014bef05a07d595cc0fc72925ffbcb2a96b7d058c877d9a/developing-today/code/issues/1980 |
| og:image:alt | Relocated from dezren39/darwin-nix#133 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