11# testkit
22
3- Shared support for end-to-end test suites under ` tests/suites/ ` . Suites test
4- a running OpenShell gateway through the Rust SDK and the installed ` openshell `
5- CLI. No suite uses testkit yet; existing suites move to it one at a time.
3+ Shared support for end-to-end test suites. Suites test a running OpenShell
4+ gateway through the Rust SDK and the installed ` openshell ` CLI.
65
76This is a separate Cargo workspace with its own lockfile:
87
98| Crate | Purpose |
109| ---| ---|
1110| ` testkit ` | Reads the target file, connects to the gateway, creates and cleans up sandboxes, runs the CLI. Also builds ` testkit-ready ` . |
1211| ` testkit-macros ` | The ` #[testkit::test] ` attribute. |
13- | ` testkit-spec ` | Parses ` #[testkit::test] ` functions, shared by the attribute and tools that list tests. |
1412
1513## Writing a test
1614
@@ -22,7 +20,7 @@ use testkit::Context;
2220
2321/// A long-running sandbox becomes ready, runs a command with exec, and is gone
2422/// from get and list after delete.
25- #[testkit:: test(id = " t-3tfdx240 " ) ]
23+ #[testkit:: test]
2624async fn long_running_exec_delete (cx : & mut Context ) -> testkit :: Result {
2725 let sandbox = cx . sandbox (" lr" ). command ([" sleep" , " infinity" ]). create (). await ? ;
2826 sandbox . wait_ready (). await ? ;
@@ -31,44 +29,25 @@ async fn long_running_exec_delete(cx: &mut Context) -> testkit::Result {
3129}
3230```
3331
34- - ** ` id ` is required.** Use ` t- ` followed by eight random lowercase letters or
35- digits. Results and coverage records refer to tests by this ID, so never
36- change or reuse it, including when you rename or move the test. Omit ` id `
37- on a new test and the compile error suggests a fresh one.
3832- ** The doc comment is required.** It is the test's description.
39- - ** ` requires ` declares capabilities** the test needs, for example
40- ` #[testkit::test(id = "...", requires = [service_exposure])] ` . The names are
41- the boolean fields of ` capabilities ` in the target file. An unknown name
42- fails to compile. If the target lacks a required capability, the test
43- fails rather than passing untested. See
44- [ Excluding tests by capability] ( #excluding-tests-by-capability ) .
45- - ** The function name is the nextest test name.** Rename it freely; the ID
46- keeps the history.
33+ - ** The function name is the nextest test name.**
4734
4835Cleanup runs after every test, whether it passes, fails, or panics. It only
4936deletes sandboxes created through ` cx.sandbox(...) ` . Delete anything else a
5037test creates, such as providers, in the test itself.
5138
52- ## What a conformance test may assert
53-
54- A conformance test asserts only what the public contract promises: the
55- comments in ` proto/ ` and the published docs, such as the sandbox lifecycle in
56- ` docs/how-it-works/sandboxes/overview.mdx ` . Do not encode gateway behavior
57- the contract does not state; file an issue to document it instead.
58-
59- - Assert on a sandbox's ` phase ` and ` exit_code ` , not condition reasons, which
60- the API leaves to the platform.
61- - To check that something did not happen, read state (for example,
62- ` restart_count ` is 0 and a second read shows the same phase) instead of
63- sleeping and watching.
64- - Behavior the docs leave to the compute driver needs a capability in
65- ` requires ` .
66- - Act through the interface that makes the promise. Upload, download,
67- connect, and port forwarding exist only in the CLI, so call
68- ` cx.cli([...]) ` and rely on its exit code and ` --output json ` , not its
69- table text.
70- - For API calls the SDK does not wrap yet, add a testkit helper over the
71- generated gRPC client rather than calling it from tests.
39+ ## What a test can do
40+
41+ ` Context ` currently provides:
42+
43+ - ` cx.sandbox(suffix) ` to build and create a sandbox with a run-unique name.
44+ The returned ` Sandbox ` can wait for ready or finished, stop, start, exec,
45+ read its config and draft policy, set a setting, and delete.
46+ - ` cx.expect_listed ` and ` cx.expect_absent ` to check a sandbox in list and get.
47+ - ` cx.cli([...]) ` to run the installed CLI against the same gateway, with
48+ ` success() ` , ` failure() ` , and ` json() ` on the output.
49+ - ` cx.client() ` for SDK calls testkit does not wrap.
50+ - ` poll_until ` for waiting on other state.
7251
7352## Running against a gateway
7453
@@ -88,11 +67,6 @@ cli: # needed by tests that call cx.cli
8867 binary : /usr/bin/openshell # default: `openshell` on PATH
8968 gateway : local # default: the CLI's active gateway
9069workspace : default
91- capabilities :
92- compute_driver : docker
93- service_exposure : true
94- persistent_workspace : false
95- gpu : false
9670` ` `
9771
9872Wait for the gateway, then run a suite. Run tests that share a gateway one at
@@ -107,21 +81,6 @@ cargo nextest run --manifest-path <suite>/Cargo.toml --test-threads 1
10781` testkit-ready [TIMEOUT_SECS] ` exits non-zero if the gateway is not healthy in
10882time or the target's CLI does not report it connected.
10983
110- ### Excluding tests by capability
111-
112- Nothing selects tests by capability yet, so a test whose ` requires ` the target
113- does not provide fails with `requires <capability >, which the target does not
114- provide`. Find those tests and exclude them by name with a nextest filter:
115-
116- ``` shell
117- grep -rn ' requires = \[' < suite> /tests
118- cargo nextest run --manifest-path < suite> /Cargo.toml --test-threads 1 \
119- -E ' not test(=stopped_sandbox_keeps_workspace)'
120- ```
121-
122- Combine names with ` or ` inside the parentheses, for example
123- ` -E 'not (test(=a) or test(=b))' ` .
124-
12584## Checks
12685
12786``` shell
0 commit comments