Skip to content

Commit e8ed61d

Browse files
committed
feat(conformance): add standalone CLI runner
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 3a6d29d commit e8ed61d

15 files changed

Lines changed: 450 additions & 71 deletions

File tree

‎AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ These pipelines connect skills into end-to-end workflows. Individual skill files
3030
| Path | Components | Purpose |
3131
|------|-----------|---------|
3232
| `crates/openshell-cli/` | CLI binary | User-facing command-line interface |
33+
| `crates/openshell-conformance/` | CLI conformance library | Reusable driver-agnostic scenarios and command runner |
34+
| `crates/openshell-conformance-cli/` | Conformance CLI | Distributable `list` and `run` entrypoint for gateway conformance |
3335
| `crates/openshell-server/` | Gateway server | Control-plane API, sandbox lifecycle, auth boundary |
3436
| `crates/openshell-sandbox/` | Sandbox runtime | Container supervision, policy-enforced egress routing |
3537
| `crates/openshell-policy/` | Policy engine | Filesystem, network, process, and inference constraints |

‎Cargo.lock‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎architecture/build.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ OpenShell builds these main artifacts:
1212
|---|---|
1313
| Gateway binary | `crates/openshell-server` |
1414
| CLI binaries and system packages | `crates/openshell-cli` plus release packaging |
15+
| E2E conformance CLI | `crates/openshell-conformance-cli` |
1516
| Python SDK wheel | `python/openshell` |
1617
| TypeScript SDK package | `sdk/typescript` |
1718
| Gateway container image | `deploy/docker/Dockerfile.gateway` |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
name = "openshell-conformance-cli"
6+
description = "Standalone OpenShell CLI conformance test runner"
7+
version.workspace = true
8+
edition.workspace = true
9+
rust-version.workspace = true
10+
license.workspace = true
11+
repository.workspace = true
12+
13+
[[bin]]
14+
name = "openshell-conformance"
15+
path = "src/main.rs"
16+
17+
[dependencies]
18+
clap.workspace = true
19+
openshell-conformance = { path = "../openshell-conformance" }
20+
serde.workspace = true
21+
serde_json.workspace = true
22+
tokio.workspace = true
23+
24+
[lints]
25+
workspace = true
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Standalone runner for `OpenShell` CLI conformance scenarios.
5+
6+
use std::path::PathBuf;
7+
use std::process::ExitCode;
8+
9+
use clap::{Parser, Subcommand, ValueEnum};
10+
use openshell_conformance::{OpenShellRunner, Scenario, scenario, scenarios};
11+
use serde::Serialize;
12+
13+
#[derive(Debug, Parser)]
14+
#[command(
15+
name = "openshell-conformance",
16+
about = "Run OpenShell CLI conformance scenarios",
17+
version
18+
)]
19+
struct Cli {
20+
#[command(subcommand)]
21+
command: Command,
22+
}
23+
24+
#[derive(Debug, Subcommand)]
25+
enum Command {
26+
/// List registered scenarios.
27+
List {
28+
#[arg(long, value_enum, default_value_t = OutputFormat::Text)]
29+
output: OutputFormat,
30+
},
31+
/// Run all registered scenarios, or named scenarios.
32+
Run {
33+
/// Scenario names. Omit to run every registered scenario.
34+
scenarios: Vec<String>,
35+
/// Explicit path to the `OpenShell` CLI. Defaults to `openshell` on PATH.
36+
#[arg(long)]
37+
openshell_bin: Option<PathBuf>,
38+
#[arg(long, value_enum, default_value_t = OutputFormat::Text)]
39+
output: OutputFormat,
40+
},
41+
}
42+
43+
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
44+
enum OutputFormat {
45+
Text,
46+
Json,
47+
}
48+
49+
#[derive(Serialize)]
50+
struct ScenarioDescription<'a> {
51+
name: &'a str,
52+
description: &'a str,
53+
}
54+
55+
#[derive(Serialize)]
56+
struct ScenarioResult<'a> {
57+
name: &'a str,
58+
passed: bool,
59+
diagnostic: Option<String>,
60+
}
61+
62+
#[derive(Serialize)]
63+
struct RunReport<'a> {
64+
scenarios: Vec<ScenarioResult<'a>>,
65+
passed: bool,
66+
}
67+
68+
#[tokio::main]
69+
async fn main() -> ExitCode {
70+
match execute(Cli::parse()).await {
71+
Ok(()) => ExitCode::SUCCESS,
72+
Err(error) => {
73+
eprintln!("openshell-conformance: {error}");
74+
ExitCode::FAILURE
75+
}
76+
}
77+
}
78+
79+
async fn execute(cli: Cli) -> Result<(), String> {
80+
match cli.command {
81+
Command::List { output } => list(output),
82+
Command::Run {
83+
scenarios: requested,
84+
openshell_bin,
85+
output,
86+
} => run(&requested, openshell_bin, output).await,
87+
}
88+
}
89+
90+
fn list(output: OutputFormat) -> Result<(), String> {
91+
match output {
92+
OutputFormat::Text => {
93+
for candidate in scenarios() {
94+
println!("{:<16} {}", candidate.name, candidate.description);
95+
}
96+
}
97+
OutputFormat::Json => {
98+
let result = scenarios()
99+
.iter()
100+
.map(|candidate| ScenarioDescription {
101+
name: candidate.name,
102+
description: candidate.description,
103+
})
104+
.collect::<Vec<_>>();
105+
println!(
106+
"{}",
107+
serde_json::to_string_pretty(&result).map_err(|error| error.to_string())?
108+
);
109+
}
110+
}
111+
Ok(())
112+
}
113+
114+
async fn run(
115+
requested: &[String],
116+
binary: Option<PathBuf>,
117+
output: OutputFormat,
118+
) -> Result<(), String> {
119+
let selected = select_scenarios(requested)?;
120+
let mut results = Vec::with_capacity(selected.len());
121+
for candidate in selected {
122+
let runner = binary.as_ref().map_or_else(
123+
|| OpenShellRunner::new(candidate.name),
124+
|path| OpenShellRunner::with_binary(path.clone(), candidate.name),
125+
);
126+
let mut runner = match runner {
127+
Ok(runner) => runner,
128+
Err(error) => {
129+
results.push(ScenarioResult {
130+
name: candidate.name,
131+
passed: false,
132+
diagnostic: Some(error.to_string()),
133+
});
134+
continue;
135+
}
136+
};
137+
eprintln!("CLI conformance run ID: {}", runner.id());
138+
let scenario_result = match runner.check_gateway_status().await {
139+
Ok(()) => candidate.run(&mut runner).await,
140+
Err(error) => Err(error),
141+
};
142+
let outcome = runner.finish(scenario_result).await;
143+
results.push(ScenarioResult {
144+
name: candidate.name,
145+
passed: outcome.is_ok(),
146+
diagnostic: outcome.err(),
147+
});
148+
}
149+
150+
let passed = results.iter().all(|result| result.passed);
151+
match output {
152+
OutputFormat::Text => {
153+
for result in &results {
154+
if result.passed {
155+
println!("PASS {}", result.name);
156+
} else {
157+
println!(
158+
"FAIL {}\n{}",
159+
result.name,
160+
result.diagnostic.as_deref().unwrap_or("unknown failure")
161+
);
162+
}
163+
}
164+
}
165+
OutputFormat::Json => println!(
166+
"{}",
167+
serde_json::to_string_pretty(&RunReport {
168+
scenarios: results,
169+
passed
170+
})
171+
.map_err(|error| error.to_string())?
172+
),
173+
}
174+
if passed {
175+
Ok(())
176+
} else {
177+
Err("one or more scenarios failed".to_string())
178+
}
179+
}
180+
181+
fn select_scenarios(requested: &[String]) -> Result<Vec<&'static Scenario>, String> {
182+
if requested.is_empty() {
183+
return Ok(scenarios().iter().collect());
184+
}
185+
requested
186+
.iter()
187+
.map(|name| {
188+
scenario(name).ok_or_else(|| {
189+
format!("unknown scenario '{name}'; run `openshell-conformance list`")
190+
})
191+
})
192+
.collect()
193+
}
194+
195+
#[cfg(test)]
196+
mod tests {
197+
use clap::Parser;
198+
199+
use super::*;
200+
201+
#[test]
202+
fn selects_all_scenarios_by_default() {
203+
assert_eq!(
204+
select_scenarios(&[]).expect("select all").len(),
205+
scenarios().len()
206+
);
207+
}
208+
209+
#[test]
210+
fn selects_named_scenario() {
211+
let selected = select_scenarios(&["smoke".to_string()]).expect("select smoke");
212+
assert_eq!(selected[0].name, "smoke");
213+
}
214+
215+
#[test]
216+
fn unknown_scenario_has_actionable_diagnostic() {
217+
let error = select_scenarios(&["missing".to_string()]).expect_err("unknown scenario");
218+
assert!(error.contains("openshell-conformance list"));
219+
}
220+
221+
#[test]
222+
fn parses_binary_override_and_json_output() {
223+
let cli = Cli::try_parse_from([
224+
"openshell-conformance",
225+
"run",
226+
"smoke",
227+
"--openshell-bin",
228+
"/opt/openshell",
229+
"--output",
230+
"json",
231+
])
232+
.expect("parse CLI");
233+
let Command::Run {
234+
openshell_bin,
235+
output,
236+
..
237+
} = cli.command
238+
else {
239+
panic!("expected run")
240+
};
241+
assert_eq!(openshell_bin, Some(PathBuf::from("/opt/openshell")));
242+
assert_eq!(output, OutputFormat::Json);
243+
}
244+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
name = "openshell-conformance"
6+
description = "Reusable OpenShell CLI conformance scenarios and runner"
7+
version.workspace = true
8+
edition.workspace = true
9+
rust-version.workspace = true
10+
license.workspace = true
11+
repository.workspace = true
12+
13+
[dependencies]
14+
rand.workspace = true
15+
serde.workspace = true
16+
serde_json.workspace = true
17+
tokio.workspace = true
18+
19+
[dev-dependencies]
20+
tempfile = "3"
21+
22+
[lints]
23+
workspace = true

e2e/rust/src/harness/conformance/executor.rs renamed to crates/openshell-conformance/src/executor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ use std::time::Duration;
1111

1212
use tokio::time::timeout;
1313

14-
pub(super) type CliExecution<'a> =
14+
pub type CliExecution<'a> =
1515
Pin<Box<dyn Future<Output = Result<Output, CliExecutionError>> + Send + 'a>>;
1616

17-
pub(super) trait CliExecutor: Send + Sync {
17+
pub trait CliExecutor: Send + Sync {
1818
fn execute(&self, args: Vec<String>, command_timeout: Duration) -> CliExecution<'_>;
1919
}
2020

21-
pub(super) enum CliExecutionError {
21+
pub enum CliExecutionError {
2222
Spawn(std::io::Error),
2323
Timeout,
2424
}
2525

26-
pub(super) struct ProcessCli {
26+
pub struct ProcessCli {
2727
binary: PathBuf,
2828
}
2929

3030
impl ProcessCli {
31-
pub(super) fn new(binary: PathBuf) -> Self {
31+
pub fn new(binary: PathBuf) -> Self {
3232
Self { binary }
3333
}
3434
}

0 commit comments

Comments
 (0)