Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion .github/workflows/mcpx-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,119 @@ jobs:
count=$(pgrep -c -x mcpx || true)
echo "surviving mcpx daemon count: ${count:-0}"

nix-e2e:
name: "environment: mcpx flake binary e2e"
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: pkgs/mcpx/go.mod
cache: true
cache-dependency-path: pkgs/mcpx/go.sum
- uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
with:
deno-version: v2.x
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- uses: actions/setup-node@v7
with:
node-version: 24
- uses: actions/setup-python@v7
with:
python-version: "3.x"
- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
continue-on-error: true
with:
use-flakehub: false
use-gha-cache: true
- name: Build the wrapped flake binary
run: nix build .#packages.x86_64-linux.mcpx --print-build-logs --out-link result-mcpx
- name: Run e2e against the wrapped flake binary
working-directory: pkgs/mcpx
env:
MCPX_TEST_BINARY: ${{ github.workspace }}/result-mcpx/bin/mcpx
MCPX_TEST_REQUIRE: deno,bun,node,python3
run: go test ./internal/e2e -count=1 -timeout 30m
Comment thread
dezren39 marked this conversation as resolved.
Resolved
Comment thread
dezren39 marked this conversation as resolved.
Resolved

container-e2e:
name: "environment: mcpx container e2e"
runs-on: ubuntu-latest
timeout-minutes: 75
steps:
- uses: actions/checkout@v7
- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
continue-on-error: true
with:
use-flakehub: false
use-gha-cache: true
- name: Build the shipped image and test harness image
run: |
nix build .#packages.x86_64-linux.mcpx-container --print-build-logs --out-link mcpx-image
nix build .#checks.x86_64-linux.mcpx-e2e --print-build-logs --out-link mcpx-e2e-check
- name: Smoke-test the shipped image
run: |
image=$(docker load --input mcpx-image | sed -n 's/^Loaded image: //p')
test -n "$image"
docker run --rm "$image" --version
docker run --rm "$image" exec 'console.log("container-e2e-runtime-ok")' \
| grep -q 'container-e2e-runtime-ok'
- name: Run e2e inside the flake-built test image
run: |
image=$(docker load --input mcpx-e2e-check | sed -n 's/^Loaded image: //p')
test -n "$image"
docker run --init --rm \
--mount "type=bind,src=$GITHUB_WORKSPACE,dst=/workspace,readonly" \
"$image"

remote-smoke:
name: "environment: mcpx remote daemon smoke"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
continue-on-error: true
with:
use-flakehub: false
use-gha-cache: true
- name: Build the shipped image
run: nix build .#packages.x86_64-linux.mcpx-container --print-build-logs --out-link mcpx-image
- name: Connect a client container to a separate daemon container
run: |
set -euo pipefail
image=$(docker load --input mcpx-image | sed -n 's/^Loaded image: //p')
test -n "$image"
network=mcpx-remote-e2e
docker network create "$network"
trap 'docker rm -f mcpx-remote-daemon >/dev/null 2>&1 || true; docker network rm "$network" >/dev/null 2>&1 || true' EXIT
docker run --detach --name mcpx-remote-daemon \
--network "$network" --network-alias mcpxd \
--env MCPX_DAEMON_ADDRESS=0.0.0.0 \
--env MCPX_DAEMON_PORT=18765 \
"$image" daemon
for attempt in $(seq 1 30); do
if output=$(docker run --rm --network "$network" \
--env MCPX_DAEMON_ENDPOINT=http://mcpxd:18765 \
"$image" status 2>&1); then
if grep -q 'daemon: running' <<<"$output"; then
echo "$output"
exit 0
fi
fi
sleep 1
done
echo "client could not reach the remote daemon after $attempt attempts" >&2
echo "$output" >&2
docker logs mcpx-remote-daemon >&2
exit 1

ci-ok:
name: "mcpx-test ci-ok"
needs: [init, unit, lint, plugin-ts, e2e]
needs: [init, unit, lint, plugin-ts, e2e, nix-e2e, container-e2e, remote-smoke]
if: always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false)
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ out
**/out
result*
**/result*
/mcpx-images*
!test/result*
!**/test/result*
!tests/result*
Expand Down
57 changes: 54 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,53 @@ let
) justRecipes.recipes;

