diff --git a/.github/workflows/mcpx-test.yml b/.github/workflows/mcpx-test.yml index 6cd40c92d7..36adb7f30a 100644 --- a/.github/workflows/mcpx-test.yml +++ b/.github/workflows/mcpx-test.yml @@ -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 + + 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 diff --git a/.gitignore b/.gitignore index de95d9048a..c204b3053c 100755 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ out **/out result* **/result* +/mcpx-images* !test/result* !**/test/result* !tests/result* diff --git a/lib/default.nix b/lib/default.nix index f6d7fdd134..8b25f439b5 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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 { }; @@ -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 -- @@ -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)"; diff --git a/pkgs/mcpx/internal/e2e/git_test.go b/pkgs/mcpx/internal/e2e/git_test.go index 9bed931f08..33bff341ec 100644 --- a/pkgs/mcpx/internal/e2e/git_test.go +++ b/pkgs/mcpx/internal/e2e/git_test.go @@ -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) } } diff --git a/pkgs/mcpx/internal/e2e/takeover_test.go b/pkgs/mcpx/internal/e2e/takeover_test.go index 740a06d67b..9310646417 100644 --- a/pkgs/mcpx/internal/e2e/takeover_test.go +++ b/pkgs/mcpx/internal/e2e/takeover_test.go @@ -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)) diff --git a/pkgs/mcpx/internal/e2e/upgrade_test.go b/pkgs/mcpx/internal/e2e/upgrade_test.go index e5f66b17ce..0f4fb01c2a 100644 --- a/pkgs/mcpx/internal/e2e/upgrade_test.go +++ b/pkgs/mcpx/internal/e2e/upgrade_test.go @@ -3,6 +3,7 @@ package e2e_test import ( "os" "path/filepath" + "strconv" "strings" "testing" "time" @@ -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) @@ -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) }