Skip to main content

csp-lab

A local CubeSat Space Protocol test environment powered by libcsp. Run your application image beside two demo nodes and a ZMQ hub in Docker, then check real request/reply behavior with Python and pytest. The CLI and MCP server provide lab diagnostics.

Quick start

With uv and Docker Compose installed and Docker running:

uvx csp-lab up --protocol 2
uvx csp-lab ping 2
uvx csp-lab down

The published Python package uses its matching prebuilt Docker image, so this does not require a source checkout or a local libcsp build. The image is pulled only when it is not already present locally, so later starts work offline. You can also install the CLI with uv tool install csp-lab and run csp-lab directly.

Why use it?

The lab gives you a repeatable place to try CSP v1 and v2, check whether simulated nodes respond, and inspect failures through the CLI or MCP tools. It is useful when developing CSP integrations or experimenting with an MCP client without arranging physical CubeSat hardware.

The Python Lab API also accepts up to eight user-owned application images via Node(address=5, image="my-service:dev"). See the independent C application for the container contract, image preparation, readiness, and stop/start example. lab.request(5, port=10, payload=b"hello") returns raw application reply bytes; the example checks the service's result, binary boundaries, and timeout behavior. Custom nodes currently belong to the Python API; CLI and MCP use the demo nodes.

Lab saves failure diagnostics under artifacts/csp-lab on startup failure or an exception leaving its context. Pytest also snapshots failures in shared labs before teardown; use --csp-lab-artifacts DIRECTORY to choose its directory. Fixture snapshots follow pytest's final outcome: skips and expected failures create no bundle, while strict XPASS failures do. Each bundle keeps a manifest and the last 200 lines per service, with a 2 MiB total limit, five-second capture budget, and at most 20 bundles per lab. The saved path is printed and remains after container cleanup. The manifest records status, image IDs, operation parameters, and the exception class; it excludes environments, payloads, probe output, and exception/assertion text. Service logs are captured verbatim and can contain application data. Use Lab(artifacts_dir=None) or pytest --csp-lab-artifacts none to disable capture.

Requirements

  • Python 3.10 or newer and uv
  • Docker with Compose

The native code is built against the pinned libcsp v2.1 submodule. That library supports CSP protocol v1 and v2 at runtime. The Docker image uses Linux because recent libcsp releases do not provide maintained native macOS support. See versioning policy for the supported combinations.

Lab state is stored in ~/.local/state/csp-lab or under XDG_STATE_HOME when set, so commands work from any directory.

Start and stop operations using the same state directory are protected by a process lock. An overlapping operation fails with a retry message. State is saved atomically; if a state file is corrupt or unsupported, csp-lab down can still stop the lab and remove that file. If down cannot finish Docker cleanup, it retains the state so you can retry.

If a lab was started by the earlier checkout-based CLI, run csp-lab down from that checkout once before switching to uvx from another directory. The CLI recognizes and removes the earlier path-based Docker project there.

To test CSP v1, start a fresh lab with up --protocol 1. up refuses to change the protocol of an existing lab; run down first. The two versions never share a running network.

up waits up to 30 seconds for both demo nodes to answer a CSP ping. The CLI commands are up, down, status, topology, ping <address>, and doctor. status checks whether the hub and both nodes are running in Docker. Use --json for machine-readable output. ping and doctor return a nonzero exit code when a node does not respond. Addresses must be 1–31 for CSP v1 or 1–16383 for CSP v2. The demo nodes use addresses 2 and 3; the probe uses address 4.

MCP

Start the lab first, then configure an MCP client to launch csp-lab mcp over stdio:

{
  "mcpServers": {
    "csp-lab": {
      "command": "uvx",
      "args": ["csp-lab", "mcp"]
    }
  }
}

With uv tool install, set the command to csp-lab and the argument to mcp. GUI clients may not see the shell's PATH; use the full path to uvx or the installed csp-lab executable when needed. For a local clone after uv sync, use /absolute/path/to/csp-lab/.venv/bin/csp-lab as the command. Keep the lab running in a separate terminal while using the MCP tools.

The stdio server provides csp_topology, csp_ping, and csp_diagnose. It does not expose commands that reboot, shut down, or read or write node memory. The simulated server binds only the CSP ping service port.

Python tests

The package includes a context-managed Python API and an automatically discovered pytest fixture. Install csp-lab[pytest] in your test environment, or use uv sync --locked from a clone. Custom nodes and raw application requests require 0.3.0 or newer; during development, use the checkout with build=True.

from csp_lab import Lab

with Lab(protocol=2) as lab:
    assert lab.ping(2).reachable
    print(lab.topology().nodes)
import pytest

@pytest.mark.csp_lab(protocol=2)
def test_node_responds(csp_lab):
    assert csp_lab.ping(2).reachable

To test an application image, build the independent uppercase example, then use:

import pytest
from csp_lab import Node

@pytest.mark.csp_lab(nodes=(Node(5, "uppercase-node:dev"),))
def test_application(csp_lab):
    assert csp_lab.request(5, port=10, payload=b"hello") == b"HELLO"

