Skip to content

Commit 193adc4

Browse files
refactor(tests): simplify the test runner and tmachine
- Replace tmachine's global QEMU PID registry with until_signal, which drops the work on SIGTERM/SIGINT/SIGHUP so kill_on_drop stops QEMU. This also lets Ctrl-C end a --keep run. - Decide a run's status from nextest's exit code (with --no-tests fail) instead of parsing JUnit; print the end of the nextest log on failure. - Move gateway diagnostics from tmachine's Session into the runner, drop Session::run_playbooks, and make Session own its VM directly. - Read TMACHINE_SSH_PORT once and reject invalid values; drop the racy port pre-check. - Build the runner with Nix so tmachine's firmware paths are compiled in, and set ANSIBLE_CONFIG only in the wrapper. - Copy the bundle directory in directly, fold lib.rs into main.rs, and make the gateway name required. - Drop the semver hint from the lockfile alignment check and trim duplicated docs. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 0182e21 commit 193adc4

21 files changed

Lines changed: 302 additions & 737 deletions

File tree

‎.agents/skills/watch-github-actions/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ gh run list --json databaseId,status,headBranch,url --jq '.[] | {id: .databaseId
127127

128128
For tmachine Kubernetes conformance failures, inspect the `tmachine-diagnostics-*` artifact. The K3s report includes Agent Sandbox controller state, leader leases, events, and current and previous controller logs. The conformance playbook checks reconciliation after guest boot with a temporary scheduling-gated Sandbox probe before running tests. Distinguish a failed controller probe from a failed conformance scenario; gateway connectivity and controller Deployment availability do not prove reconciliation works.
129129

130-
For the `e2e-suites` lane (`.github/workflows/e2e-suites.yml`), the last lines of the job log give the runner's result: PASS, FAIL with the failed tests, or ERROR with the step that broke. Then inspect the `e2e-results-<family>-<package>-<environment>-<installer>` artifact, which holds `junit.xml`, `nextest.log` and, after a failure, the guest's `diagnostics/`.
130+
For the `e2e-suites` lane (`.github/workflows/e2e-suites.yml`), the last lines of the job log give the runner's result: PASS, FAIL after the end of the nextest log (which names the failed tests), or ERROR with the step that broke. Then inspect the `e2e-results-<family>-<package>-<environment>-<installer>` artifact, which holds `junit.xml`, `nextest.log` and, after a failure, the guest's `diagnostics/`.
131131

132132
`Pre-release` temporarily omits Codex Security from its `Security Scan` job.
133133
`Release` uses the passing prerelease qualification result. Other scanners and

‎AGENTS.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ Do not rely on this file for a full inventory. The detailed public and contribut
6464
| `proto/` | Protobuf definitions | gRPC service contracts |
6565
| `tests/testkit/` | E2E testkit | Support library and `#[testkit::test]` attribute for SDK-driven E2E suites |
6666
| `tests/suites/` | E2E suites | One directory per test family, such as `conformance` |
67-
| `tests/tmachine/` | Test machines | QEMU machines provisioned with Ansible, and the `Session` API that drives them |
68-
| `tests/runner/` | Test runner | `openshell-test-runner`: runs a test family in a tmachine environment and checks the results |
6967
| `deploy/` | Docker, Helm, K8s | Dockerfiles, Helm chart, manifests |
7068
| `docs/` | Published docs | MDX pages, navigation, and content assets |
7169
| `fern/` | Docs site config | Fern site config, components, and theme assets |

‎TESTING.md‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ gateway with:
151151
mise run e2e:testkit
152152
```
153153

154-
That task runs `e2e/with-docker-gateway.sh`, which starts a gateway and exports
155-
`OPENSHELL_GATEWAY` and `OPENSHELL_BIN`, so the suite runs the same way the
156-
runner runs it in a guest.
157-
158154
Workspaces that build root crates through path dependencies must lock shared
159155
crates at the versions in the root `Cargo.lock`; otherwise CI can build against
160156
dependencies the Nix toolchain doesn't support. `mise run rust:lockfiles:check`
@@ -173,27 +169,18 @@ nix run .#openshell-test-runner -- \
173169
--family conformance --package sandbox
174170
```
175171