mcpx = pkgs.callPackage ../pkgs/mcpx/package.nix { };
mcpxContainerBinary = pkgs.callPackage ../pkgs/mcpx/package.nix {
wrapWithRuntimes = false;
doCheck = false;
};
mcpxContainer = pkgs.callPackage ../pkgs/mcpx/container-image.nix {
mcpx = pkgs.callPackage ../pkgs/mcpx/package.nix {
wrapWithRuntimes = false;
doCheck = false;
mcpx = mcpxContainerBinary;
};
mcpxTestImage = pkgs.dockerTools.buildLayeredImage {
name = "mcpx-e2e-test";
tag = "ci";
# This is a test harness, not the shipped image: Go builds the fake
# MCP server at test time, and the suite requires all wrapped runtimes.
# The mcpx executable is the same unwrapped artifact used by the user
# image; source is mounted read-only by the workflow.
contents = with pkgs; [
bash
bun
cacert
coreutils
deno
git
go_1_27
mcpxContainerBinary
nodejs
python3
];
extraCommands = ''
mkdir -p tmp work usr/bin
chmod 1777 tmp work
ln -s ${pkgs.coreutils}/bin/env usr/bin/env
'';
config = {
Entrypoint = [ "${pkgs.bash}/bin/bash" ];
Cmd = [
"-lc"
"cd /workspace/pkgs/mcpx && go test ./internal/e2e -count=1 -timeout 30m"
];
User = "0:0";
WorkingDir = "/workspace";
Env = [
"GOFLAGS=-buildvcs=false"
"HOME=/tmp"
"MCPX_TEST_BINARY=${mcpxContainerBinary}/bin/mcpx"
"MCPX_TEST_REQUIRE=deno,bun,node,python3"
"PATH=${pkgs.lib.makeBinPath (with pkgs; [ bash bun coreutils deno git go_1_27 nodejs python3 ])}:${mcpxContainerBinary}/bin"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
];
};
};
identity = pkgs.callPackage ../pkgs/identity/package.nix { };
Expand Down Expand Up @@ -739,6 +782,8 @@ let
generic-runtime = genericRuntime;
generic-js-runtime = genericJsRuntime;
generic-python-runtime = genericPythonRuntime;
} // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
mcpx-e2e-test-image = mcpxTestImage;
};
checks = {
# The packaging test (#1981): run the built mcpx artifact --
Expand Down Expand Up @@ -792,6 +837,12 @@ let
bash scripts/just-recipes-root-check-test.sh
touch $out
'';
} // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
# The e2e suite spawns daemon/runtime process trees and needs init to
# reap them. Expose the flake-built test image as the check output;
# mcpx-test runs the suite in that image with Docker's --init, outside
# the Nix build sandbox where those process trees cannot be reaped.
mcpx-e2e = mcpxTestImage;
};
apps = (pkgs.lib.mapAttrs mkRecipeApp publicRecipes) // {
id-mail-deploy = mkApp idMailDeploy "Deploy the mail Worker from this checkout (needs Bitwarden and sops access)";
Expand Down
8 changes: 6 additions & 2 deletions pkgs/mcpx/internal/e2e/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ func TestRepoAndWorktreeScopesResolveWithNoGitInstalled(t *testing.T) {
line = l
}
}
// An artifact supplied through MCPX_TEST_BINARY may be a wrapper that
// changes PATH, so only the unwrapped run can assert git is absent.
noGitExpected := os.Getenv("MCPX_TEST_BINARY") == ""
if !strings.HasPrefix(line, "ok") || !strings.Contains(line, "worktree "+side) ||
!strings.Contains(line, "resolved natively") || !strings.Contains(line, "no git on PATH") {
t.Errorf("doctor should report the native answer and that git is absent, without warning:\n%s", doctor)
!strings.Contains(line, "resolved natively") ||
(noGitExpected && !strings.Contains(line, "no git on PATH")) {
t.Errorf("doctor should report the native answer and the expected git fallback, without warning:\n%s", doctor)
}
}

Expand Down
8 changes: 1 addition & 7 deletions pkgs/mcpx/internal/e2e/takeover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,7 @@ func TestUpgradeStartsTheSuccessorThroughTheUnitsStartCommand(t *testing.T) {
wrapper := filepath.Join(bin, "mcpx-start")
writeUnitScript(t, wrapper, "MCPX_UNIT_TOKEN=rotated\nexport MCPX_UNIT_TOKEN\nexec \"$@\"\n")
next := filepath.Join(bin, "mcpx")
src, err := os.ReadFile(e.mcpx)
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(next, src, 0o755); err != nil {
t.Fatal(err)
}
copyDaemonExecutable(t, before.PID, e.mcpx, next)
// systemd reports the wrapper and the binary as the unit's ExecStart.
writeUnitScript(t, filepath.Join(bin, "systemctl"),
fmt.Sprintf("echo '{ path=%s ; argv[]=%s %s daemon ; ignore_errors=no ; pid=0 ; status=0/0 }'\n", wrapper, wrapper, next))
Expand Down
16 changes: 15 additions & 1 deletion pkgs/mcpx/internal/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e_test
import (
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -19,6 +20,19 @@ func copyExecutable(t *testing.T, from, to string) {
}
}

// copyDaemonExecutable makes a distinct upgrade target from the executable
// the daemon is actually running. Copying e.mcpx is not sufficient for
// wrapped artifacts: a wrapper can exec an absolute store path, making the
// copied wrapper start the same executable again.
func copyDaemonExecutable(t *testing.T, pid int, fallback, to string) {
t.Helper()
executable := filepath.Join("/proc", strconv.Itoa(pid), "exe")
if _, err := os.Stat(executable); err != nil {
executable = fallback
}
copyExecutable(t, executable, to)
}

func awaitDaemonOtherThan(t *testing.T, e *env, pid int) daemonDoc {
t.Helper()
deadline := time.Now().Add(30 * time.Second)
Expand All @@ -45,7 +59,7 @@ func TestUpgradeKeepsTheChildAndHandsMainPIDToTheSuccessor(t *testing.T) {
}

next := filepath.Join(t.TempDir(), "mcpx-next")
copyExecutable(t, e.mcpx, next)
copyDaemonExecutable(t, before.PID, e.mcpx, next)
if out, err := e.tryWith(next, "upgrade"); err != nil {
t.Fatalf("upgrade failed: %v\n%s", err, out)
}
Expand Down