Tests using csp_lab share a lab for the pytest session by default, keyed by protocol, native-build setting, and normalized nodes (address and image reference). Reordering the same nodes shares a lab; changing an image, address, or protocol creates another. Use @pytest.mark.csp_lab(scope="function", nodes=(...)) for stop/start tests. The nearest marker supplies the whole configuration; marker values are not merged, and every level is validated. If a shared lab fails to start, the remaining tests with that configuration fail immediately with the original error rather than starting it again. The fixture skips when Docker or Compose is unavailable. An interrupted process can leave containers behind: list their project names with docker ps -a --filter label=com.docker.compose.project --format '{{.Label "com.docker.compose.project"}}' | sort -u, then run csp-lab cleanup <csp-lab-py-project> for the affected project.

Each probe is created stopped on the lab's private network and started only after Docker acknowledges its ID. The caller confirms removal before returning its result, including after a timeout or interruption. If cleanup cannot be confirmed, that Lab rejects further operations; exit its context and use the reported cleanup command to recover. A killed worker's probe containers are also covered by project cleanup.

Local development

From a clone of this repository:

git submodule update --init --recursive
uv sync --locked
uv run --locked csp-lab up --protocol 2 --build
uv run --locked csp-lab ping 2 --json
uv run --locked csp-lab doctor --json
uv run --locked csp-lab down

--build compiles the native image from this checkout, so it needs the libcsp submodule. Without --build, the CLI uses the image matching its own version from GHCR.

Testing your own libcsp

Since 0.4.0, to run the hub, demo nodes, and probe on a libcsp branch of your own, such as a fix you are preparing, point up at that checkout:

uv run --locked csp-lab up --protocol 2 --libcsp-path ../libcsp
uv run --locked csp-lab doctor --json

This is the layer 2 check in the verify skill of csp-agent-skills, agent skills for libcsp work. --libcsp-path implies --build and still needs this repository's checkout for the Dockerfile. A compile error in your tree fails up and shows the compiler output. up, status, and doctor report a libcsp object with source (local), path, version from libcsp's CMakeLists.txt, revision (the checkout's commit, with -dirty when it has uncommitted changes), and labPatch. The lab's ZMQ frame guard is applied when it applies cleanly. Otherwise labPatch is skipped and your libcsp runs unmodified. Your branch must stay API-compatible with libcsp 2.1 for the lab's native node program to build. Custom node images build their own libcsp and are not affected by this option.

What is tested

uv run --locked pytest checks protocol validation, unavailable Docker, cleanup after a failed start, and unresponsive nodes without requiring Docker. Run uv run --locked ruff check src/csp_lab tests examples/custom-node/tests and uv run --locked mypy src/csp_lab for lint and types. The Docker integration flow exercises real libcsp, ZMQ, CLI/MCP, custom images, raw requests, failure artifacts, and pytest for both protocols. It requires the intentionally broken image to fail the same application assertion after readiness ping succeeds:

bash test/integration.sh

bash test/native-bounds.sh builds a separate AddressSanitizer image, verifies frame boundaries directly, and injects malformed ZMQ frames into a live hub and node for both protocol versions. The build applies the documented local libcsp guards without modifying the pinned submodule.

The GitHub Actions workflow is configured to run both checks on Ubuntu with Docker Compose. The integration script uses its own temporary XDG_STATE_HOME and unique CSP_LAB_PROJECT, and cleans only those resources on exit, including after a failure. It does not adopt checkout-based legacy labs. If cleanup fails, it reports the project and retains the temporary state for recovery.

Scope and license

This lab uses the pinned libcsp release as a build dependency and selects CSP v1 or v2 as a runtime protocol. It does not build against historical libcsp 1.x releases or operate mixed-version networks. ZMQ is the only transport in this lab. The project is licensed under MIT; the libcsp submodule retains its own license. Thanks to the libcsp and ZeroMQ projects that make the image possible; their licenses and source links are listed in THIRD_PARTY_NOTICES.md.

Metadata

Release files for csp-lab 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csp-lab 0.4.0
File Size Uploaded Provenance Actions
csp_lab-0.4.0.tar.gz 25.6 kB With provenance Details for csp_lab-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for csp-lab 0.4.0
File Interpreter ABI Platform Actions
csp_lab-0.4.0-py3-none-any.whl Python 3 none any Details for csp_lab-0.4.0-py3-none-any.whl

Total release size: 54.7 kB

Release files / csp_lab-0.4.0.tar.gz

Download URL csp_lab-0.4.0.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8c8cf85ce12c9dede248a927cdde131a795ba4a2f8b9e10001f78a83131a9f6
BLAKE2b-256 checksum
How to use checksums
25889db4576bcb22500e7f9d6ece767b57cbe7d5eab5fde7db759665b2a628c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / csp_lab-0.4.0-py3-none-any.whl

Download URL csp_lab-0.4.0-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ce89949cd8094d6df8378313d99c8f6ca6f5e175bad82b76384a08e743c38a5
BLAKE2b-256 checksum
How to use checksums
15a295778fa50cda49b3e340232a5554ccadf4d4170fdca6548b0c4f1060d3fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for csp-lab 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for csp_lab-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page