diff --git a/.github/scripts/test_ci_changes.py b/.github/scripts/test_ci_changes.py index 9c81987da6..9e907fa2c5 100644 --- a/.github/scripts/test_ci_changes.py +++ b/.github/scripts/test_ci_changes.py @@ -461,6 +461,21 @@ def assert_inventory( package_tests[1], "Build the rstack dev hosts before affected package tests", ) + evidence_runtime = self.require_step( + workflow, + "rust-tests", + "Build the Evidence runtime for evidencectl tests", + ["cargo", "build", "--locked", "-p", "registry-evidence", "--bin", "evidence"], + condition=( + "matrix.name == 'evidence' " + "&& contains(matrix.packages, 'registry-evidencectl')" + ), + ) + self.assertLess( + evidence_runtime[1], + package_tests[1], + "Build the Evidence runtime before affected package tests", + ) manifest = self.require_step( workflow, "rust-tests", @@ -1521,6 +1536,22 @@ def test_developer_tools_starts_first_in_broad_and_sparse_matrices(self) -> None self.assertEqual("developer-tools", matrix[0]["name"]) self.assertEqual(expected_shards, {row["name"] for row in matrix}) + def test_evidence_shard_can_select_the_cli_without_the_runtime(self) -> None: + for path, package in ( + ("crates/registry-evidencectl/tests/fixtures.rs", "registry-evidencectl"), + ("crates/registry-evidence-oid4vci/src/main.rs", "registry-evidence-oid4vci"), + ): + with self.subTest(path=path): + outputs = classify(self.workspace, (path,), pull_request=True) + evidence = [ + row for row in outputs["rust_matrix"]["include"] + if row["name"] == "evidence" + ] + self.assertEqual( + [{"name": "evidence", "packages": [package], "all_features": False}], + evidence, + ) + def test_bregctl_wasm_coverage_tracks_the_selected_normal_rust_suite( self, ) -> None: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e7905196d..2ac69d8816 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -996,6 +996,12 @@ jobs: -p registry-render \ -p registry-discoveryctl + # The evidencectl packaging tests resolve the matching evidence binary + # beside the CLI, even when the runtime package is outside the test selection. + - name: Build the Evidence runtime for evidencectl tests + if: matrix.name == 'evidence' && contains(matrix.packages, 'registry-evidencectl') + run: cargo build --locked -p registry-evidence --bin evidence + - name: Test affected packages run: python3 .github/scripts/run_cargo_packages.py test diff --git a/crates/registry-evidencectl/src/fixtures.rs b/crates/registry-evidencectl/src/fixtures.rs index ce1337dfc6..e37d0357dd 100644 --- a/crates/registry-evidencectl/src/fixtures.rs +++ b/crates/registry-evidencectl/src/fixtures.rs @@ -220,16 +220,33 @@ fn failed_run_diagnostic(command: &str) -> JsonValue { }) } +/// Identify the fixture project before resolving the runtime helper. Return +/// the deployment runtime path for a deployment project or `None` for an +/// editable project. A refusal already names the file from the supplied path. +pub(crate) fn preflight(project: &Path) -> Result> { + let runtime_path = project.join("runtime.yaml"); + if runtime_path.is_file() { + return Ok(Some(runtime_path)); + } + if project + .join(registry_evidence_authoring::project::PROJECT_FILE) + .is_file() + { + return Ok(None); + } + Err(crate::project_snapshot::no_project_report(project).into()) +} + pub(crate) fn run_fixtures( args: RunArgs, + runtime_path: Option, declared: registry_platform_config::DeclaredPosture, ) -> Result { - let runtime_path = args.project.join("runtime.yaml"); let evidence_bin = evidence_binary::resolve_matching(args.evidence_bin.as_deref())?; let mut editable_lock = None; // What the shared reader found in the fixture files, warnings only. let reader_warnings; - let target = if runtime_path.is_file() { + let target = if let Some(runtime_path) = runtime_path { if args.target.is_some() { bail!("--target is only used with editable projects, not deployment projects"); } @@ -247,13 +264,6 @@ pub(crate) fn run_fixtures( fixture_paths, } } else { - if !args - .project - .join(registry_evidence_authoring::project::PROJECT_FILE) - .is_file() - { - return Err(crate::project_snapshot::no_project_report(&args.project).into()); - } // The shared reader decides what a fixture file is before the project // is compiled or any step is delegated, so a file it refuses is // reported with its own diagnostics and nothing runs against it. diff --git a/crates/registry-evidencectl/src/lib.rs b/crates/registry-evidencectl/src/lib.rs index 0f4e5b3b3a..2b2e6313e7 100644 --- a/crates/registry-evidencectl/src/lib.rs +++ b/crates/registry-evidencectl/src/lib.rs @@ -760,7 +760,7 @@ fn run_entry() -> ExitCode { Command::Test(args) => { let artifact = args.project.display().to_string(); let project = args.project.clone(); - safe_command( + let result = fixtures::preflight(&project).and_then(|runtime_path| { fixtures::run_fixtures( fixtures::RunArgs { posture: None, @@ -775,9 +775,13 @@ fn run_entry() -> ExitCode { explain: args.explain, deny_warnings: args.deny_warnings, }, + runtime_path, posture, ) - .map_err(|error| authored::project_refusal(error, &project, &project)), + .map_err(|error| authored::project_refusal(error, &project, &project)) + }); + safe_command( + result, "evidence.test.failed", artifact, "Evidence could not complete the selected offline fixture run.", @@ -825,7 +829,8 @@ fn run_entry() -> ExitCode { Command::Fixtures(fixtures::FixturesCommand::Run(mut args)) => { args.json |= format == OutputFormat::Json; args.junit = junit; - fixtures::run_fixtures(args, posture) + fixtures::preflight(&args.project) + .and_then(|runtime_path| fixtures::run_fixtures(args, runtime_path, posture)) } Command::Fixtures(fixtures::FixturesCommand::RecordFacts(args)) => { let artifact = args.fixture.clone(); diff --git a/crates/registry-evidencectl/tests/fixtures.rs b/crates/registry-evidencectl/tests/fixtures.rs index 794f30fd0b..299e0d2d8b 100644 --- a/crates/registry-evidencectl/tests/fixtures.rs +++ b/crates/registry-evidencectl/tests/fixtures.rs @@ -1270,13 +1270,14 @@ fn unresolvable_evidence_binary_errors_clearly() { let output = evidencectl() .args(["fixtures", "run"]) .arg(&project) + .env_remove("RSTACK_GENERATION_DIR") .arg("--evidence-bin") .arg(&missing_bin) .output() .expect("run evidencectl"); - assert!(!output.status.success()); let stderr = stderr_of(&output); + assert_eq!(output.status.code(), Some(3), "{stderr}"); assert!(stderr.contains("evidence binary not found"), "{stderr}"); assert!( stderr.contains(missing_bin.to_str().expect("utf8 path")), diff --git a/crates/registry-evidencectl/tests/project_diagnostics.rs b/crates/registry-evidencectl/tests/project_diagnostics.rs index c7abec2e81..13bac500ee 100644 --- a/crates/registry-evidencectl/tests/project_diagnostics.rs +++ b/crates/registry-evidencectl/tests/project_diagnostics.rs @@ -6,12 +6,24 @@ use std::{fs, path::Path, process::Command}; use serde_json::Value; -fn run(command: &str, project: &Path) -> (Option, Value) { - let output = Command::new(env!("CARGO_BIN_EXE_evidencectl")) - .args(["--format", "json", command]) - .arg(project) - .output() - .expect("run evidencectl"); +fn run( + command: &str, + working_directory: &Path, + project: &Path, + evidence_bin: Option<&Path>, +) -> (Option, Value) { + let mut process = Command::new(env!("CARGO_BIN_EXE_evidencectl")); + process + .current_dir(working_directory) + .env_remove("REGISTRY_STACK_POSTURE") + .args(["--format", "json", command]); + if let Some(evidence_bin) = evidence_bin { + process + .env_remove("RSTACK_GENERATION_DIR") + .arg("--evidence-bin") + .arg(evidence_bin); + } + let output = process.arg(project).output().expect("run evidencectl"); let report = serde_json::from_slice(&output.stdout).unwrap_or_else(|error| { panic!( "invalid JSON: {error}: {}{}", @@ -53,28 +65,31 @@ const PACK: &str = "adapter-packs/synthetic-register/pack.yaml"; #[test] fn a_directory_without_evidence_yaml_is_refused_naming_the_path_given() { let temporary = tempfile::tempdir().expect("temporary directory"); - let project = temporary.path().join("old-layout"); - fs::create_dir(&project).unwrap(); - for command in ["check", "test"] { - let (code, report) = run(command, &project); - assert_eq!(code, Some(1), "{command}: {report}"); - let diagnostic = first_diagnostic(&report); - assert_eq!(diagnostic["code"], "evidence.project.not-found", "{report}"); - let shown = report.to_string(); - assert!( - diagnostic["source"]["file"] - .as_str() - .is_some_and(|file| file.starts_with(project.to_str().unwrap()) - && file.ends_with("evidence.yaml")), - "{shown}" - ); - assert!(!shown.contains("snapshot"), "{shown}"); - let action = diagnostic["suggestedAction"].as_str().unwrap(); - assert!(action.contains("evidencectl init"), "{action}"); - if command == "test" { - // `test` also runs a deployment directory, which it knows by its - // runtime.yaml, so the action names that shape too. - assert!(action.contains("runtime.yaml"), "{action}"); + let relative = Path::new("old-layout"); + let absolute = temporary.path().join(relative); + fs::create_dir(&absolute).unwrap(); + let missing_bin = temporary.path().join("missing-evidence"); + for project in [absolute.as_path(), relative] { + let expected_file = project.join("evidence.yaml"); + for (command, evidence_bin) in [("check", None), ("test", Some(missing_bin.as_path()))] { + let (code, report) = run(command, temporary.path(), project, evidence_bin); + assert_eq!(code, Some(1), "{command}: {report}"); + let diagnostic = first_diagnostic(&report); + assert_eq!(diagnostic["code"], "evidence.project.not-found", "{report}"); + assert_eq!( + diagnostic["source"]["file"].as_str(), + Some(expected_file.to_str().unwrap()), + "{command}: {report}" + ); + let shown = report.to_string(); + assert!(!shown.contains("snapshot"), "{shown}"); + let action = diagnostic["suggestedAction"].as_str().unwrap(); + assert!(action.contains("evidencectl init"), "{action}"); + if command == "test" { + // `test` also runs a deployment directory, which it knows by its + // runtime.yaml, so the action names that shape too. + assert!(action.contains("runtime.yaml"), "{action}"); + } } } } @@ -83,7 +98,7 @@ fn a_directory_without_evidence_yaml_is_refused_naming_the_path_given() { fn an_unparseable_pack_is_refused_at_the_pack_file() { let project = standalone_copy(); fs::write(project.path().join(PACK), "apiVersion: [unterminated\n").unwrap(); - let (code, report) = run("check", project.path()); + let (code, report) = run("check", project.path(), project.path(), None); assert_eq!(code, Some(1), "{report}"); let diagnostic = first_diagnostic(&report); assert_ne!(diagnostic["code"], "evidence.check.failed", "{report}"); @@ -105,7 +120,7 @@ fn a_pack_with_an_unknown_key_is_refused_at_that_key() { authored.replacen("{\n", "{\n \"bogusKey\": 1,\n", 1), ) .unwrap(); - let (code, report) = run("check", project.path()); + let (code, report) = run("check", project.path(), project.path(), None); assert_eq!(code, Some(1), "{report}"); let diagnostic = first_diagnostic(&report); assert_ne!(diagnostic["code"], "evidence.check.failed", "{report}"); @@ -129,7 +144,7 @@ fn an_unknown_source_route_is_refused_at_the_route_naming_the_declared_ones() { authored.replacen("route: person\n", "route: no-such-route\n", 1), ) .unwrap(); - let (code, report) = run("check", project.path()); + let (code, report) = run("check", project.path(), project.path(), None); assert_eq!(code, Some(1), "{report}"); let diagnostic = first_diagnostic(&report); assert_eq!(