176-
It:
177-
178-
1. builds the family's packages on the host as a nextest archive for the
179-
guest's musl target, with `testkit-ready`;
180-
2. boots the tmachine environment with the installer (this needs KVM, and
181-
tmachine only boots guests of the host's architecture);
182-
3. copies the archive in, waits for the gateway with `testkit-ready`, and runs
183-
the tests with the guest's `cargo-nextest`, pointing them at the installed
184-
CLI (`OPENSHELL_BIN`) and the gateway the installer registered
185-
(`OPENSHELL_GATEWAY`, `--gateway`, default `openshell`);
186-
4. writes `junit.xml`, `nextest.log` and, after a failure, the guest's
187-
diagnostics to `artifacts/test-results/` (`--results`);
188-
5. shuts the VM down, also on failure or SIGTERM.
189-
190-
A run passes if nextest succeeds and its JUnit report shows at least one test
191-
and no failures. `--filter <filterset>` narrows the tests with a nextest
192-
filterset, and `--keep` leaves the VM running until you press Enter. Every SSH
193-
and nextest step has a timeout. Two runs on one host need different
194-
`TMACHINE_SSH_PORT` values (default 2222). The installer inputs, such as the
195-
Debian package and the images, come from `artifacts/`, built by
196-
`nix run .#build-artifacts` or downloaded by CI.
172+
It needs KVM, and tmachine only boots guests of the host's architecture. The
173+
runner points the tests at the installed CLI and the gateway the installer
174+
registered (`--gateway`, default `openshell`). A run passes if nextest
175+
succeeds; nextest fails a run with no tests. The runner writes `junit.xml`,
176+
`nextest.log` and, after a failure, the guest's diagnostics to
177+
`artifacts/test-results/` (`--results`).
178+
179+
`--filter <filterset>` narrows the tests with a nextest filterset, and
180+
`--keep` leaves the VM running until you press Enter. Two runs on one host
181+
need different `TMACHINE_SSH_PORT` values (default 2222). The installer
182+
inputs, such as the Debian package and the images, come from `artifacts/`,
183+
built by `nix run .#build-artifacts` or downloaded by CI.
197184

198185
A flaky or broken test is marked `#[ignore = "<issue link>"]`, which takes it
199186
out of every environment until it's fixed.

‎tasks/scripts/check_cargo_lockfile_alignment.py‎

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from __future__ import annotations
2626

2727
import argparse
28-
import re
2928
import shutil
3029
import subprocess
3130
import sys
@@ -48,27 +47,6 @@ class Mismatch:
4847
version: str
4948
root_versions: tuple[str, ...]
5049

51-
def target(self) -> str | None:
52-
"""The root version semver-compatible with the locked one, if any."""
53-
key = compat_key(self.version)
54-
candidates = [v for v in self.root_versions if compat_key(v) == key]
55-
return max(candidates, key=version_tuple) if candidates else None
56-
57-
58-
def version_tuple(version: str) -> tuple[int, ...]:
59-
core = re.split(r"[-+]", version, maxsplit=1)[0]
60-
return tuple(int(part) for part in core.split("."))
61-
62-
63-
def compat_key(version: str) -> tuple[int, ...]:
64-
"""Cargo's caret-compatibility class: the leftmost non-zero component."""
65-
major, minor, patch = (*version_tuple(version), 0, 0, 0)[:3]
66-
if major:
67-
return (major,)
68-
if minor:
69-
return (0, minor)
70-
return (0, 0, patch)
71-
7250

7351
def registry_versions(lockfile: Path) -> dict[str, set[str]]:
7452
"""Versions of registry (non-path) packages in a lockfile, by name."""
@@ -89,12 +67,8 @@ def mismatches(root: Path, workspace: str) -> list[Mismatch]:
8967
shared = root_versions.get(name)
9068
if shared is None:
9169
continue
92-
for version in sorted(versions - shared, key=version_tuple):
93-
found.append(
94-
Mismatch(
95-
workspace, name, version, tuple(sorted(shared, key=version_tuple))
96-
)
97-
)
70+
for version in sorted(versions - shared):
71+
found.append(Mismatch(workspace, name, version, tuple(sorted(shared))))
9872
return found
9973

10074

@@ -125,14 +99,9 @@ def fix(root: Path, workspace: str) -> list[Mismatch]:
12599

126100
def report(problems: list[Mismatch]) -> None:
127101
for m in problems:
128-
target = m.target()
129-
hint = (
130-
f"; root has {target}"
131-
if target
132-
else f"; root has {', '.join(m.root_versions)}"
133-
)
134102
print(
135-
f"error: {m.workspace}: {m.name} {m.version} is not in the root Cargo.lock{hint}",
103+
f"error: {m.workspace}: {m.name} {m.version} is not in the root Cargo.lock;"
104+
f" root has {', '.join(m.root_versions)}",
136105
file=sys.stderr,
137106
)
138107

‎tasks/scripts/check_cargo_lockfile_alignment_test.py‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ def lockfile(path: Path, packages: list[tuple[str, str, bool]]) -> None:
3333
path.write_text("version = 4\n\n" + "\n".join(entries))
3434

3535

36-
def test_compat_key_follows_cargo_caret_rules() -> None:
37-
assert alignment.compat_key("1.52.1") == (1,)
38-
assert alignment.compat_key("0.44.0") == (0, 44)
39-
assert alignment.compat_key("0.0.3") == (0, 0, 3)
40-
assert alignment.compat_key("1.0.4+wasi-0.2.12") == (1,)
41-
42-
4336
def test_reports_shared_registry_crates_at_other_versions(tmp_path: Path) -> None:
4437
lockfile(
4538
tmp_path / "Cargo.lock",
@@ -63,21 +56,12 @@ def test_reports_shared_registry_crates_at_other_versions(tmp_path: Path) -> Non
6356

6457
found = alignment.mismatches(tmp_path, "ws")
6558

66-
assert [(m.name, m.version, m.target()) for m in found] == [
67-
("rand", "0.9.5", "0.9.4"),
68-
("tokio", "1.53.1", "1.52.1"),
59+
assert [(m.name, m.version, m.root_versions) for m in found] == [
60+
("rand", "0.9.5", ("0.8.6", "0.9.4")),
61+
("tokio", "1.53.1", ("1.52.1",)),
6962
]
7063

7164

72-
def test_no_target_without_a_compatible_root_version(tmp_path: Path) -> None:
73-
lockfile(tmp_path / "Cargo.lock", [("syn", "1.0.109", True)])
74-
lockfile(tmp_path / "ws" / "Cargo.lock", [("syn", "2.0.119", True)])
75-
76-
(found,) = alignment.mismatches(tmp_path, "ws")
77-
78-
assert found.target() is None
79-
80-
8165
def test_aligned_lockfiles_pass(tmp_path: Path) -> None:
8266
lockfile(tmp_path / "Cargo.lock", [("tokio", "1.52.1", True)])
8367
lockfile(tmp_path / "ws" / "Cargo.lock", [("tokio", "1.52.1", True)])

‎tests/runner/default.nix‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{
5+
lib,
6+
OVMF,
7+
rustPlatform,
8+
stdenv,
9+
}:
10+
11+
rustPlatform.buildRustPackage {
12+
pname = "openshell-test-runner";
13+
version = "0.0.0";
14+
15+
# The runner and the tmachine crate it depends on by path, and nothing else,
16+
# so edits to the suites or the Ansible tree do not rebuild it.
17+
src = lib.fileset.toSource {
18+
root = ../.;
19+
fileset = lib.fileset.unions [
20+
./Cargo.toml
21+
./Cargo.lock
22+
./src
23+
../tmachine/Cargo.toml
24+
../tmachine/src
25+
];
26+
};
27+
cargoRoot = "runner";
28+
buildAndTestSubdir = "runner";
29+
cargoLock.lockFile = ./Cargo.lock;
30+
31+
# tmachine compiles the firmware paths in.
32+
env = lib.optionalAttrs stdenv.hostPlatform.isAarch64 {
33+
TMACHINE_FIRMWARE_CODE = OVMF.firmware;
34+
TMACHINE_FIRMWARE_VARS = OVMF.variables;
35+
};
36+
}

‎tests/runner/src/bundle.rs‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! Building a family's test bundle for the guest, on the host.
55
//!
6-
//! A bundle is a tar holding a nextest archive built for the guest target,
6+
//! A bundle is a directory holding a nextest archive built for the guest target,
77
//! the family workspace's `Cargo.toml` files (for `--workspace-remap`), a
88
//! `nextest` config with the runner's `JUnit` profile, and `testkit-ready`,
99
//! which waits for the gateway before the tests run. The guest needs only the
@@ -34,9 +34,13 @@ slow-timeout = { period = "30s", terminate-after = 4 }
3434
path = "junit.xml"
3535
"#;
3636

37-
pub struct Bundle {
38-
pub path: PathBuf,
39-
_dir: TempDir,
37+
/// The bundle directory, removed when this is dropped.
38+
pub struct Bundle(TempDir);
39+
40+
impl Bundle {
41+
pub fn path(&self) -> &Path {
42+
self.0.path()
43+
}
4044
}
4145

4246
/// The Rust target for guests. tmachine only boots guests of the host's
@@ -106,8 +110,7 @@ fn built_executable(messages: &[u8], name: &str) -> Option<PathBuf> {
106110
/// the guest's `testkit-ready`.
107111
pub fn build(workspace: &Path, packages: &[String], target: &str, ready: &Path) -> Result<Bundle> {
108112
let dir = tempfile::tempdir().context("create bundle directory")?;
109-
let stage = dir.path().join("stage");
110-
std::fs::create_dir(&stage)?;
113+
let stage = dir.path();
111114
let manifest = workspace.join("Cargo.toml");
112115
ensure!(
113116
manifest.is_file(),
@@ -130,20 +133,11 @@ pub fn build(workspace: &Path, packages: &[String], target: &str, ready: &Path)
130133
}
131134
run(&mut command).with_context(|| format!("build the {} test archive", workspace.display()))?;
132135

133-
copy_manifests(workspace, &stage)?;
136+
copy_manifests(workspace, stage)?;
134137
std::fs::write(stage.join("nextest.toml"), NEXTEST_CONFIG)?;
135138
std::fs::copy(ready, stage.join(READY_BINARY))
136139
.with_context(|| format!("copy {}", ready.display()))?;
137-
138-
let path = dir.path().join("tests.tar");
139-
run(Command::new("tar")
140-
.arg("-C")
141-
.arg(&stage)
142-
.arg("-cf")
143-
.arg(&path)
144-
.arg("."))
145-
.context("pack test bundle")?;
146-
Ok(Bundle { path, _dir: dir })
140+
Ok(Bundle(dir))
147141
}
148142

149143
/// Copy every `Cargo.toml` under `workspace` into `stage`, keeping relative

0 commit comments

Comments
 (0)