fix(review): retain metadata version diagnostics across scopes

This commit is contained in:
Jan Petykiewicz 2026-11-15 19:46:52 -08:00
commit 0cbb2c0e2f
4 changed files with 104 additions and 7 deletions

View file

@ -130,7 +130,9 @@ side is an addition/deletion.
targets use that layer transitively. Cells with no relevant content are omitted. targets use that layer transitively. Cells with no relevant content are omitted.
Unresolved references, cycles, and unsupported records with unknown layer effect Unresolved references, cycles, and unsupported records with unknown layer effect
remain incomplete results. Unsupported objects on another known layer can be remain incomplete results. Unsupported objects on another known layer can be
excluded. Library fields, including units, remain compared. Scoped dumps and excluded. Library fields, including units, remain compared. Unsupported layer-name
version diagnostics are always retained, since those declarations can affect any
layer or cell in the library. Scoped dumps and
hierarchy views accept the same selectors. Scope selection parses the complete hierarchy views accept the same selectors. Scope selection parses the complete
input: malformed record grammar and conflicting metadata are still errors. input: malformed record grammar and conflicting metadata are still errors.

View file

@ -597,15 +597,22 @@ impl<'a> Document<'a> {
} }
fn read_metadata(&mut self) -> Result<(), String> { fn read_metadata(&mut self) -> Result<(), String> {
for cell in self.cells.values_mut() { for (cell_name, cell) in &mut self.cells {
for object in cell.objects.iter_mut().filter(|o| o.kind == RTAG_TEXT) { for object in cell.objects.iter().filter(|o| o.kind == RTAG_TEXT) {
let text = object.field(RTAG_STRING).unwrap(); let text = object.field(RTAG_STRING).unwrap();
if text.starts_with(b"KLAMATH_LAYER_NAMES_") && text != LAYER_SENTINEL.as_bytes() { if text.starts_with(b"KLAMATH_LAYER_NAMES_") && text != LAYER_SENTINEL.as_bytes() {
object.issues.push(Diagnostic::at( // Layer names apply across the library. An unknown version
// may describe layers used outside this carrier or cell, so
// geometry scope selection cannot establish its relevance.
let mut diagnostic = Diagnostic::at(
"unsupported_metadata_version", "unsupported_metadata_version",
object.offset, object.offset,
"unsupported layer-name metadata version".to_string(), "unsupported layer-name metadata version".to_string(),
)); );
diagnostic.cell = Some(cell_name.clone());
diagnostic.layer = object.layer;
diagnostic.message = format!("cell {cell_name:?}: {}", diagnostic.message);
self.global_issues.push(diagnostic);
} }
} }
let carriers: BTreeSet<_> = cell let carriers: BTreeSet<_> = cell

View file

@ -63,9 +63,9 @@ pub fn write_layer_names(
) -> Result<Vec<u8>, String> { ) -> Result<Vec<u8>, String> {
let doc = Document::parse(input)?; let doc = Document::parse(input)?;
if doc if doc
.issues .diagnostics
.iter() .iter()
.any(|i| i.contains("unsupported layer-name metadata version")) .any(|i| i.code == "unsupported_metadata_version")
{ {
return Err("cannot rewrite an unsupported layer-name metadata version".to_string()); return Err("cannot rewrite an unsupported layer-name metadata version".to_string());
} }

View file

@ -104,6 +104,73 @@ fn incomplete_reports_distinguish_known_differences_and_include_structured_locat
); );
} }
#[test]
fn future_layer_metadata_remains_incomplete_under_geometry_scopes() {
for location in ["CHIP", "legend"] {
let bytes = if location == "CHIP" {
layout(&[(
"CHIP",
vec![square(), label((900, 7), "KLAMATH_LAYER_NAMES_V2")],
)])
} else {
layout(&[
("CHIP", vec![square()]),
("legend", vec![label((900, 7), "KLAMATH_LAYER_NAMES_V2")]),
])
};
let source = Document::parse(&bytes).unwrap().diagnostics[0].offset;
for scope in [
Scope::default(),
Scope {
layer: Some((1, 0)),
..Default::default()
},
Scope {
layer: Some((999, 0)),
..Default::default()
},
Scope {
top: Some("CHIP".into()),
..Default::default()
},
Scope {
cell: Some("CHIP".into()),
..Default::default()
},
Scope {
top: Some("CHIP".into()),
layer: Some((1, 0)),
..Default::default()
},
Scope {
cell: Some("CHIP".into()),
layer: Some((1, 0)),
..Default::default()
},
] {
let doc = Document::parse(&bytes)
.unwrap()
.selected(&scope, false)
.unwrap();
assert_eq!(doc.diagnostics.len(), 1, "{scope:?}");
let diagnostic = &doc.diagnostics[0];
assert_eq!(diagnostic.code, "unsupported_metadata_version");
assert_eq!(diagnostic.cell.as_deref(), Some(location));
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!(diff.text(0).contains("INCOMPLETE"));
let json = diff.json_report(&doc, &doc, &inputs(), &ReportOptions::default());
assert_eq!(json["status"], "incomplete");
assert_eq!(json["result"], "unknown");
assert_eq!(json["exit_code"], 2);
assert_eq!(json["diagnostics"].as_array().unwrap().len(), 2);
}
}
}
#[test] #[test]
fn json_is_unbounded_by_default_and_explicit_filters_do_not_change_totals() { fn json_is_unbounded_by_default_and_explicit_filters_do_not_change_totals() {
let a = layout(&[("CHIP", vec![])]); let a = layout(&[("CHIP", vec![])]);
@ -542,4 +609,25 @@ fn cli_emits_json_for_success_input_errors_scope_errors_and_argument_errors() {
assert_eq!(command(&[])["result"], "equal"); assert_eq!(command(&[])["result"], "equal");
fs::write(&b, unknown(square())).unwrap(); fs::write(&b, unknown(square())).unwrap();
assert_eq!(command(&[])["status"], "incomplete"); assert_eq!(command(&[])["status"], "incomplete");
fs::write(
&b,
layout(&[
("CHIP", vec![square()]),
("legend", vec![label((900, 7), "KLAMATH_LAYER_NAMES_V2")]),
]),
)
.unwrap();
for flags in [
&["--layer", "1/0"][..],
&["--top", "CHIP"],
&["--cell", "CHIP", "--layer", "1/0"],
] {
let report = command(flags);
assert_eq!(report["status"], "incomplete");
assert_eq!(report["exit_code"], 2);
assert_eq!(
report["diagnostics"][0]["code"],
"unsupported_metadata_version"
);
}
} }