From 788dd44c9f78ea350154f3aedf60f2ed8cbf82af Mon Sep 17 00:00:00 2001 From: Steady Infrastructure Bot <176285811+SteadyInfraBot@users.noreply.github.com> Date: Sun, 29 Nov 2026 02:00:25 +0700 Subject: [PATCH] feat: publish release binaries and container image --- .dockerignore | 6 ++ .github/workflows/release.yml | 165 ++++++++++++++++++++++++++++++++-- Dockerfile | 16 ++++ README.md | 25 ++++-- docs/INSTALL.md | 116 ++++++++++++++++++++++++ docs/RELEASING.md | 6 +- tests/mcp_stdio.rs | 81 ++++++++++++----- 7 files changed, 374 insertions(+), 41 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docs/INSTALL.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d0d9b5c4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.github +target +dist +.nosrc-cache +.nosrc-exports diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5cc3d107..9ad2d60b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,22 +4,34 @@ on: push: tags: - "v*" + pull_request: permissions: - contents: write + contents: read jobs: validate: - name: Validate milestone tag + name: Validate release ref runs-on: ubuntu-latest steps: - - name: Check out source + - name: Check out source and history uses: actions/checkout@v7 + with: + fetch-depth: 0 - name: Validate milestone tag + if: github.event_name == 'push' run: bash scripts/check-release-tag.sh "$GITHUB_REF_NAME" - # Windows and macOS only run selectively on ordinary commits, so a release must pass them. + - name: Require a commit already merged to main + if: github.event_name == 'push' + run: | + git fetch origin main --no-tags + git merge-base --is-ancestor "$GITHUB_SHA" origin/main || { + echo "Release tags must point to a commit reachable from main" >&2 + exit 1 + } + platforms: name: Windows and macOS tests needs: validate @@ -27,15 +39,150 @@ jobs: contents: read uses: ./.github/workflows/platforms.yml + build: + name: Build (${{ matrix.target }}) + needs: validate + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-24.04 + target: x86_64-unknown-linux-gnu + - runner: ubuntu-24.04-arm + target: aarch64-unknown-linux-gnu + - runner: macos-15 + target: aarch64-apple-darwin + - runner: windows-2025 + target: x86_64-pc-windows-msvc + steps: + - name: Check out source + uses: actions/checkout@v7 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Cache Cargo artifacts + uses: Swatinem/rust-cache@v2 + with: + key: release-${{ matrix.target }} + cache-on-failure: true + + - name: Build release binary + run: cargo build --locked --release --target "${{ matrix.target }}" + + - name: Package Unix binary + if: runner.os != 'Windows' + shell: bash + run: | + mkdir -p dist + tar -C "target/${{ matrix.target }}/release" -czf "dist/nosrc-${{ matrix.target }}.tar.gz" nosrc + + - name: Package Windows binary + if: runner.os == 'Windows' + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path dist | Out-Null + Compress-Archive -Path "target/${{ matrix.target }}/release/nosrc.exe" -DestinationPath "dist/nosrc-${{ matrix.target }}.zip" + + - name: Upload release archive + uses: actions/upload-artifact@v7 + with: + name: nosrc-${{ matrix.target }} + path: dist/nosrc-${{ matrix.target }}.* + if-no-files-found: error + retention-days: 7 + + artifact-smoke: + name: Smoke-test Linux release binary offline + needs: build + runs-on: ubuntu-24.04 + steps: + - name: Check out source + uses: actions/checkout@v7 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + + - name: Download Linux x86_64 release binary + uses: actions/download-artifact@v7 + with: + name: nosrc-x86_64-unknown-linux-gnu + path: dist + + - name: Extract release binary + run: | + tar -xzf dist/nosrc-x86_64-unknown-linux-gnu.tar.gz -C dist + chmod +x dist/nosrc + dist/nosrc --help + + - name: Export and serve an offline bundle using the release binary + env: + NOSRC_TEST_BINARY: ${{ github.workspace }}/dist/nosrc + run: | + cargo test --locked --test mcp_stdio mcp_exported_generation_can_be_served_offline_without_provider_credentials -- --exact + publish: - name: Create GitHub Release - needs: [validate, platforms] - runs-on: ubuntu-latest + if: github.event_name == 'push' + name: Publish GitHub Release and container + needs: [validate, platforms, build, artifact-smoke] + runs-on: ubuntu-24.04 + permissions: + contents: write + packages: write steps: - name: Check out source uses: actions/checkout@v7 - - name: Create GitHub Release + - name: Download all release archives + uses: actions/download-artifact@v7 + with: + pattern: nosrc-* + path: dist + merge-multiple: true + + - name: Create SHA-256 checksums + run: | + cd dist + sha256sum nosrc-*.tar.gz nosrc-*.zip 2>/dev/null > SHA256SUMS + + - name: Create GitHub Release and upload artifacts env: GH_TOKEN: ${{ github.token }} - run: gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes + run: | + gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes + gh release upload "$GITHUB_REF_NAME" dist/nosrc-* dist/SHA256SUMS + + - name: Prepare multi-architecture container context + run: | + mkdir -p container-context + tar -xzf dist/nosrc-x86_64-unknown-linux-gnu.tar.gz -C container-context + mv container-context/nosrc container-context/nosrc-linux-amd64 + tar -xzf dist/nosrc-aarch64-unknown-linux-gnu.tar.gz -C container-context + mv container-context/nosrc container-context/nosrc-linux-arm64 + cp Dockerfile container-context/Dockerfile + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish multi-architecture container image + uses: docker/build-push-action@v6 + with: + context: container-context + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/nonops/nosrc:${{ github.ref_name }} + ghcr.io/nonops/nosrc:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..212f284e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM debian:trixie-slim + +LABEL org.opencontainers.image.source="https://github.com/NonOps/nosrc" + +ARG TARGETARCH +COPY nosrc-linux-${TARGETARCH} /usr/local/bin/nosrc + +RUN groupadd --system --gid 10001 nosrc \ + && useradd --system --uid 10001 --gid nosrc --home-dir /var/lib/nosrc \ + --create-home --shell /usr/sbin/nologin nosrc \ + && chmod 0555 /usr/local/bin/nosrc + +USER 10001:10001 +WORKDIR /var/lib/nosrc + +ENTRYPOINT ["/usr/local/bin/nosrc"] diff --git a/README.md b/README.md index acb893da..bf4a776c 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,23 @@ These are operating modes of one executable, not separate guest runtimes. MCP ca The model-generated assertion suite is supplemental. It does not replace the operator-authored SPEC verification suite, and passing tests do not prove correctness or security. +## Install a release binary + +Prebuilt binaries for Linux (x86_64 and aarch64, glibc 2.39+), macOS (Apple Silicon), and Windows (x86_64 MSVC) are attached to each [GitHub Release](https://github.com/NonOps/nosrc/releases). Verify downloads with the published SHA-256 checksums. See [Installation and deployment](docs/INSTALL.md) for exact commands, container usage, and supervisor examples. + +For a source build, Rust 1.97 or later is required: + +```sh +cargo install --path . +``` + ## Quick start: HTTP -Requirements: Rust 1.97 or later, Cargo, and an OpenAI-compatible API key. +Requirements: an installed nosrc binary and an OpenAI-compatible API key. Rust is not required when using a release binary. ```sh export LLM_API_KEY="your-api-key" -cargo run -- --spec ./examples/minimal/SPEC.md --port 8080 +nosrc --spec ./examples/minimal/SPEC.md --port 8080 ``` The listener binds to `127.0.0.1` by default. Use `--bind 0.0.0.0` only when external access is intended. Check the runtime and example endpoint: @@ -81,7 +91,7 @@ curl -i http://localhost:8080/hello ```sh export LLM_API_KEY="your-api-key" # required for source: "spec" -cargo run -- mcp --spec ./examples/minimal/SPEC.md +nosrc mcp --spec ./examples/minimal/SPEC.md ``` The default MCP mode uses stdio and does not open an HTTP listener. It exposes six tools: `prepare_app`, `activate_app`, `invoke_app`, `get_app_status`, `rollback_app`, and `export_app`. Exports are confined to the configured `--export-root` (default `./.nosrc-exports`). Rollback is limited to the immediately previous retained generation. Generation state and rollback history are process-local and disappear when the MCP process exits. Failed `prepare_app` calls return bounded structured diagnostics: stable verification-case IDs, expected/actual status, allowlisted response headers, redacted JSON body previews where safe, compiler details, and resource-limit categories. Trusted verification policy, request inputs, and arbitrary non-JSON response bodies are not returned. @@ -89,7 +99,7 @@ The default MCP mode uses stdio and does not open an HTTP listener. It exposes s MCP can also start without an operator SPEC: ```sh -cargo run -- mcp +nosrc mcp ``` This starts with empty application state and baseline runtime resource limits. The agent can prepare direct JavaScript with `source: "direct_js"`, or provide a draft contract with `source: "draft_spec"` and a `draft_spec` Markdown string. Draft SPEC data is synthesis input and candidate-test material, not trusted operator policy. Prepared generations can be inspected, and draft-SPEC generations can be exported for review, but **cannot be activated** until an operator reviews the draft and restarts nosrc with it as `--spec PATH`; activation always requires at least one operator-controlled trusted verification case. Direct-JavaScript preparation without a startup SPEC is a compile/preparation check only: it cannot be invoked, activated, or exported. MCP `export_app` accepts only a single bundle directory name beneath the configured `--export-root` (default `./.nosrc-exports`), never an arbitrary filesystem path. The bundle includes `SPEC.md`, handler source, component, assertions, and manifest, and can be served without an API key. @@ -97,7 +107,7 @@ This starts with empty application state and baseline runtime resource limits. T To expose HTTP from the same process and share the active generation with MCP, add `--http-port` (and optionally `--http-bind`): ```sh -LLM_API_KEY="your-api-key" cargo run -- mcp --spec ./examples/minimal/SPEC.md --http-port 8080 +LLM_API_KEY="your-api-key" nosrc mcp --spec ./examples/minimal/SPEC.md --http-port 8080 ``` MCP activation and rollback update the handler used by HTTP ingress. This is one application lifecycle and one generation history, not two runtimes synchronized over a network. The HTTP listener defaults to loopback; use `--http-bind 0.0.0.0` only when external exposure is intended. The stdio transport itself remains local and has no MCP-level authentication. @@ -134,7 +144,7 @@ The `--spec` file is the operator-controlled trusted policy: a connected agent c ```sh export LLM_API_KEY="your-api-key" -cargo run -- export --spec ./examples/minimal/SPEC.md --out-dir ./dist +nosrc export --spec ./examples/minimal/SPEC.md --out-dir ./dist ``` The export command runs synthesis (or loads a cache entry), componentization/compilation, trusted and generated verification, and fresh production-instance creation before writing: @@ -152,7 +162,7 @@ The export directory is for inspection, audit support, and version control. The After exporting a bundle, start the HTTP runtime without an API key or model-provider request: ```sh -cargo run -- serve --bundle ./dist --bind 127.0.0.1 --port 8080 +nosrc serve --bundle ./dist --bind 127.0.0.1 --port 8080 ``` Startup validates the bundle files and SHA-256 metadata, compiles the prebuilt component with the current Wasmtime engine, reruns the assertion suites on separate candidate instances according to the manifest policy mode, runs the fixed host-owned ABI probes on another disposable instance, and creates a fresh serving instance only after every check passes. The HTTP listener opens only after successful validation. This mode does not read a SPEC file, synthesize code, or access an LLM provider. @@ -221,6 +231,7 @@ Git tags and GitHub Releases use the short milestone form: `v0.1`, `v0.2`, `v0.3 ## Project documentation +- [Installation and deployment](docs/INSTALL.md) - [Architecture and implemented design](ARCHITECTURE.md) - [CLI reference](docs/CLI.md) - [Exported artifact format](docs/ARTIFACTS.md) diff --git a/docs/INSTALL.md b/docs/INSTALL.md new file mode 100644 index 00000000..84be241e --- /dev/null +++ b/docs/INSTALL.md @@ -0,0 +1,116 @@ +# Installation and deployment + +## Release binaries + +Release archives are published for: + +| Platform | Archive | +| --- | --- | +| Linux x86_64 (glibc 2.39+) | `nosrc-x86_64-unknown-linux-gnu.tar.gz` | +| Linux aarch64 (glibc 2.39+) | `nosrc-aarch64-unknown-linux-gnu.tar.gz` | +| macOS Apple Silicon | `nosrc-aarch64-apple-darwin.tar.gz` | +| Windows x86_64 (MSVC) | `nosrc-x86_64-pc-windows-msvc.zip` | + +Linux binaries are built on Ubuntu 24.04 and require glibc 2.39 or later. These are glibc builds, not musl/static builds. Windows x86_64 binaries are built natively for the MSVC toolchain and distributed as ZIP archives. + +Choose the archive matching the machine, then download and verify it. Example for Linux x86_64: + +```sh +VERSION=v0.1 +ASSET=nosrc-x86_64-unknown-linux-gnu.tar.gz +BASE="https://github.com/NonOps/nosrc/releases/download/$VERSION" + +curl -fLO "$BASE/$ASSET" +curl -fLO "$BASE/SHA256SUMS" +grep " $ASSET$" SHA256SUMS | sha256sum --check - +tar -xzf "$ASSET" +sudo install -m 0755 nosrc /usr/local/bin/nosrc +nosrc --help +``` + +Windows PowerShell example (run in a directory where you want the binary installed): + +```powershell +$Version = "v0.1" +$Asset = "nosrc-x86_64-pc-windows-msvc.zip" +$Base = "https://github.com/NonOps/nosrc/releases/download/$Version" + +Invoke-WebRequest "$Base/$Asset" -OutFile $Asset +Invoke-WebRequest "$Base/SHA256SUMS" -OutFile SHA256SUMS +$Expected = ((Select-String -Path SHA256SUMS -Pattern ([regex]::Escape($Asset))).Line -split '\s+')[0] +$Actual = (Get-FileHash -Algorithm SHA256 $Asset).Hash.ToLowerInvariant() +if ($Actual -ne $Expected) { throw "SHA-256 checksum mismatch" } +Expand-Archive $Asset -DestinationPath nosrc -Force +.\nosrc\nosrc.exe --help +``` + +Replace `VERSION` and `ASSET` with the release and platform you need. The checksum verifies downloaded bytes against the checksum file published alongside that release; it is not a signature or provenance attestation. + +For a source install, use Rust 1.97 or later: + +```sh +cargo install --path . +``` + +## Container image + +The release workflow publishes a multi-architecture image to [GitHub Container Registry](https://ghcr.io/nonops/nosrc), for Linux amd64 and arm64. The image runs as the unprivileged UID/GID `10001:10001`. + +An exported bundle can be served without an LLM key or provider access: + +```sh +docker run --detach \ + --name nosrc \ + --restart unless-stopped \ + --publish 8080:8080 \ + --volume "$PWD/dist:/bundle:ro" \ + ghcr.io/nonops/nosrc:v0.1 \ + serve --bundle /bundle --bind 0.0.0.0 --port 8080 +``` + +The bind mount is read-only. Keep the bundle directory operator-controlled. For a live synthesis workflow, run the binary directly with an operator SPEC and configure `LLM_API_KEY` through your secret manager; do not bake credentials into an image. + +## systemd supervision + +Release builds use `panic = "abort"`: an unexpected host panic exits the process. Run nosrc under a supervisor so it is restarted after an unexpected exit. For offline bundle serving, create a dedicated account and install this unit as `/etc/systemd/system/nosrc.service`: + +```ini +[Unit] +Description=nosrc verified HTTP handler +After=network.target + +[Service] +Type=simple +User=nosrc +Group=nosrc +WorkingDirectory=/var/lib/nosrc +ExecStart=/usr/local/bin/nosrc serve --bundle /var/lib/nosrc/bundle --bind 127.0.0.1 --port 8080 +Restart=on-failure +RestartSec=5 +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ProtectHome=true +ReadOnlyPaths=/var/lib/nosrc/bundle + +[Install] +WantedBy=multi-user.target +``` + +Create the `nosrc` user/group, install the exported bundle at `/var/lib/nosrc/bundle`, and grant that account read/traverse access to the bundle. Then enable the service: + +```sh +sudo systemctl daemon-reload +sudo systemctl enable --now nosrc +sudo systemctl status nosrc +``` + +Use `systemctl restart nosrc` after replacing the bundle. The unit intentionally serves an already-verified offline bundle and needs no model-provider credentials. Place a reverse proxy in front if TLS or external routing is required; nosrc defaults to loopback. + +## Health and readiness + +- `GET /healthz` reports process liveness. +- `GET /readyz` reports readiness only after a verified generation is active. +- `GET /_nosrc/status` reports active generation, readiness, and runtime telemetry. + +A supervisor restart policy handles process exit; readiness checks should be used by the surrounding deployment to decide whether the instance should receive traffic. diff --git a/docs/RELEASING.md b/docs/RELEASING.md index b1d62636..eaed2fa6 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -25,9 +25,11 @@ Cargo requires a three-component SemVer package version. Keep that internal vers git push origin v0.1 ``` -5. The Release workflow validates the tag against `Cargo.toml`, runs the Windows and macOS test suite (`platforms.yml`, about 25 minutes, because those platforms do not run on every commit), and only then creates a GitHub Release named exactly after the tag, with generated release notes. If the platform tests fail, no release is created; fix the problem, delete the tag, and tag again. +5. The Release workflow validates the tag against `Cargo.toml` and requires the tagged commit to be reachable from `main`. +6. It runs the Windows and macOS test suite (`platforms.yml`), builds Linux x86_64, Linux aarch64, macOS Apple Silicon, and Windows x86_64 (MSVC) release binaries, then smoke-tests the Linux x86_64 release binary by exporting and serving a bundle offline without provider credentials. +7. Only after every gate passes does it create the GitHub Release, upload the archives and `SHA256SUMS`, and publish the multi-architecture container image to `ghcr.io/nonops/nosrc`. -The workflow rejects tags with a patch component, prerelease suffix, or major/minor mismatch. It does not build or upload release binaries yet; binary/container distribution is a separate roadmap item. +The workflow rejects tags with a patch component, prerelease suffix, major/minor mismatch, or a commit that is not already on `main`. If a required check fails, no release is published; fix the problem, delete the tag, and tag again. Linux binaries are built on Ubuntu 24.04 and require glibc 2.39 or later. These are glibc builds, not musl/static builds. Windows x86_64 binaries are built natively with the MSVC toolchain. The container uses Debian Trixie and runs as UID/GID 10001. Checksums are integrity checks only: artifacts are not described as signed or attested. ## Validation diff --git a/tests/mcp_stdio.rs b/tests/mcp_stdio.rs index 6a54691e..20d527b8 100644 --- a/tests/mcp_stdio.rs +++ b/tests/mcp_stdio.rs @@ -2,7 +2,7 @@ use std::process::Stdio; use std::time::Duration; use serde_json::{json, Value}; -use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines}; +use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, Lines}; use tokio::process::{ChildStdin, ChildStdout, Command}; async fn send_request( @@ -30,6 +30,12 @@ async fn send_notification(stdin: &mut ChildStdin, notification: Value) { stdin.flush().await.unwrap(); } +fn nosrc_command() -> Command { + let binary = + std::env::var_os("NOSRC_TEST_BINARY").unwrap_or_else(|| env!("CARGO_BIN_EXE_nosrc").into()); + Command::new(binary) +} + fn structured_result(response: &Value) -> Value { if let Some(value) = response.pointer("/result/structuredContent") { return value.clone(); @@ -63,7 +69,7 @@ async fn stdio_protocol_supports_prepare_status_activate_and_invoke() { let spec_path = directory.path().join("SPEC.md"); std::fs::write(&spec_path, spec).unwrap(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--spec") .arg(&spec_path) @@ -291,7 +297,7 @@ async fn shared_http_listener_serves_the_generation_activated_over_mcp() { std::fs::write(&spec_path, spec).unwrap(); let http_port = free_port(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--spec") .arg(&spec_path) @@ -533,7 +539,7 @@ async fn shared_http_listener_serves_the_generation_activated_over_mcp() { async fn sigterm_stops_shared_http_and_mcp_process() { let directory = tempfile::tempdir().unwrap(); let http_port = free_port(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--http-port") .arg(http_port.to_string()) @@ -614,7 +620,7 @@ async fn sigterm_stops_shared_http_and_mcp_process() { async fn closing_mcp_stdin_stops_shared_http_and_process() { let directory = tempfile::tempdir().unwrap(); let http_port = free_port(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--http-port") .arg(http_port.to_string()) @@ -689,7 +695,7 @@ async fn closing_mcp_stdin_stops_shared_http_and_process() { #[tokio::test] async fn stdio_protocol_rejects_mistyped_tool_arguments() { - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--no-cache") .stdin(Stdio::piped()) @@ -772,7 +778,7 @@ async fn mcp_exported_generation_can_be_served_offline_without_provider_credenti let export_root = directory.path().join("exports"); std::fs::write(&spec_path, spec).unwrap(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--spec") .arg(&spec_path) @@ -889,7 +895,7 @@ async fn mcp_exported_generation_can_be_served_offline_without_provider_credenti // Offline serving is a separate process and must not require any provider settings. let port = free_port(); - let mut server = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut server = nosrc_command() .arg("serve") .arg("--bundle") .arg(&bundle) @@ -900,35 +906,64 @@ async fn mcp_exported_generation_can_be_served_offline_without_provider_credenti .env_remove("LLM_MODEL") .stdin(Stdio::null()) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(Stdio::piped()) .kill_on_drop(true) .spawn() .expect("failed to start offline bundle server"); + let mut stderr = server.stderr.take().expect("server stderr must be piped"); + let stderr_task = tokio::spawn(async move { + let mut bytes = Vec::new(); + stderr.read_to_end(&mut bytes).await.unwrap(); + String::from_utf8_lossy(&bytes).into_owned() + }); + let client = reqwest::Client::builder() + .timeout(Duration::from_secs(5)) + .build() + .expect("failed to build bounded HTTP client"); let deadline = tokio::time::Instant::now() + Duration::from_secs(30); loop { - if tokio::net::TcpStream::connect(("127.0.0.1", port)) + if let Some(status) = server.try_wait().expect("failed to inspect server process") { + let server_stderr = stderr_task.await.unwrap(); + panic!( + "offline bundle server exited before becoming healthy ({status}); stderr: {server_stderr}" + ); + } + let last_probe_error = match client + .get(format!("http://127.0.0.1:{port}/healthz")) + .send() .await - .is_ok() { - let health = raw_http(port, &simple_get("/healthz")).await; - if health.starts_with("HTTP/1.1 200") { - break; - } + Ok(response) if response.status().is_success() => break, + Ok(response) => format!("health endpoint returned {}", response.status()), + Err(error) => error.to_string(), + }; + if tokio::time::Instant::now() >= deadline { + let _ = server.kill().await; + let _ = server.wait().await; + let server_stderr = stderr_task.await.unwrap(); + panic!( + "offline bundle server did not become healthy: {last_probe_error}; stderr: {server_stderr}" + ); } - assert!( - tokio::time::Instant::now() < deadline, - "offline bundle server did not become healthy" - ); tokio::time::sleep(Duration::from_millis(100)).await; } - let response = raw_http(port, &simple_get("/health")).await; - assert!(response.starts_with("HTTP/1.1 200"), "{response}"); - assert!(response.ends_with("offline"), "{response}"); + let response = client + .get(format!("http://127.0.0.1:{port}/health")) + .send() + .await + .expect("offline health endpoint request failed"); + assert_eq!(response.status(), reqwest::StatusCode::OK); + assert_eq!( + response.text().await.unwrap(), + "offline", + "offline health endpoint returned an unexpected body" + ); server.kill().await.unwrap(); let _ = server.wait().await; + let _ = stderr_task.await.unwrap(); } #[tokio::test] @@ -953,7 +988,7 @@ async fn stdio_guest_trap_is_isolated_and_instance_recovers() { let spec_path = directory.path().join("SPEC.md"); std::fs::write(&spec_path, spec).unwrap(); - let mut child = Command::new(env!("CARGO_BIN_EXE_nosrc")) + let mut child = nosrc_command() .arg("mcp") .arg("--spec") .arg(&spec_path)