Change to skip asserting the artifact graph for samples (#7153)

* Change to skip asserting the artifact graph for samples

* Fix clippy warning
This commit is contained in:
Jonathan Tran
2025-05-21 10:51:31 -04:00
committed by GitHub
parent b50f2f5a2a
commit 5976a0cba6
3 changed files with 37 additions and 23 deletions

View File

@ -36,20 +36,20 @@ new-sim-test test_name render_to_png="true":
# Run a KCL deterministic simulation test case and accept output.
overwrite-sim-test-sample test_name:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::parse_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::unparse_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::kcl_test_execute_{{test_name}}
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::test_after_engine
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::parse_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::unparse_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::kcl_test_execute_{{test_name}}
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::kcl_samples::test_after_engine
overwrite-sim-test test_name:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::parse
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::unparse
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::kcl_test_execute
[ {{test_name}} != "kcl_samples" ] || EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::test_after_engine
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::parse
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::unparse
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::kcl_test_execute
[ {{test_name}} != "kcl_samples" ] || ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests::{{test_name}}::test_after_engine
# Regenerate all the simulation test output.
redo-sim-tests:
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests
ZOO_SIM_UPDATE=always EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests
test:
cargo install cargo-nextest

View File

@ -26,6 +26,10 @@ struct Test {
input_dir: PathBuf,
/// Expected snapshot output files are in this directory.
output_dir: PathBuf,
/// True to skip asserting the artifact graph and only write it. The default
/// is false and to assert it.
#[cfg_attr(not(feature = "artifact-graph"), expect(dead_code))]
skip_assert_artifact_graph: bool,
}
pub(crate) const RENDERED_MODEL_NAME: &str = "rendered_model.png";
@ -37,6 +41,7 @@ impl Test {
entry_point: Path::new("tests").join(name).join("input.kcl"),
input_dir: Path::new("tests").join(name),
output_dir: Path::new("tests").join(name),
skip_assert_artifact_graph: false,
}
}
@ -299,6 +304,12 @@ fn assert_common_snapshots(
})
}));
let result3 = catch_unwind(AssertUnwindSafe(|| {
// If the user is explicitly writing, we always want to run so that they
// can save new expected output. There's no way to reliably determine
// if insta will write, as far as I can tell, so we use our own
// environment variable.
let is_writing = matches!(std::env::var("ZOO_SIM_UPDATE").as_deref(), Ok("always"));
if !test.skip_assert_artifact_graph || is_writing {
assert_snapshot(test, "Artifact graph flowchart", || {
let mut artifact_graph = artifact_graph.clone();
// Sort the map by artifact where we can.
@ -314,6 +325,7 @@ fn assert_common_snapshots(
insta::assert_binary_snapshot!("artifact_graph_flowchart.md", flowchart.as_bytes().to_owned());
}
})
}
}));
result1.unwrap();

View File

@ -145,6 +145,8 @@ fn test(test_name: &str, entry_point: std::path::PathBuf) -> Test {
entry_point: entry_point.clone(),
input_dir: parent.to_path_buf(),
output_dir: relative_output_dir,
// Skip is temporary while we have non-deterministic output.
skip_assert_artifact_graph: true,
}
}