Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/scripts/test_ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 19 additions & 9 deletions crates/registry-evidencectl/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<PathBuf>> {
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<PathBuf>,
declared: registry_platform_config::DeclaredPosture,
) -> Result<ExitCode> {
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");
}
Expand All @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions crates/registry-evidencectl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.",
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion crates/registry-evidencectl/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
77 changes: 46 additions & 31 deletions crates/registry-evidencectl/tests/project_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ use std::{fs, path::Path, process::Command};

use serde_json::Value;

fn run(command: &str, project: &Path) -> (Option<i32>, 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<i32>, 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}: {}{}",
Expand Down Expand Up @@ -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}");
}
}
}
}
Expand All @@ -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}");
Expand All @@ -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}");
Expand All @@ -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!(
Expand Down
Loading