From 182fac777138647883c5a442be317c3069990cd3 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 03:30:53 -0500 Subject: [PATCH 1/5] test(mcpx): packaging test for the built artifact (#1981) --- .github/workflows/mcpx-nixbuild.yml | 5 ++ lib/default.nix | 14 +++++ pkgs/mcpx/AGENTS.md | 11 ++++ pkgs/mcpx/packaging-test.sh | 89 +++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100755 pkgs/mcpx/packaging-test.sh diff --git a/.github/workflows/mcpx-nixbuild.yml b/.github/workflows/mcpx-nixbuild.yml index bc222d037c..cc593958eb 100644 --- a/.github/workflows/mcpx-nixbuild.yml +++ b/.github/workflows/mcpx-nixbuild.yml @@ -59,3 +59,8 @@ jobs: - name: Nix build run: nix build .#packages.x86_64-linux.mcpx --print-build-logs + + # Packaging test (#1981): building the package proves it + # compiles; this runs the built artifact the way a user does. + - name: Packaging test + run: nix build .#checks.x86_64-linux.mcpx-packaging --print-build-logs diff --git a/lib/default.nix b/lib/default.nix index 7d8dfa6b03..1645bbaebd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -607,6 +607,20 @@ let inherit mcpx idMailDeploy; mcpx-docs = mcpxDocs; }; + checks = { + # The packaging test (#1981): run the built mcpx artifact -- + # never the source tree -- with an empty HOME: --version, + # the wrapper PATH (via `mcpx doctor` in a scrubbed + # environment), the man page and completions, and a stdio + # serve handshake. The script is the single source, shared + # with the hand-run command in pkgs/mcpx/AGENTS.md. + mcpx-packaging = pkgs.runCommand "mcpx-packaging-test" { + nativeBuildInputs = [ pkgs.bash pkgs.gzip ]; + } '' + bash ${../pkgs/mcpx/packaging-test.sh} ${mcpx} + touch $out + ''; + }; apps = (pkgs.lib.mapAttrs mkRecipeApp publicRecipes) // { id-mail-deploy = mkApp idMailDeploy "Deploy the mail Worker from this checkout (needs Bitwarden and sops access)"; mcpx = { diff --git a/pkgs/mcpx/AGENTS.md b/pkgs/mcpx/AGENTS.md index 6b4c9eaef1..c419ae0dfe 100644 --- a/pkgs/mcpx/AGENTS.md +++ b/pkgs/mcpx/AGENTS.md @@ -111,6 +111,17 @@ in a tool argument or on a command line. Ask them to give it through OpenChamber or to run `mcpx secrets set ` themselves, then try again. `mcpx secrets list` shows which names have a value. +## Packaging test + +`packaging-test.sh` (beside this file) tests the built artifact, not the +source tree: version, wrapper PATH, man page and completions, and a stdio +serve handshake, all with an empty HOME (#1981). + + nix build .#packages.x86_64-linux.mcpx + pkgs/mcpx/packaging-test.sh ./result + +CI runs the same script as the flake check `checks.mcpx-packaging`. + ## Do not - Do not add these servers to your own MCP config. The point is that they are diff --git a/pkgs/mcpx/packaging-test.sh b/pkgs/mcpx/packaging-test.sh new file mode 100755 index 0000000000..b9ac89592d --- /dev/null +++ b/pkgs/mcpx/packaging-test.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# packaging-test.sh -- test the mcpx artifact users install, not the +# source tree (#1981). Everything below runs the wrapped binary from a +# built package output with an empty HOME: +# +# nix build .#packages.x86_64-linux.mcpx +# pkgs/mcpx/packaging-test.sh ./result +# +# The same script is the flake check checks.mcpx-packaging (wired in +# lib/default.nix, run by the mcpx-nixbuild workflow), so the hand-run +# command and CI can never drift apart. Source-tree suites +# (internal/e2e and friends) complement this; they never see $out. +set -euo pipefail + +out="${1:?usage: packaging-test.sh }" +bin="$out/bin/mcpx" +fail() { + echo "packaging-test: FAIL: $*" >&2 + exit 1 +} +note() { echo "packaging-test: $*"; } + +[ -x "$bin" ] || fail "$bin is missing or not executable" +[ -f "$out/bin/.mcpx-wrapped" ] || fail "the wrapped binary is missing: $out/bin/mcpx is not the packaged wrapper" + +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT +export HOME="$work/home" +mkdir -p "$HOME" +# State belongs under the empty HOME, never in a developer's real one. +unset MCPX_STATE_DIR MCPX_CACHE_DIR + +# --version, from the store path, with no pre-existing state. +version_out="$("$bin" --version)" || fail "mcpx --version did not run" +version="$(printf '%s' "$version_out" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+[^ ]*' | head -1)" +[ -n "$version" ] || fail "mcpx --version printed no version: $version_out" +note "version: $version_out" + +# The wrapper's PATH, verified from inside the process: run doctor +# with a PATH that has none of the runtimes on it. Whatever doctor +# finds (it uses exec.LookPath in-process) arrived via the wrapper's +# --suffix PATH from package.nix's postInstall. +doctor_out="$(env -i HOME="$HOME" PATH=/nonexistent "$bin" doctor -v 2>&1 || true)" +for rt in deno bun node; do + printf '%s' "$doctor_out" | grep -q "$rt (/nix/store/" || + fail "doctor (scrubbed PATH) did not find $rt on the wrapper PATH" +done +printf '%s' "$doctor_out" | grep -q 'git at /nix/store/' || + fail "doctor (scrubbed PATH) did not find git on the wrapper PATH" +note "wrapper PATH reaches deno, bun, node and git (doctor, scrubbed PATH)" + +# Man page and completions, present in the built output, and the man +# page's .TH line carries the built version. +man="$out/share/man/man1/mcpx.1.gz" +[ -f "$man" ] || fail "man page missing: $man" +zcat "$man" >"$work/mcpx.1" || fail "man page does not decompress" +grep -m1 '^\.TH' "$work/mcpx.1" | grep -q "mcpx $version" || + fail "man page .TH line does not carry the built version $version" +for f in "share/bash-completion/completions/mcpx.bash" "share/zsh/site-functions/_mcpx" "share/fish/vendor_completions.d/mcpx.fish"; do + [ -s "$out/$f" ] || fail "completion file missing or empty: $f" +done +note "man page (version $version) and bash/zsh/fish completions present" + +# mcpx serve over stdio: initialize and server/discover answer, and +# tools/list returns the catalogue. Newline-delimited JSON-RPC in, +# the same out; the process exits when stdin closes. +req="$work/requests.jsonl" +resp="$work/responses.jsonl" +{ + printf '%s +' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"packaging-test","version":"0"}}}' + printf '%s +' '{"jsonrpc":"2.0","method":"notifications/initialized"}' + printf '%s +' '{"jsonrpc":"2.0","id":2,"method":"server/discover","params":{}}' + printf '%s +' '{"jsonrpc":"2.0","id":3,"method":"tools/list","params":{}}' +} >"$req" +timeout 60 "$bin" serve <"$req" >"$resp" 2>"$work/serve.err" || + fail "mcpx serve exited non-zero: $(cat "$work/serve.err")" +grep -q '"id":1' "$resp" || fail "initialize went unanswered" +grep '"id":1' "$resp" | grep -q '"serverInfo"' || fail "initialize answered without serverInfo" +grep '"id":2' "$resp" | grep -q '2026-07-28' || + fail "server/discover did not answer on the 2026-07-28 revision" +grep '"id":3' "$resp" | grep -q '"name":"mcpx_' || + fail "tools/list returned an empty catalogue" +note "stdio serve: initialize, server/discover (2026-07-28) and tools/list all answer" + +note "PASS: the built artifact installs, starts cold, and serves" From 8dbe3cdfde74f05d7ddb99560811e94e34d858c8 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 03:55:43 -0500 Subject: [PATCH 2/5] packaging-test: read doctor through --json, isolate XDG state/cache (#1981) Codex P1 on PR #2994: the wrapper-PATH assertions parsed human doctor -v output, contrary to pkgs/mcpx/AGENTS.md. They now read mcpx --json doctor and scope the greps to the runtime/git check objects. Codex P2: also unset XDG_STATE_HOME and XDG_CACHE_HOME so an inherited XDG dir cannot leak state out of the empty HOME. --- pkgs/mcpx/packaging-test.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pkgs/mcpx/packaging-test.sh b/pkgs/mcpx/packaging-test.sh index b9ac89592d..6396cda392 100755 --- a/pkgs/mcpx/packaging-test.sh +++ b/pkgs/mcpx/packaging-test.sh @@ -28,7 +28,10 @@ trap 'rm -rf "$work"' EXIT export HOME="$work/home" mkdir -p "$HOME" # State belongs under the empty HOME, never in a developer's real one. -unset MCPX_STATE_DIR MCPX_CACHE_DIR +# XDG_STATE_HOME / XDG_CACHE_HOME override the HOME-based defaults in +# the daemon's path resolution, so they go too: an inherited XDG dir +# would leak state out of the empty HOME (Codex, PR #2994). +unset MCPX_STATE_DIR MCPX_CACHE_DIR XDG_STATE_HOME XDG_CACHE_HOME # --version, from the store path, with no pre-existing state. version_out="$("$bin" --version)" || fail "mcpx --version did not run" @@ -39,15 +42,22 @@ note "version: $version_out" # The wrapper's PATH, verified from inside the process: run doctor # with a PATH that has none of the runtimes on it. Whatever doctor # finds (it uses exec.LookPath in-process) arrived via the wrapper's -# --suffix PATH from package.nix's postInstall. -doctor_out="$(env -i HOME="$HOME" PATH=/nonexistent "$bin" doctor -v 2>&1 || true)" +# --suffix PATH from package.nix's postInstall. Read the results +# through doctor's JSON interface, never its human output +# (pkgs/mcpx/AGENTS.md: "Do not parse human output; use +# `mcpx --json `" — Codex, PR #2994). +doctor_json="$(env -i HOME="$HOME" PATH=/nonexistent "$bin" --json doctor 2>/dev/null || true)" +[ -n "$doctor_json" ] || fail "mcpx --json doctor produced no output" +runtime_check="$(printf '%s' "$doctor_json" | grep -o '"name":"runtime"[^}]*}' || true)" +[ -n "$runtime_check" ] || fail "mcpx --json doctor has no runtime check: $doctor_json" for rt in deno bun node; do - printf '%s' "$doctor_out" | grep -q "$rt (/nix/store/" || + printf '%s' "$runtime_check" | grep -q "$rt (/nix/store/" || fail "doctor (scrubbed PATH) did not find $rt on the wrapper PATH" done -printf '%s' "$doctor_out" | grep -q 'git at /nix/store/' || +git_check="$(printf '%s' "$doctor_json" | grep -o '"name":"git"[^}]*}' || true)" +printf '%s' "$git_check" | grep -q 'git at /nix/store/' || fail "doctor (scrubbed PATH) did not find git on the wrapper PATH" -note "wrapper PATH reaches deno, bun, node and git (doctor, scrubbed PATH)" +note "wrapper PATH reaches deno, bun, node and git (doctor --json, scrubbed PATH)" # Man page and completions, present in the built output, and the man # page's .TH line carries the built version. From 6e70a6212288b70e9d6c65e9d66fd3e8fc5c1a75 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 04:29:19 -0500 Subject: [PATCH 3/5] fix(mcpx): packaging test parses doctor JSON with jq, not a compact-JSON grep (#1981) Codex P1 on 8dbe3cdfd: CmdDoctor writes through the app encoder with SetIndent, so the runtime/git records are multi-line indented JSON and the grep for a compact single-line record never matched -- runtime_check stayed empty and the packaging check failed before the handshake on a healthy binary. Extract the runtime and git check details with jq (a real parser, per the finding) and declare pkgs.jq in the mcpx-packaging check build inputs in lib/default.nix. --- lib/default.nix | 2 +- pkgs/mcpx/packaging-test.sh | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 1645bbaebd..ed48a908ac 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -615,7 +615,7 @@ let # serve handshake. The script is the single source, shared # with the hand-run command in pkgs/mcpx/AGENTS.md. mcpx-packaging = pkgs.runCommand "mcpx-packaging-test" { - nativeBuildInputs = [ pkgs.bash pkgs.gzip ]; + nativeBuildInputs = [ pkgs.bash pkgs.gzip pkgs.jq ]; } '' bash ${../pkgs/mcpx/packaging-test.sh} ${mcpx} touch $out diff --git a/pkgs/mcpx/packaging-test.sh b/pkgs/mcpx/packaging-test.sh index 6396cda392..afdb2c6033 100755 --- a/pkgs/mcpx/packaging-test.sh +++ b/pkgs/mcpx/packaging-test.sh @@ -48,14 +48,23 @@ note "version: $version_out" # `mcpx --json `" — Codex, PR #2994). doctor_json="$(env -i HOME="$HOME" PATH=/nonexistent "$bin" --json doctor 2>/dev/null || true)" [ -n "$doctor_json" ] || fail "mcpx --json doctor produced no output" -runtime_check="$(printf '%s' "$doctor_json" | grep -o '"name":"runtime"[^}]*}' || true)" -[ -n "$runtime_check" ] || fail "mcpx --json doctor has no runtime check: $doctor_json" +# Parse the JSON with a parser, not a pattern: CmdDoctor writes +# through the app's indented encoder, so the records are multi-line +# and a compact-JSON grep can never match (Codex P1, PR #2994). jq +# is a declared build input of the flake check (lib/default.nix). +command -v jq >/dev/null || fail "jq is required to parse mcpx --json doctor output" +check_detail() { + printf '%s' "$doctor_json" | jq -r --arg n "$1" \ + '[.[] | select(.name == $n) | .detail // ""] | first // ""' || true +} +runtime_detail="$(check_detail runtime)" +[ -n "$runtime_detail" ] || fail "mcpx --json doctor has no runtime check: $doctor_json" for rt in deno bun node; do - printf '%s' "$runtime_check" | grep -q "$rt (/nix/store/" || + printf '%s' "$runtime_detail" | grep -q "$rt (/nix/store/" || fail "doctor (scrubbed PATH) did not find $rt on the wrapper PATH" done -git_check="$(printf '%s' "$doctor_json" | grep -o '"name":"git"[^}]*}' || true)" -printf '%s' "$git_check" | grep -q 'git at /nix/store/' || +git_detail="$(check_detail git)" +printf '%s' "$git_detail" | grep -q 'git at /nix/store/' || fail "doctor (scrubbed PATH) did not find git on the wrapper PATH" note "wrapper PATH reaches deno, bun, node and git (doctor --json, scrubbed PATH)" From 6ff0b9af1ad00685e1750fba79b84092cad9610d Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 04:53:30 -0500 Subject: [PATCH 4/5] test(mcpx): select .checks[] before filtering doctor records in packaging test (#1981) --- pkgs/mcpx/packaging-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/mcpx/packaging-test.sh b/pkgs/mcpx/packaging-test.sh index afdb2c6033..0463fd008d 100755 --- a/pkgs/mcpx/packaging-test.sh +++ b/pkgs/mcpx/packaging-test.sh @@ -55,7 +55,7 @@ doctor_json="$(env -i HOME="$HOME" PATH=/nonexistent "$bin" --json doctor 2>/dev command -v jq >/dev/null || fail "jq is required to parse mcpx --json doctor output" check_detail() { printf '%s' "$doctor_json" | jq -r --arg n "$1" \ - '[.[] | select(.name == $n) | .detail // ""] | first // ""' || true + '[.checks[] | select(.name == $n) | .detail // ""] | first // ""' || true } runtime_detail="$(check_detail runtime)" [ -n "$runtime_detail" ] || fail "mcpx --json doctor has no runtime check: $doctor_json" From 0fb2771e566b067a06393361f15360f032eec7d0 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 07:22:17 -0500 Subject: [PATCH 5/5] docs(mcpx): re-sync story.md AGENTS.md line count to 152 after main merge (#1981) --- pkgs/mcpx/docs/story.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/mcpx/docs/story.md b/pkgs/mcpx/docs/story.md index cebfd3e927..dda5cad412 100644 --- a/pkgs/mcpx/docs/story.md +++ b/pkgs/mcpx/docs/story.md @@ -18,7 +18,7 @@ their schemas is in the agent's context, which is the entire point, but the agent does not know that yet. What it does have is one instruction file, [`AGENTS.md`](../AGENTS.md), -injected at session start. Abridged -- the full file is 120 lines and adds +injected at session start. Abridged -- the full file is 152 lines and adds profiles, the script contract and the secrets section, which this walk does not need -- it reads: @@ -2906,7 +2906,7 @@ else in this document is detail underneath those four verbs. - [`AGENTS.md`](../AGENTS.md) — the instruction file abridged above. This is the text to inject into an agent's session; it is deliberately short, and - 120 lines today. The quote above is not the whole of it (#264). + 152 lines today. The quote above is not the whole of it (#264). - [`ASSESSMENT.md`](../ASSESSMENT.md) — why this exists, with the measurements against the predecessor it replaced. - [`OPENCODE-V2.md`](../OPENCODE-V2.md) — how this compares to opencode v2's