Skip to content

Latest commit

 

History

History
103 lines (87 loc) · 7 KB

README.md

File metadata and controls

103 lines (87 loc) · 7 KB

Conformance suites

The conformance crate holds the testkit suites for sandbox behavior that every compute driver must provide. The family is this one crate, its own workspace. It is a library of suites, one module each in src/, and the openshell-conformance program that runs them. The program is the crate's test target (harness = false), so openshell-conformance run, cargo test --bin openshell-conformance and cargo nextest run --bin openshell-conformance all run the same code.

Suite Covers
smoke Create a sandbox, run echo in it, delete it
lifecycle SDK: long-running and run-to-completion sandboxes, prompt delete when the workload is slow to handle TERM, the default command, restart of a stopped sandbox, deleting a stopped sandbox, exec past the startup recovery deadline, the final phase when the main command exits, the main command's environment, --no-keep cleanup
cli The same lifecycle through the openshell CLI: status, create, get, list, exec, stop, start, delete; attached sandbox create -- <command> streams the main process and reports its exit code; --no-keep deletes the sandbox afterwards
exec-cli sandbox exec through the CLI: complete large output, piped stdin up to the 4 MiB limit, early exit, a forced TTY, unreadable stdin
attach sandbox connect to the main process: one input owner, read-only viewers, history replay on reconnect, stop and start while attached, a main exit of 255
ssh The SSH host key: the same in get, list, and ssh; kept across stop and start; new for a recreated sandbox
persistent-workspace Files in /sandbox survive stop and start
policy-advisor policy.local accepts a proposed rule; a denied address or hostname yields one draft rule
file-transfer sandbox upload and download: round trips, file modes and symlinks outside the workspace, .gitignore filtering, workspace-escape and option-looking names, a large upload
create-upload sandbox create --upload: directory basename and nested files, multiple uploads, a single file
credential-gating Provider credentials: admission of credentialed endpoints, REST header and body placeholders and rewriting, WebSocket text and binary frames, live policy binding, static credentials bound to their profile endpoints
network Direct connections that bypass the proxy are denied; reserved destinations fail with EACCES; localhost works without proxy settings; closed listeners release their ports
network-l7 REST, GraphQL, JSON-RPC, and MCP rules allow and deny requests; REST upgrades are refused
network-egress Transparent egress: policy reloads close open connections, ambiguous updates are rejected, tls: skip relays raw bytes, middleware redacts or blocks traffic, pipelined requests are authorized one at a time
policy-update policy set and policy update: revisions and versions, repeated updates, scoped endpoint changes, the revision for a sparse initial policy
port-forward forward start reaches a server on the sandbox's loopback; forward stop closes the port
image A sandbox runs the default image or the one it is created from
labels Labels are stored and select sandboxes in sandbox list
templates A sandbox created from a template uses its workload; duplicate, deleted and missing templates return the right errors
settings Sandbox-scoped settings
workspaces Workspace create, get, list and delete; a template is scoped to its workspace; a workspace holding a resource goes Terminating, rejects creates and deletes once empty
process Core dumps are disabled for sandbox processes
filesystem-policy Landlock: a hard requirement accepts added device paths; a replaced policy path rejects the next launch

smoke is the smallest end-to-end check that the runner can run a real test in a tmachine environment on CI. The other suites are ports of the old conformance/cli scenarios and of Evan Lezar's suites in #4629 (credited in each file). file-transfer runs git on the machine that runs the tests, so a test environment needs it installed (tests/tmachine/ansible/playbooks/test-tools.yaml does that for the tmachine environments). credential-gating, network, network-l7, and network-egress start servers (tests/support/host-server) on the machine that runs the tests and reaches them from sandboxes created from testkit::python_image() through host.openshell.internal. ssh runs ssh and ssh-keygen there and needs a named gateway, which sandbox ssh-config writes into its ProxyCommand.

Running it

TESTING.md covers running it against a local Docker gateway and in a tmachine VM, as CI does.

The openshell-conformance program

openshell-conformance runs the suite against a gateway without cargo or nextest, so a driver author or operator can check their own gateway. It finds the gateway and the CLI as the tests do. Build it and run it with:

cargo build --locked --manifest-path tests/suites/conformance/Cargo.toml --bin openshell-conformance
tests/suites/conformance/target/debug/openshell-conformance list
tests/suites/conformance/target/debug/openshell-conformance ready
tests/suites/conformance/target/debug/openshell-conformance run --junit conformance.xml

The program runs only this suite: passing it means a gateway meets the conformance contract below. The machine that runs it must be reachable from sandboxes as host.openshell.internal, which rules out a gateway on a remote Kubernetes cluster (#5409). Feature and driver suites are not part of it. The testkit README describes the commands and exit codes. tasks/scripts/check-conformance-program.sh checks that it lists the same tests as nextest.

See Unsupported tests to skip a test in specific CI environments.

Adding a test

Add a #[testkit::test] function to a suite, or for a new area, a new file in src/ and a mod line for it in src/lib.rs. openshell-conformance includes every test in the crate.

Tests must be safe to run concurrently on a shared gateway; see What a conformance test may assert.

What a test may assert

These tests run on every compute driver, so they check the public contract and leave driver behavior alone.

  • Assert only what the public contract promises: the proto comments and the published docs.
  • Assert phase and exit_code. Don't assert condition reasons.
  • Check that something did not happen by reading state, not by sleeping.
  • Don't test behavior that only some drivers have. A test that can't pass on every environment isn't conformance; put it in tests/suites/features or tests/suites/drivers.
  • Use the CLI for upload, download, connect and forward. Rely on its exit code and --output json.
  • Add a testkit helper instead of calling raw gRPC from a test.