Make Pheon structural review results self-contained
Capture revision metadata, cell presence and attributes, and structured diagnostics in owned comparison results. Derive outcomes and render text, JSON, and hierarchy reports without retaining source documents. Keep derived descriptions and graph analysis in their renderers. Use pheon-structural-v1 and PHEON_LAYER_NAMES_V1 consistently, expose helpers through their defining modules, and remove obsolete re-exports. Update user guides and report fixtures without changing schema version 1. Cover dropped inputs, diagnostic ordering, absent and empty cells, offset independence, and CLI failures. All 92 Rust tests pass in debug and release; report and hierarchy goldens retain their behavior.
This commit is contained in:
parent
a723ba2265
commit
df62677f5c
10 changed files with 870 additions and 504 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"cell_changes": [],
|
||||
"comparison_profile": "klamath-object-v2",
|
||||
"comparison_profile": "pheon-structural-v1",
|
||||
"coordinates": {
|
||||
"bounds": "coordinate_envelope",
|
||||
"frame": "cell_local",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"cell_changes": [],
|
||||
"comparison_profile": "klamath-object-v2",
|
||||
"comparison_profile": "pheon-structural-v1",
|
||||
"coordinates": {
|
||||
"bounds": "coordinate_envelope",
|
||||
"frame": "cell_local",
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"comparison_profile": "klamath-object-v2",
|
||||
"comparison_profile": "pheon-structural-v1",
|
||||
"coordinates": {
|
||||
"bounds": "coordinate_envelope",
|
||||
"frame": "cell_local",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"cell_changes": [],
|
||||
"comparison_profile": "klamath-object-v2",
|
||||
"comparison_profile": "pheon-structural-v1",
|
||||
"coordinates": {
|
||||
"bounds": "coordinate_envelope",
|
||||
"frame": "cell_local",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"cell_changes": [],
|
||||
"comparison_profile": "klamath-object-v2",
|
||||
"comparison_profile": "pheon-structural-v1",
|
||||
"coordinates": {
|
||||
"bounds": "coordinate_envelope",
|
||||
"frame": "cell_local",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
profile klamath-object-v2
|
||||
profile pheon-structural-v1
|
||||
scope top=all cell=all layer=all
|
||||
coordinates: integer database units; bounds: coordinate envelopes
|
||||
HEADER=[600]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
profile klamath-object-v2
|
||||
profile pheon-structural-v1
|
||||
scope top=all cell=all layer=all
|
||||
cell "CHIP" old@Some(62) new@Some(62)
|
||||
~ BOUNDARY modified; coordinate bounds unchanged
|
||||
|
|
|
|||
150
tests/review.rs
150
tests/review.rs
|
|
@ -5,7 +5,7 @@ mod reports;
|
|||
use common::{library_header, record};
|
||||
use pheon::{
|
||||
records::*,
|
||||
review::{Comparison, Document, LAYER_SENTINEL, hierarchy},
|
||||
review::{Comparison, Document, names::LAYER_SENTINEL},
|
||||
};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
||||
|
|
@ -251,7 +251,12 @@ fn ten_fixture_pairs_have_explicit_expected_changes() {
|
|||
let old = Document::parse(&pair.old).unwrap();
|
||||
let new = Document::parse(&pair.new).unwrap();
|
||||
let diff = Comparison::between(&old, &new);
|
||||
assert!(diff.issues.is_empty(), "{}: {:?}", pair.name, diff.issues);
|
||||
assert!(
|
||||
diff.diagnostics.is_empty(),
|
||||
"{}: {:?}",
|
||||
pair.name,
|
||||
diff.diagnostics
|
||||
);
|
||||
assert_eq!(diff.cells.len(), pair.changed_cells, "{}", pair.name);
|
||||
assert_eq!(
|
||||
diff.cells.iter().map(|c| c.removed.len()).sum::<usize>(),
|
||||
|
|
@ -267,14 +272,14 @@ fn ten_fixture_pairs_have_explicit_expected_changes() {
|
|||
);
|
||||
assert_eq!(diff.layer_names.len(), pair.metadata, "{}", pair.name);
|
||||
let equal = pair.changed_cells + pair.metadata == 0;
|
||||
assert_eq!(diff.is_equal(), equal, "{}", pair.name);
|
||||
assert_eq!(diff.outcome().is_equal(), equal, "{}", pair.name);
|
||||
assert_eq!(
|
||||
old.canonical_dump() == new.canonical_dump(),
|
||||
equal,
|
||||
"{}",
|
||||
pair.name
|
||||
);
|
||||
assert_eq!(diff.exit_code(), if equal { 0 } else { 1 });
|
||||
assert_eq!(diff.outcome().exit_code(), if equal { 0 } else { 1 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -317,11 +322,11 @@ fn canonical_dump_and_hierarchy_match_versioned_goldens() {
|
|||
let b = Document::parse(&b).unwrap();
|
||||
let diff = Comparison::between(&a, &b);
|
||||
assert_eq!(
|
||||
hierarchy(&a, &b, Some(&diff), false, 8),
|
||||
diff.hierarchy(false, 8),
|
||||
include_str!("golden/review-hierarchy.txt")
|
||||
);
|
||||
assert_eq!(
|
||||
hierarchy(&a, &b, Some(&diff), true, 8),
|
||||
diff.hierarchy(true, 8),
|
||||
include_str!("golden/review-hierarchy.mmd")
|
||||
);
|
||||
}
|
||||
|
|
@ -352,7 +357,8 @@ fn cell_and_property_order_do_not_affect_comparison() {
|
|||
let b = layout(&[("a", vec![]), ("z", vec![b])]);
|
||||
let a = Document::parse(&a).unwrap();
|
||||
let b = Document::parse(&b).unwrap();
|
||||
assert!(Comparison::between(&a, &b).is_equal());
|
||||
assert_ne!(a.cells["z"].offset, b.cells["z"].offset);
|
||||
assert!(Comparison::between(&a, &b).outcome().is_equal());
|
||||
assert_eq!(a.canonical_dump(), b.canonical_dump());
|
||||
}
|
||||
|
||||
|
|
@ -393,9 +399,12 @@ fn metadata_requires_a_sentinel_in_the_same_cell_and_carrier_pair() {
|
|||
.unwrap()
|
||||
.contains("1:0:B")
|
||||
);
|
||||
let future = layout(&[("CHIP", vec![label((9, 0), "KLAMATH_LAYER_NAMES_V2")])]);
|
||||
let future = layout(&[("CHIP", vec![label((9, 0), "PHEON_LAYER_NAMES_V2")])]);
|
||||
let future = Document::parse(&future).unwrap();
|
||||
assert_eq!(Comparison::between(&future, &future).exit_code(), 2);
|
||||
assert_eq!(
|
||||
Comparison::between(&future, &future).outcome().exit_code(),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -407,8 +416,8 @@ fn unknown_records_never_produce_a_successful_equality_claim() {
|
|||
let bytes = layout(&[("CHIP", vec![unknown])]);
|
||||
let doc = Document::parse(&bytes).unwrap();
|
||||
let diff = Comparison::between(&doc, &doc);
|
||||
assert!(!diff.is_equal());
|
||||
assert_eq!(diff.exit_code(), 2);
|
||||
assert!(!diff.outcome().is_equal());
|
||||
assert_eq!(diff.outcome().exit_code(), 2);
|
||||
assert!(doc.record_dump().contains("7f00"));
|
||||
assert!(diff.text(0).contains("INCOMPLETE"));
|
||||
}
|
||||
|
|
@ -421,7 +430,7 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
|||
let b = Document::parse(&b).unwrap();
|
||||
let diff = Comparison::between(&a, &b);
|
||||
assert_eq!(
|
||||
hierarchy(&a, &b, Some(&diff), false, 8),
|
||||
diff.hierarchy(false, 8),
|
||||
concat!(
|
||||
"scope top=all cell=all layer=all\n",
|
||||
"\"CHIP\" x1 [affected]\n",
|
||||
|
|
@ -431,11 +440,11 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
|||
" \"leaf\" x3 [cell changed] [shown above]\n",
|
||||
)
|
||||
);
|
||||
let graph = hierarchy(&a, &b, Some(&diff), true, 8);
|
||||
let graph = diff.hierarchy(true, 8);
|
||||
assert_eq!(graph.matches("leaf [cell changed]").count(), 1);
|
||||
assert!(graph.contains("x2"));
|
||||
assert!(graph.contains("x3"));
|
||||
let limited = hierarchy(&a, &b, Some(&diff), false, 1);
|
||||
let limited = diff.hierarchy(false, 1);
|
||||
assert!(!limited.contains("\"leaf\""));
|
||||
assert!(limited.contains("children omitted"));
|
||||
}
|
||||
|
|
@ -449,7 +458,7 @@ fn reference_changes_keep_unchanged_targets_and_old_edges_visible() {
|
|||
let old = Document::parse(&pair.old).unwrap();
|
||||
let new = Document::parse(&pair.new).unwrap();
|
||||
let diff = Comparison::between(&old, &new);
|
||||
let tree = hierarchy(&old, &new, Some(&diff), false, 8);
|
||||
let tree = diff.hierarchy(false, 8);
|
||||
assert!(tree.contains("[cell unchanged]"), "{tree}");
|
||||
assert!(tree.contains("[reference changed]"), "{tree}");
|
||||
if pair.name == "array count" {
|
||||
|
|
@ -463,7 +472,7 @@ fn reference_changes_keep_unchanged_targets_and_old_edges_visible() {
|
|||
let b = layout(&[("CHIP", vec![])]);
|
||||
let a = Document::parse(&a).unwrap();
|
||||
let b = Document::parse(&b).unwrap();
|
||||
let tree = hierarchy(&a, &b, Some(&Comparison::between(&a, &b)), false, 8);
|
||||
let tree = Comparison::between(&a, &b).hierarchy(false, 8);
|
||||
assert!(tree.contains("\"leaf\" x1 -> x0"), "{tree}");
|
||||
}
|
||||
|
||||
|
|
@ -479,7 +488,7 @@ fn same_bounds_changes_and_truncated_reports_remain_differences() {
|
|||
diff.cells[0].added[0].bounds
|
||||
);
|
||||
assert!(diff.text(0).contains("0 of 2 object changes shown"));
|
||||
assert_eq!(diff.exit_code(), 1);
|
||||
assert_eq!(diff.outcome().exit_code(), 1);
|
||||
assert!(diff.cells[0].removed[0].offset > 0);
|
||||
}
|
||||
|
||||
|
|
@ -494,17 +503,19 @@ fn unit_changes_report_values_without_claiming_geometry_equivalence() {
|
|||
.unwrap()
|
||||
.offset;
|
||||
let mut b = a.clone();
|
||||
b[units + 12..units + 20].copy_from_slice(
|
||||
&pheon::basic::encode_real8(2e-9)
|
||||
.unwrap()
|
||||
.to_be_bytes(),
|
||||
);
|
||||
b[units + 12..units + 20]
|
||||
.copy_from_slice(&pheon::basic::encode_real8(2e-9).unwrap().to_be_bytes());
|
||||
let a = Document::parse(&a).unwrap();
|
||||
let b = Document::parse(&b).unwrap();
|
||||
let diff = Comparison::between(&a, &b);
|
||||
assert_eq!(diff.exit_code(), 1);
|
||||
assert_eq!(diff.library_fields.len(), 1);
|
||||
assert_eq!(diff.library_fields[0].field, "UNITS");
|
||||
assert_eq!(diff.outcome().exit_code(), 1);
|
||||
assert!(matches!(
|
||||
diff.library_changes.as_slice(),
|
||||
[pheon::review::LibraryChange::Record {
|
||||
tag: RTAG_UNITS,
|
||||
..
|
||||
}]
|
||||
));
|
||||
assert!(diff.text(0).contains("UNITS changed"));
|
||||
assert!(diff.cells.is_empty());
|
||||
}
|
||||
|
|
@ -515,17 +526,22 @@ fn dangling_references_cycles_and_duplicate_cell_names_are_reported() {
|
|||
let missing = Document::parse(&missing).unwrap();
|
||||
assert!(
|
||||
missing
|
||||
.issues
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|s| s.contains("unresolved reference"))
|
||||
.any(|d| d.code == "unresolved_reference")
|
||||
);
|
||||
let cycle = layout(&[
|
||||
("a", vec![reference("b", 0, 1)]),
|
||||
("b", vec![reference("a", 0, 1)]),
|
||||
]);
|
||||
let cycle = Document::parse(&cycle).unwrap();
|
||||
assert!(cycle.issues.iter().any(|s| s.contains("cyclic")));
|
||||
assert!(hierarchy(&cycle, &cycle, None, false, 8).len() < 200);
|
||||
assert!(
|
||||
cycle
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|d| d.code == "hierarchy_cycle")
|
||||
);
|
||||
assert!(cycle.hierarchy(false, 8).len() < 200);
|
||||
let duplicate = layout(&[("a", vec![]), ("a", vec![])]);
|
||||
assert!(
|
||||
Document::parse(&duplicate)
|
||||
|
|
@ -547,6 +563,7 @@ fn absolute_transform_flags_are_not_discarded() {
|
|||
let b = layout(&[("CHIP", vec![b]), ("leaf", vec![])]);
|
||||
assert_eq!(
|
||||
Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap())
|
||||
.outcome()
|
||||
.exit_code(),
|
||||
1
|
||||
);
|
||||
|
|
@ -568,7 +585,11 @@ fn polygon_normalization_handles_repeated_minimum_vertices() {
|
|||
rotated.push(rotated[0]);
|
||||
let candidate = layout(&[("CHIP", vec![polygon(&rotated)])]);
|
||||
let candidate = Document::parse(&candidate).unwrap();
|
||||
assert!(Comparison::between(&baseline, &candidate).is_equal());
|
||||
assert!(
|
||||
Comparison::between(&baseline, &candidate)
|
||||
.outcome()
|
||||
.is_equal()
|
||||
);
|
||||
}
|
||||
open.reverse();
|
||||
}
|
||||
|
|
@ -672,7 +693,7 @@ fn cli_uses_documented_exit_codes_and_accepts_paths_with_spaces() {
|
|||
|
||||
#[test]
|
||||
fn metadata_writer_preserves_unrelated_bytes_and_consolidates_updates() {
|
||||
use pheon::review::write_layer_names;
|
||||
use pheon::review::names::write_layer_names;
|
||||
use std::collections::BTreeMap;
|
||||
let mut bytes = shared(with_property(square(), "keep this"));
|
||||
bytes.extend_from_slice(&[0; 32]);
|
||||
|
|
@ -720,7 +741,7 @@ fn metadata_writer_preserves_unrelated_bytes_and_consolidates_updates() {
|
|||
|
||||
#[test]
|
||||
fn metadata_writer_rejects_ambiguous_carriers_versions_and_bad_names() {
|
||||
use pheon::review::{parse_layer_name, write_layer_names};
|
||||
use pheon::review::names::{parse_layer_name, write_layer_names};
|
||||
use std::collections::BTreeMap;
|
||||
let bytes = layout(&[("CHIP", vec![label((900, 7), "ordinary label")])]);
|
||||
assert!(
|
||||
|
|
@ -733,7 +754,7 @@ fn metadata_writer_rejects_ambiguous_carriers_versions_and_bad_names() {
|
|||
.unwrap_err()
|
||||
.contains("does not exist")
|
||||
);
|
||||
let bytes = layout(&[("CHIP", vec![label((900, 7), "KLAMATH_LAYER_NAMES_V2")])]);
|
||||
let bytes = layout(&[("CHIP", vec![label((900, 7), "PHEON_LAYER_NAMES_V2")])]);
|
||||
assert!(
|
||||
write_layer_names(&bytes, "CHIP", (901, 7), &BTreeMap::new())
|
||||
.unwrap_err()
|
||||
|
|
@ -788,7 +809,7 @@ fn metadata_cli_creates_a_separate_file_and_refuses_existing_output() {
|
|||
|
||||
#[test]
|
||||
fn scope_selection_distinguishes_reachable_subtrees_from_exact_cells() {
|
||||
use pheon::review::Scope;
|
||||
use pheon::review::selection::Scope;
|
||||
let a = layout(&[
|
||||
("CHIP", vec![reference("leaf", 0, 1)]),
|
||||
("leaf", vec![square()]),
|
||||
|
|
@ -817,8 +838,8 @@ fn scope_selection_distinguishes_reachable_subtrees_from_exact_cells() {
|
|||
};
|
||||
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());
|
||||
assert!(old.diagnostics.is_empty());
|
||||
assert!(Comparison::between(&old, &new).outcome().is_equal());
|
||||
let missing = Scope {
|
||||
top: Some("missing".to_string()),
|
||||
..Scope::default()
|
||||
|
|
@ -843,7 +864,7 @@ fn scope_selection_distinguishes_reachable_subtrees_from_exact_cells() {
|
|||
|
||||
#[test]
|
||||
fn layer_scope_filters_geometry_and_references_by_descendant_coverage() {
|
||||
use pheon::review::Scope;
|
||||
use pheon::review::selection::Scope;
|
||||
let mut other_layer = square();
|
||||
other_layer[8..10].copy_from_slice(&2_u16.to_be_bytes());
|
||||
let a = layout(&[
|
||||
|
|
@ -875,14 +896,17 @@ fn layer_scope_filters_geometry_and_references_by_descendant_coverage() {
|
|||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap();
|
||||
assert_eq!(Comparison::between(&old, &new).exit_code(), expected);
|
||||
assert!(old.issues.is_empty());
|
||||
assert_eq!(
|
||||
Comparison::between(&old, &new).outcome().exit_code(),
|
||||
expected
|
||||
);
|
||||
assert!(old.diagnostics.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_issues_do_not_hide_relevant_unsupported_objects_or_cycles() {
|
||||
use pheon::review::Scope;
|
||||
use pheon::review::selection::Scope;
|
||||
let mut unknown = square();
|
||||
unknown.truncate(unknown.len() - 4);
|
||||
record(&mut unknown, 0x7f00, &[]);
|
||||
|
|
@ -897,7 +921,7 @@ fn scoped_issues_do_not_hide_relevant_unsupported_objects_or_cycles() {
|
|||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.diagnostics
|
||||
.is_empty()
|
||||
);
|
||||
let scope = Scope {
|
||||
|
|
@ -909,7 +933,7 @@ fn scoped_issues_do_not_hide_relevant_unsupported_objects_or_cycles() {
|
|||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.diagnostics
|
||||
.is_empty()
|
||||
);
|
||||
let bytes = layout(&[
|
||||
|
|
@ -925,15 +949,15 @@ fn scoped_issues_do_not_hide_relevant_unsupported_objects_or_cycles() {
|
|||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap()
|
||||
.issues
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|s| s.contains("cyclic"))
|
||||
.any(|d| d.code == "hierarchy_cycle")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_filters_never_change_equality_or_totals() {
|
||||
use pheon::review::DisplayFilter;
|
||||
use pheon::review::selection::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());
|
||||
|
|
@ -946,7 +970,7 @@ fn display_filters_never_change_equality_or_totals() {
|
|||
);
|
||||
assert!(text.contains("display-only"));
|
||||
assert!(text.contains("0 of 2 object changes shown"));
|
||||
assert_eq!(diff.exit_code(), 1);
|
||||
assert_eq!(diff.outcome().exit_code(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1057,11 +1081,7 @@ fn git_external_driver_handles_changes_additions_deletions_and_errors() {
|
|||
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=pheon-text\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(directory.join(".gitattributes"), "*.gds diff=pheon-text\n").unwrap();
|
||||
fs::write(&renamed, shared(square())).unwrap();
|
||||
let result = git(&["diff", "--", "renamed layout.gds"]);
|
||||
assert!(
|
||||
|
|
@ -1145,13 +1165,25 @@ fn unchanged_layer_names_explain_geometry_changes_once() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn an_added_empty_document_is_still_a_presence_change() {
|
||||
fn library_presence_changes_distinguish_empty_and_absent_revisions() {
|
||||
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"));
|
||||
let absent = doc.empty_like();
|
||||
let added = Comparison::between(&absent, &doc);
|
||||
assert_eq!(added.outcome().exit_code(), 1);
|
||||
assert!(
|
||||
added
|
||||
.text(0)
|
||||
.contains("library presence: [\"absent\"] -> [\"present\"]\n")
|
||||
);
|
||||
assert!(!added.text(0).contains("equal under"));
|
||||
let removed = Comparison::between(&doc, &absent);
|
||||
assert_eq!(removed.outcome().exit_code(), 1);
|
||||
assert!(
|
||||
removed
|
||||
.text(0)
|
||||
.contains("library presence: [\"present\"] -> [\"absent\"]\n")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1213,8 +1245,8 @@ fn large_polygons_and_billion_instance_arrays_stay_compact() {
|
|||
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());
|
||||
assert!(doc.hierarchy(false, 8).len() < 200);
|
||||
assert!(Comparison::between(&doc, &doc).outcome().is_equal());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1241,7 +1273,7 @@ fn deep_hierarchy_comparison_and_rendering_are_iterative() {
|
|||
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);
|
||||
let tree = diff.hierarchy(false, 5);
|
||||
assert_eq!(diff.cells.len(), 1);
|
||||
assert!(tree.contains("children omitted"));
|
||||
assert!(tree.len() < 500);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use super::*;
|
||||
use pheon::review::{
|
||||
DisplayFilter, Scope,
|
||||
Diagnostic, Outcome, Side,
|
||||
report::{ReportInputs, ReportOptions, failure_report},
|
||||
selection::{DisplayFilter, Scope},
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ fn inputs() -> ReportInputs {
|
|||
fn report(old: &[u8], new: &[u8], options: &ReportOptions) -> Value {
|
||||
let a = Document::parse(old).unwrap();
|
||||
let b = Document::parse(new).unwrap();
|
||||
Comparison::between(&a, &b).json_report(&a, &b, &inputs(), options)
|
||||
Comparison::between(&a, &b).json_report(&inputs(), options)
|
||||
}
|
||||
|
||||
fn unknown(geometry: Vec<u8>) -> Vec<u8> {
|
||||
|
|
@ -26,12 +27,109 @@ fn unknown(geometry: Vec<u8>) -> Vec<u8> {
|
|||
layout(&[("CHIP", vec![object])])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comparison_reports_survive_dropped_documents_and_overwritten_inputs() {
|
||||
let comparison = {
|
||||
let mut old_bytes = shared(square());
|
||||
let mut new_bytes = shared(triangle());
|
||||
let old = Document::parse(&old_bytes).unwrap();
|
||||
let new = Document::parse(&new_bytes).unwrap();
|
||||
let comparison = Comparison::between(&old, &new);
|
||||
drop(old);
|
||||
drop(new);
|
||||
old_bytes.fill(0);
|
||||
new_bytes.fill(0);
|
||||
comparison
|
||||
};
|
||||
assert_eq!(comparison.outcome(), Outcome::Different);
|
||||
assert!(comparison.old.present && comparison.new.present);
|
||||
assert_eq!(comparison.old.units.as_ref().unwrap().len(), 16);
|
||||
let mut actual = comparison.json_report(
|
||||
&inputs(),
|
||||
&ReportOptions {
|
||||
hierarchy: true,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
actual["producer"]["version"] = json!("test");
|
||||
let expected: Value =
|
||||
serde_json::from_str(include_str!("../golden/report-geometry.json")).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
assert_eq!(
|
||||
comparison.hierarchy(false, 8),
|
||||
include_str!("../golden/review-hierarchy.txt")
|
||||
);
|
||||
assert_eq!(
|
||||
comparison.hierarchy(true, 8),
|
||||
include_str!("../golden/review-hierarchy.mmd")
|
||||
);
|
||||
// Display choices affect evidence, not the captured outcome or full graph.
|
||||
let limited = comparison.json_report(
|
||||
&inputs(),
|
||||
&ReportOptions {
|
||||
hierarchy: true,
|
||||
max_objects: Some(0),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
assert_eq!(limited["hierarchy"], actual["hierarchy"]);
|
||||
assert_eq!(limited["summary"], actual["summary"]);
|
||||
assert_eq!(limited["exit_code"], 1);
|
||||
assert!(comparison.text(0).contains("0 of 2 object changes shown"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comparison_diagnostics_capture_both_sides_and_scope_mismatch_once() {
|
||||
let comparison = {
|
||||
let bytes = unknown(square());
|
||||
let old = Document::parse(&bytes)
|
||||
.unwrap()
|
||||
.selected(
|
||||
&Scope {
|
||||
cell: Some("CHIP".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
let mut new = Document::parse(&bytes).unwrap();
|
||||
let comparison = Comparison::between(&old, &new);
|
||||
// Changes to source documents cannot alter an existing result.
|
||||
new.scope = old.scope.clone();
|
||||
new.diagnostics.clear();
|
||||
comparison
|
||||
};
|
||||
assert_eq!(
|
||||
comparison.outcome(),
|
||||
Outcome::Incomplete { different: false }
|
||||
);
|
||||
assert_eq!(comparison.diagnostics.len(), 3);
|
||||
assert_eq!(comparison.diagnostics[0].side, Some(Side::Old));
|
||||
assert_eq!(comparison.diagnostics[1].side, Some(Side::New));
|
||||
assert_eq!(comparison.diagnostics[2].code, "scope_mismatch");
|
||||
assert_eq!(comparison.diagnostics[2].side, None);
|
||||
let report = comparison.json_report(&inputs(), &ReportOptions::default());
|
||||
assert_eq!(report["status"], "incomplete");
|
||||
assert_eq!(report["result"], "unknown");
|
||||
assert_eq!(report["exit_code"], 2);
|
||||
assert_eq!(report["scope"]["cell"], "CHIP");
|
||||
assert_eq!(report["diagnostics"].as_array().unwrap().len(), 3);
|
||||
assert_eq!(report["diagnostics"][0]["side"], "old");
|
||||
assert_eq!(report["diagnostics"][1]["side"], "new");
|
||||
assert_eq!(report["diagnostics"][2]["code"], "scope_mismatch");
|
||||
let text = comparison.text(0);
|
||||
let scope = text.find("INCOMPLETE: comparison scopes differ").unwrap();
|
||||
let old = text.find("INCOMPLETE: old:").unwrap();
|
||||
let new = text.find("INCOMPLETE: new:").unwrap();
|
||||
assert!(scope < old && old < new);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_preserve_fixture_results_totals_and_replacement_links() {
|
||||
for pair in corpus() {
|
||||
let r = report(&pair.old, &pair.new, &ReportOptions::default());
|
||||
assert_eq!(r["schema_version"], 1);
|
||||
assert_eq!(r["comparison_profile"], "klamath-object-v2");
|
||||
assert_eq!(r["comparison_profile"], "pheon-structural-v1");
|
||||
assert_eq!(r["producer"]["version"], env!("CARGO_PKG_VERSION"));
|
||||
assert_eq!(r["status"], "complete", "{}", pair.name);
|
||||
assert_eq!(
|
||||
|
|
@ -110,12 +208,12 @@ fn future_layer_metadata_remains_incomplete_under_geometry_scopes() {
|
|||
let bytes = if location == "CHIP" {
|
||||
layout(&[(
|
||||
"CHIP",
|
||||
vec![square(), label((900, 7), "KLAMATH_LAYER_NAMES_V2")],
|
||||
vec![square(), label((900, 7), "PHEON_LAYER_NAMES_V2")],
|
||||
)])
|
||||
} else {
|
||||
layout(&[
|
||||
("CHIP", vec![square()]),
|
||||
("legend", vec![label((900, 7), "KLAMATH_LAYER_NAMES_V2")]),
|
||||
("legend", vec![label((900, 7), "PHEON_LAYER_NAMES_V2")]),
|
||||
])
|
||||
};
|
||||
let source = Document::parse(&bytes).unwrap().diagnostics[0].offset;
|
||||
|
|
@ -159,10 +257,10 @@ fn future_layer_metadata_remains_incomplete_under_geometry_scopes() {
|
|||
assert_eq!(diagnostic.layer, Some((900, 7)));
|
||||
assert_eq!(diagnostic.offset, source);
|
||||
let diff = Comparison::between(&doc, &doc);
|
||||
assert_eq!(diff.exit_code(), 2);
|
||||
assert!(!diff.is_equal());
|
||||
assert_eq!(diff.outcome().exit_code(), 2);
|
||||
assert!(!diff.outcome().is_equal());
|
||||
assert!(diff.text(0).contains("INCOMPLETE"));
|
||||
let json = diff.json_report(&doc, &doc, &inputs(), &ReportOptions::default());
|
||||
let json = diff.json_report(&inputs(), &ReportOptions::default());
|
||||
assert_eq!(json["status"], "incomplete");
|
||||
assert_eq!(json["result"], "unknown");
|
||||
assert_eq!(json["exit_code"], 2);
|
||||
|
|
@ -339,7 +437,7 @@ fn hierarchy_reports_shared_ancestors_and_symbolic_arrays() {
|
|||
.unwrap()
|
||||
.selected(&scope, false)
|
||||
.unwrap();
|
||||
let r = Comparison::between(&doc, &doc).json_report(&doc, &doc, &inputs(), &options);
|
||||
let r = Comparison::between(&doc, &doc).json_report(&inputs(), &options);
|
||||
assert_eq!(r["scope"]["cell"], "CHIP");
|
||||
assert_eq!(
|
||||
r["hierarchy"]["nodes"]
|
||||
|
|
@ -369,6 +467,14 @@ fn library_attributes_empty_cells_units_and_absence_are_explicit() {
|
|||
let r = report(&a, &b, &ReportOptions::default());
|
||||
assert_eq!(r["cell_changes"][0]["before"], Value::Null);
|
||||
assert_eq!(r["cell_changes"][0]["after"]["attributes"], json!([]));
|
||||
assert_eq!(r["cell_changes"][0]["attributes_changed"], true);
|
||||
let removed = report(&b, &a, &ReportOptions::default());
|
||||
assert_eq!(
|
||||
removed["cell_changes"][0]["before"]["attributes"],
|
||||
json!([])
|
||||
);
|
||||
assert_eq!(removed["cell_changes"][0]["after"], Value::Null);
|
||||
assert_eq!(removed["cell_changes"][0]["attributes_changed"], true);
|
||||
let mut b = b;
|
||||
let end = Document::parse(&b).unwrap().cells["empty"].end_offset;
|
||||
let mut attribute = Vec::new();
|
||||
|
|
@ -379,15 +485,11 @@ fn library_attributes_empty_cells_units_and_absence_are_explicit() {
|
|||
r["cell_changes"][0]["after"]["attributes"][0]["value"],
|
||||
json!([1])
|
||||
);
|
||||
assert_eq!(r["cell_changes"][0]["attributes_changed"], true);
|
||||
assert_eq!(r["inputs"]["old"]["units"]["encoding"], "real8");
|
||||
let doc = Document::parse(&a).unwrap();
|
||||
let absent = doc.empty_like();
|
||||
let r = Comparison::between(&absent, &doc).json_report(
|
||||
&absent,
|
||||
&doc,
|
||||
&inputs(),
|
||||
&ReportOptions::default(),
|
||||
);
|
||||
let r = Comparison::between(&absent, &doc).json_report(&inputs(), &ReportOptions::default());
|
||||
assert_eq!(r["inputs"]["old"]["present"], false);
|
||||
assert_eq!(r["inputs"]["old"]["units"], Value::Null);
|
||||
assert_eq!(
|
||||
|
|
@ -401,11 +503,8 @@ fn library_attributes_empty_cells_units_and_absence_are_explicit() {
|
|||
.find(|r| r.tag == RTAG_UNITS)
|
||||
.unwrap()
|
||||
.offset;
|
||||
b[units + 12..units + 20].copy_from_slice(
|
||||
&pheon::basic::encode_real8(2e-9)
|
||||
.unwrap()
|
||||
.to_be_bytes(),
|
||||
);
|
||||
b[units + 12..units + 20]
|
||||
.copy_from_slice(&pheon::basic::encode_real8(2e-9).unwrap().to_be_bytes());
|
||||
let r = report(&a, &b, &ReportOptions::default());
|
||||
assert_eq!(r["library_changes"][0]["tag"], RTAG_UNITS);
|
||||
assert_ne!(r["inputs"]["old"]["units"], r["inputs"]["new"]["units"]);
|
||||
|
|
@ -530,9 +629,7 @@ fn machine_reports_match_versioned_goldens() {
|
|||
&inputs(),
|
||||
&Scope::default(),
|
||||
&ReportOptions::default(),
|
||||
"invalid_input",
|
||||
"truncated record",
|
||||
Some("new"),
|
||||
&Diagnostic::new("invalid_input", "truncated record", Some(Side::New)),
|
||||
),
|
||||
),
|
||||
];
|
||||
|
|
@ -580,6 +677,24 @@ fn cli_emits_json_for_success_input_errors_scope_errors_and_argument_errors() {
|
|||
);
|
||||
report
|
||||
};
|
||||
let check_text_failure = |report: &Value, extra: &[&str]| {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_pheon"))
|
||||
.arg("diff")
|
||||
.arg(&a)
|
||||
.arg(&b)
|
||||
.args(extra)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(output.status.code(), Some(2));
|
||||
assert!(output.stdout.is_empty());
|
||||
assert_eq!(
|
||||
String::from_utf8(output.stderr).unwrap(),
|
||||
format!(
|
||||
"pheon: {}\n",
|
||||
report["diagnostics"][0]["message"].as_str().unwrap()
|
||||
)
|
||||
);
|
||||
};
|
||||
let full = command(&["--hierarchy", "graph"]);
|
||||
assert_eq!(full["result"], "different");
|
||||
assert!(full["hierarchy"].is_object());
|
||||
|
|
@ -597,14 +712,35 @@ fn cli_emits_json_for_success_input_errors_scope_errors_and_argument_errors() {
|
|||
assert_eq!(failure["status"], "failed");
|
||||
assert_eq!(failure["result"], "unknown");
|
||||
assert_eq!(failure["summary"], Value::Null);
|
||||
if extra.first() == Some(&"--top") {
|
||||
assert_eq!(failure["diagnostics"][0]["code"], "invalid_scope");
|
||||
assert_eq!(failure["diagnostics"][0]["side"], Value::Null);
|
||||
check_text_failure(&failure, extra);
|
||||
}
|
||||
}
|
||||
fs::write(&b, b"invalid").unwrap();
|
||||
let invalid = command(&[]);
|
||||
assert_eq!(invalid["diagnostics"][0]["code"], "invalid_input");
|
||||
assert_eq!(invalid["diagnostics"][0]["side"], "new");
|
||||
assert_eq!(invalid["inputs"]["new"]["path"], b.to_str().unwrap());
|
||||
check_text_failure(&invalid, &[]);
|
||||
fs::write(&a, b"invalid").unwrap();
|
||||
let invalid = command(&[]);
|
||||
assert_eq!(invalid["diagnostics"][0]["code"], "invalid_input");
|
||||
assert_eq!(invalid["diagnostics"][0]["side"], "old");
|
||||
check_text_failure(&invalid, &[]);
|
||||
fs::write(&a, shared(square())).unwrap();
|
||||
fs::remove_file(&b).unwrap();
|
||||
assert_eq!(command(&[])["diagnostics"][0]["code"], "io_error");
|
||||
let missing = command(&[]);
|
||||
assert_eq!(missing["diagnostics"][0]["code"], "io_error");
|
||||
assert_eq!(missing["diagnostics"][0]["side"], "new");
|
||||
check_text_failure(&missing, &[]);
|
||||
fs::remove_file(&a).unwrap();
|
||||
let missing = command(&[]);
|
||||
assert_eq!(missing["diagnostics"][0]["code"], "io_error");
|
||||
assert_eq!(missing["diagnostics"][0]["side"], "old");
|
||||
check_text_failure(&missing, &[]);
|
||||
fs::write(&a, shared(square())).unwrap();
|
||||
fs::write(&b, fs::read(&a).unwrap()).unwrap();
|
||||
assert_eq!(command(&[])["result"], "equal");
|
||||
fs::write(&b, unknown(square())).unwrap();
|
||||
|
|
@ -613,7 +749,7 @@ fn cli_emits_json_for_success_input_errors_scope_errors_and_argument_errors() {
|
|||
&b,
|
||||
layout(&[
|
||||
("CHIP", vec![square()]),
|
||||
("legend", vec![label((900, 7), "KLAMATH_LAYER_NAMES_V2")]),
|
||||
("legend", vec![label((900, 7), "PHEON_LAYER_NAMES_V2")]),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ fn fractional_aref_pitches_are_rejected_by_all_arrow_readers() {
|
|||
record(&mut bytes, records::RTAG_ENDLIB, &[]);
|
||||
let doc = pheon::review::Document::parse(&bytes).unwrap();
|
||||
assert_eq!(
|
||||
pheon::review::Comparison::between(&doc, &doc).exit_code(),
|
||||
pheon::review::Comparison::between(&doc, &doc).outcome().exit_code(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue