feat(review): add scoped reports and native Git integration
Separate top, exact-cell and layer comparison scopes from display filters. Explain unique replacements and preserve full evidence, duplicate counts and incomplete-result handling. Version the dump profile and freeze canonical, hierarchy and diff goldens. Package native Git and textconv drivers with integration coverage for edits, additions, deletions, renames, quoted paths and errors. Document embedded metadata writing and validate deep hierarchies, large polygons and symbolic arrays.
This commit is contained in:
parent
e56026c3a6
commit
d8f764c7fe
1 changed files with 1191 additions and 97 deletions
462
tests/review.rs
462
tests/review.rs
|
|
@ -421,6 +421,7 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
|||
assert_eq!(
|
||||
hierarchy(&a, &b, Some(&diff), false, 8),
|
||||
concat!(
|
||||
"scope top=all cell=all layer=all\n",
|
||||
"\"CHIP\" x1 [affected]\n",
|
||||
" \"left\" x1 [affected]\n",
|
||||
" \"leaf\" x2 [cell changed]\n",
|
||||
|
|
@ -782,3 +783,464 @@ fn metadata_cli_creates_a_separate_file_and_refuses_existing_output() {
|
|||
assert_eq!(fs::read(&output).unwrap(), generated);
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scope_selection_distinguishes_reachable_subtrees_from_exact_cells() {
|
||||
use klamath_rs_ext::review::Scope;
|
||||
let a = layout(&[
|
||||
("CHIP", vec![reference("leaf", 0, 1)]),
|
||||
("leaf", vec![square()]),
|
||||
("unused", vec![square()]),
|
||||
]);
|
||||
let b = layout(&[
|
||||
("CHIP", vec![reference("leaf", 0, 1)]),
|
||||
("leaf", vec![triangle()]),
|
||||
("unused", vec![triangle()]),
|
||||
]);
|
||||
let top = Scope {
|
||||
top: Some("CHIP".to_string()),
|
||||
..Scope::default()
|
||||
};
|
||||
let old = Document::parse(&a).unwrap().selected(&top, false).unwrap();
|
||||
let new = Document::parse(&b).unwrap().selected(&top, false).unwrap();
|
||||
assert_eq!(
|
||||
old.cells.keys().map(String::as_str).collect::<Vec<_>>(),
|
||||
["CHIP", "leaf"]
|
||||
);
|
||||
assert_eq!(Comparison::between(&old, &new).cells.len(), 1);
|
||||
assert!(old.canonical_dump().contains("scope top=\"CHIP\""));
|
||||
let cell = Scope {
|
||||
cell: Some("CHIP".to_string()),
|
||||
..Scope::default()
|
||||
};
|
||||
let old = Document::parse(&a).unwrap().selected(&cell, false).unwrap();
|
||||
let new = Document::parse(&b).unwrap().selected(&cell, false).unwrap();
|
||||
assert!(old.issues.is_empty());
|
||||
assert!(Comparison::between(&old, &new).is_equal());
|
||||
let missing = Scope {
|
||||
top: Some("missing".to_string()),
|
||||
..Scope::default()
|
||||
};
|
||||
assert!(
|
||||
Document::parse(&a)
|
||||
.unwrap()
|
||||
.selected(&missing, false)
|
||||
.is_err()
|
||||
);
|
||||
let wrong = Scope {
|
||||
top: Some("CHIP".to_string()),
|
||||
cell: Some("unused".to_string()),
|
||||
layer: None,
|
||||
};
|
||||
assert!(
|
||||
wrong
|
||||
.validate_pair(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap())
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_scope_filters_geometry_and_references_by_descendant_coverage() {
|
||||
use klamath_rs_ext::review::Scope;
|
||||
let mut other_layer = square();
|
||||
other_layer[8..10].copy_from_slice(&2_u16.to_be_bytes());
|
||||
let a = layout(&[
|
||||
(
|
||||
"CHIP",
|
||||
vec![reference("wg", 0, 1), reference("heater", 0, 1)],
|
||||
),
|
||||
("wg", vec![square()]),
|
||||
("heater", vec![other_layer.clone()]),
|
||||
]);
|
||||
let b = layout(&[
|
||||
(
|
||||
"CHIP",
|
||||
vec![reference("wg", 0, 1), reference("heater", 5, 1)],
|
||||
),
|
||||
("wg", vec![square()]),
|
||||
("heater", vec![other_layer]),
|
||||
]);
|
||||
for (layer, expected) in [((1, 0), 0), ((2, 0), 1)] {
|
||||
let scope = Scope {
|
||||
layer: Some(layer),
|
||||
..Scope::default()
|
||||
};
|
||||
let old = Document::parse(&a)
|
||||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap();
|
||||
let new = Document::parse(&b)
|
||||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap();
|
||||
assert_eq!(Comparison::between(&old, &new).exit_code(), expected);
|
||||
assert!(old.issues.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_issues_do_not_hide_relevant_unsupported_objects_or_cycles() {
|
||||
use klamath_rs_ext::review::Scope;
|
||||
let mut unknown = square();
|
||||
unknown.truncate(unknown.len() - 4);
|
||||
record(&mut unknown, 0x7f00, &[]);
|
||||
record(&mut unknown, RTAG_ENDEL, &[]);
|
||||
let bytes = layout(&[("CHIP", vec![square()]), ("unused", vec![unknown])]);
|
||||
let scope = Scope {
|
||||
cell: Some("CHIP".to_string()),
|
||||
..Scope::default()
|
||||
};
|
||||
assert!(
|
||||
Document::parse(&bytes)
|
||||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.is_empty()
|
||||
);
|
||||
let scope = Scope {
|
||||
cell: Some("unused".to_string()),
|
||||
..Scope::default()
|
||||
};
|
||||
assert!(
|
||||
!Document::parse(&bytes)
|
||||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.is_empty()
|
||||
);
|
||||
let bytes = layout(&[
|
||||
("a", vec![reference("b", 0, 1)]),
|
||||
("b", vec![reference("a", 0, 1)]),
|
||||
]);
|
||||
let scope = Scope {
|
||||
layer: Some((999, 0)),
|
||||
..Scope::default()
|
||||
};
|
||||
assert!(
|
||||
Document::parse(&bytes)
|
||||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.iter()
|
||||
.any(|s| s.contains("cyclic"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_filters_never_change_equality_or_totals() {
|
||||
use klamath_rs_ext::review::DisplayFilter;
|
||||
let a = layout(&[("CHIP", vec![square()])]);
|
||||
let b = layout(&[("CHIP", vec![triangle()])]);
|
||||
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
|
||||
let text = diff.text_filtered(
|
||||
100,
|
||||
&DisplayFilter {
|
||||
cell: None,
|
||||
layer: Some((42, 0)),
|
||||
},
|
||||
);
|
||||
assert!(text.contains("display-only"));
|
||||
assert!(text.contains("0 of 2 object changes shown"));
|
||||
assert_eq!(diff.exit_code(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn git_external_driver_handles_changes_additions_deletions_and_errors() {
|
||||
let directory = std::env::temp_dir().join(format!(
|
||||
"klamath-git-review-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos()
|
||||
));
|
||||
fs::create_dir_all(&directory).unwrap();
|
||||
let inherited_path = std::env::var_os("PATH").unwrap_or_default();
|
||||
let git_path = std::env::join_paths(
|
||||
std::iter::once(
|
||||
PathBuf::from(env!("CARGO_BIN_EXE_klamath"))
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_path_buf(),
|
||||
)
|
||||
.chain(std::env::split_paths(&inherited_path)),
|
||||
)
|
||||
.unwrap();
|
||||
let git = |args: &[&str]| {
|
||||
let result = Command::new("git")
|
||||
.env("PATH", &git_path)
|
||||
.arg("-C")
|
||||
.arg(&directory)
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.status.success(),
|
||||
"git {args:?}: {}",
|
||||
String::from_utf8_lossy(&result.stderr)
|
||||
);
|
||||
result
|
||||
};
|
||||
git(&["init", "-q"]);
|
||||
git(&["config", "user.name", "Review Fixture"]);
|
||||
git(&["config", "user.email", "fixture@example.invalid"]);
|
||||
git(&["config", "commit.gpgsign", "false"]);
|
||||
git(&["config", "core.hooksPath", "/dev/null"]);
|
||||
git(&[
|
||||
"config",
|
||||
"include.path",
|
||||
concat!(env!("CARGO_MANIFEST_DIR"), "/contrib/git/config"),
|
||||
]);
|
||||
assert_eq!(
|
||||
String::from_utf8(git(&["config", "--get", "diff.klamath.trustExitCode"]).stdout)
|
||||
.unwrap()
|
||||
.trim(),
|
||||
"false"
|
||||
);
|
||||
fs::write(
|
||||
directory.join(".gitattributes"),
|
||||
include_str!("../contrib/git/attributes"),
|
||||
)
|
||||
.unwrap();
|
||||
let path = directory.join("chip layout.gds");
|
||||
fs::write(&path, layout(&[("CHIP", vec![square()])])).unwrap();
|
||||
git(&["add", "."]);
|
||||
git(&["commit", "-qm", "baseline"]);
|
||||
fs::write(&path, layout(&[("CHIP", vec![triangle()])])).unwrap();
|
||||
let changed = git(&["diff", "--", "chip layout.gds"]);
|
||||
assert!(
|
||||
String::from_utf8(changed.stdout)
|
||||
.unwrap()
|
||||
.contains("2 of 2 object changes shown")
|
||||
);
|
||||
fs::write(&path, b"invalid").unwrap();
|
||||
let invalid = Command::new("git")
|
||||
.env("PATH", &git_path)
|
||||
.arg("-C")
|
||||
.arg(&directory)
|
||||
.args(["diff", "--", "chip layout.gds"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(!invalid.status.success());
|
||||
assert!(String::from_utf8_lossy(&invalid.stderr).contains("klamath:"));
|
||||
fs::write(&path, layout(&[("CHIP", vec![square()])])).unwrap();
|
||||
let added = directory.join("added layout.gds");
|
||||
fs::write(&added, shared(square())).unwrap();
|
||||
git(&["add", "added layout.gds"]);
|
||||
let result = git(&["diff", "--cached", "--", "added layout.gds"]);
|
||||
assert!(
|
||||
String::from_utf8(result.stdout)
|
||||
.unwrap()
|
||||
.contains("layout added")
|
||||
);
|
||||
fs::remove_file(&path).unwrap();
|
||||
git(&["add", "-u"]);
|
||||
let result = git(&["diff", "--cached", "--", "chip layout.gds"]);
|
||||
assert!(
|
||||
String::from_utf8(result.stdout)
|
||||
.unwrap()
|
||||
.contains("layout deleted")
|
||||
);
|
||||
// Textconv is an alternative to the external driver, with a separate cache.
|
||||
git(&["commit", "-qm", "replace fixture"]);
|
||||
git(&["mv", "added layout.gds", "renamed layout.gds"]);
|
||||
let renamed = directory.join("renamed layout.gds");
|
||||
fs::write(&renamed, shared(triangle())).unwrap();
|
||||
git(&["add", "renamed layout.gds"]);
|
||||
let result = git(&["diff", "--cached", "--find-renames"]);
|
||||
let text = String::from_utf8(result.stdout).unwrap();
|
||||
assert!(text.contains("renamed layout.gds"), "{text}");
|
||||
assert!(text.contains("2 of 2 object changes shown"), "{text}");
|
||||
git(&["commit", "-qm", "rename fixture"]);
|
||||
fs::write(
|
||||
directory.join(".gitattributes"),
|
||||
"*.gds diff=klamath-text\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(&renamed, shared(square())).unwrap();
|
||||
let result = git(&["diff", "--", "renamed layout.gds"]);
|
||||
assert!(
|
||||
String::from_utf8(result.stdout)
|
||||
.unwrap()
|
||||
.contains("- BOUNDARY")
|
||||
);
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replacement_explanations_are_unique_and_keep_full_evidence() {
|
||||
for pair in corpus().into_iter().filter(|p| {
|
||||
[
|
||||
"same bounds different geometry",
|
||||
"moved reference",
|
||||
"array count",
|
||||
]
|
||||
.contains(&p.name)
|
||||
}) {
|
||||
let old = Document::parse(&pair.old).unwrap();
|
||||
let new = Document::parse(&pair.new).unwrap();
|
||||
let diff = Comparison::between(&old, &new);
|
||||
assert_eq!(diff.cells[0].replacements.len(), 1);
|
||||
let text = diff.text(100);
|
||||
assert!(text.contains(" ~ "));
|
||||
assert!(text.contains(" - @"));
|
||||
assert!(text.contains(" + @"));
|
||||
match pair.name {
|
||||
"moved reference" => assert!(text.contains("delta=(5, 0) dbu")),
|
||||
"array count" => assert!(text.contains("columns/rows 2 x 1 -> 3 x 1")),
|
||||
_ => assert_eq!(text, include_str!("golden/review-diff.txt")),
|
||||
}
|
||||
assert!(!diff.text(0).contains(" ~ "));
|
||||
assert!(diff.text(1).contains("1 of 2 object changes shown"));
|
||||
}
|
||||
let a = layout(&[("CHIP", vec![square(), square()])]);
|
||||
let b = layout(&[("CHIP", vec![triangle(), triangle()])]);
|
||||
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
|
||||
assert!(diff.cells[0].replacements.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_width_explanation_preserves_absent_and_zero() {
|
||||
let path = |width: Option<i32>| {
|
||||
let mut bytes = Vec::new();
|
||||
record(&mut bytes, RTAG_PATH, &[]);
|
||||
record(&mut bytes, RTAG_LAYER, &[0, 1]);
|
||||
record(&mut bytes, RTAG_DATATYPE, &[0, 0]);
|
||||
if let Some(n) = width {
|
||||
record(&mut bytes, RTAG_WIDTH, &n.to_be_bytes());
|
||||
}
|
||||
xy(&mut bytes, &[[0, 0], [10, 10]]);
|
||||
record(&mut bytes, RTAG_ENDEL, &[]);
|
||||
layout(&[("CHIP", vec![bytes])])
|
||||
};
|
||||
let a = path(None);
|
||||
let b = path(Some(0));
|
||||
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
|
||||
assert!(diff.text(100).contains("width absent -> 0 dbu"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_layer_names_explain_geometry_changes_once() {
|
||||
let named = |geometry| {
|
||||
layout(&[(
|
||||
"CHIP",
|
||||
vec![
|
||||
geometry,
|
||||
label((900, 7), LAYER_SENTINEL),
|
||||
label((900, 7), "1:0:WG"),
|
||||
],
|
||||
)])
|
||||
};
|
||||
let a = named(square());
|
||||
let b = named(triangle());
|
||||
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
|
||||
let text = diff.text(100);
|
||||
assert_eq!(text.matches("name=\"WG\"").count(), 1);
|
||||
assert!(diff.layer_names.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_added_empty_document_is_still_a_presence_change() {
|
||||
let bytes = layout(&[]);
|
||||
let doc = Document::parse(&bytes).unwrap();
|
||||
let diff = Comparison::between(&doc.empty_like(), &doc);
|
||||
assert_eq!(diff.exit_code(), 1);
|
||||
assert!(diff.text(0).contains("library presence:"));
|
||||
assert!(!diff.text(0).contains("equal under"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_scope_and_display_filters_have_distinct_exit_behavior() {
|
||||
let directory = std::env::temp_dir().join(format!("klamath-scope-{}", std::process::id()));
|
||||
fs::create_dir_all(&directory).unwrap();
|
||||
let old = directory.join("old.gds");
|
||||
let new = directory.join("new.gds");
|
||||
fs::write(&old, shared(square())).unwrap();
|
||||
fs::write(&new, shared(triangle())).unwrap();
|
||||
for (options, expected) in [
|
||||
(vec!["--cell", "CHIP"], 0),
|
||||
(vec!["--top", "CHIP"], 1),
|
||||
(vec!["--layer", "99/0"], 0),
|
||||
(vec!["--show-cell", "missing"], 1),
|
||||
(vec!["--show-layer", "99/0"], 1),
|
||||
(vec!["--top", "missing"], 2),
|
||||
] {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_klamath"))
|
||||
.arg("diff")
|
||||
.args(&options)
|
||||
.arg(&old)
|
||||
.arg(&new)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(expected),
|
||||
"{options:?}: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
fs::write(&old, layout(&[])).unwrap();
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_klamath"))
|
||||
.args(["diff", "--top", "CHIP"])
|
||||
.arg(&old)
|
||||
.arg(&new)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn large_polygons_and_billion_instance_arrays_stay_compact() {
|
||||
let mut points = vec![[0, 0], [0, 1]];
|
||||
points.extend((1..8187).map(|x| [x, 1]));
|
||||
points.extend([[8186, 0], [0, 0]]);
|
||||
let mut array = Vec::new();
|
||||
record(&mut array, RTAG_AREF, &[]);
|
||||
ascii(&mut array, RTAG_SNAME, "leaf");
|
||||
record(&mut array, RTAG_COLROW, &[0x7f, 0xff, 0x7f, 0xff]);
|
||||
xy(&mut array, &[[0, 0], [32767, 0], [0, 32767]]);
|
||||
record(&mut array, RTAG_ENDEL, &[]);
|
||||
let bytes = layout(&[("CHIP", vec![array]), ("leaf", vec![polygon(&points)])]);
|
||||
let doc = Document::parse(&bytes).unwrap();
|
||||
assert_eq!(
|
||||
doc.edges()[&("CHIP".to_string(), "leaf".to_string())],
|
||||
32767 * 32767
|
||||
);
|
||||
assert_eq!(doc.cells["CHIP"].objects.len(), 1);
|
||||
assert!(hierarchy(&doc, &doc, None, false, 8).len() < 200);
|
||||
assert!(Comparison::between(&doc, &doc).is_equal());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deep_hierarchy_comparison_and_rendering_are_iterative() {
|
||||
let names: Vec<_> = (0..2048).map(|i| format!("cell_{i}")).collect();
|
||||
let cells = |leaf: Vec<u8>| {
|
||||
names
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, name)| {
|
||||
(
|
||||
name.as_str(),
|
||||
if i + 1 == names.len() {
|
||||
vec![leaf.clone()]
|
||||
} else {
|
||||
vec![reference(&names[i + 1], 0, 1)]
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let a = layout(&cells(square()));
|
||||
let b = layout(&cells(triangle()));
|
||||
let a = Document::parse(&a).unwrap();
|
||||
let b = Document::parse(&b).unwrap();
|
||||
let diff = Comparison::between(&a, &b);
|
||||
let tree = hierarchy(&a, &b, Some(&diff), false, 5);
|
||||
assert_eq!(diff.cells.len(), 1);
|
||||
assert!(tree.contains("children omitted"));
|
||||
assert!(tree.len() < 500);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue