use crate::{
OmenaQueryStyleSourceInputV0, summarize_omena_query_style_diagnostics_for_workspace_file,
};
fn sources(entries: &[(&str, &str)]) -> Vec<OmenaQueryStyleSourceInputV0> {
entries
.iter()
.map(|(path, source)| OmenaQueryStyleSourceInputV0 {
style_path: path.to_string(),
style_source: source.to_string(),
})
.collect()
}
fn diagnostic_fingerprint(entry: &str, corpus: &[(&str, &str)]) -> Vec<(String, String)> {
let Some(summary) = summarize_omena_query_style_diagnostics_for_workspace_file(
entry,
sources(corpus).as_slice(),
&[],
&[],
None,
) else {
return Vec::new();
};
let mut fingerprint = summary
.diagnostics
.iter()
.map(|diagnostic| (diagnostic.code.to_string(), diagnostic.message.clone()))
.collect::<Vec<_>>();
fingerprint.sort();
fingerprint
}
const CONVERGENCE: [(&str, &str); 5] = [
(
"/tmp/cv_d.scss",
"$brand: blue !default; .base { color: $brand; }",
),
("/tmp/cv_b.scss", "@forward \"./cv_d\" with ($brand: red);"),
("/tmp/cv_c.scss", "@forward \"./cv_d\" with ($brand: red);"),
(
"/tmp/cv_e.scss",
"@forward \"./cv_d\" with ($brand: green);",
),
(
"/tmp/cv_a.scss",
"@use \"./cv_b\" as b; @use \"./cv_c\" as c; @use \"./cv_e\" as e;",
),
];
const NESTED_MERGE: [(&str, &str); 5] = [
(
"/tmp/nm_d.scss",
"$x: blue !default; $y: purple !default; .base { color: $x; border-color: $y; }",
),
("/tmp/nm_b.scss", "@forward \"./nm_d\" with ($y: 10);"),
("/tmp/nm_c.scss", "@forward \"./nm_d\" with ($y: 20);"),
(
"/tmp/nm_a.scss",
"@forward \"./nm_b\" with ($x: 1); @forward \"./nm_c\" with ($x: 2);",
),
("/tmp/nm_app.scss", "@use \"./nm_a\" as a;"),
];
const CHAIN: [(&str, &str); 4] = [
("/tmp/ch_a.scss", "$x: 0 !default; .base { color: $x; }"),
("/tmp/ch_b.scss", "@forward \"./ch_a\" with ($x: 1);"),
("/tmp/ch_c.scss", "@forward \"./ch_b\" with ($x: 2);"),
("/tmp/ch_driver.scss", "@use \"./ch_c\" as c;"),
];
const CONFIG_CYCLE: [(&str, &str); 3] = [
(
"/tmp/cy_a.scss",
"$x: 0 !default; @forward \"./cy_b\" with ($x: 1); .a { color: $x; }",
),
(
"/tmp/cy_b.scss",
"$x: 0 !default; @forward \"./cy_a\" with ($x: 2); .b { color: $x; }",
),
("/tmp/cy_driver.scss", "@use \"./cy_a\" as a;"),
];
type BatteryCase = (
&'static str,
&'static str,
&'static [(&'static str, &'static str)],
);
const BATTERY: &[BatteryCase] = &[
("convergence", "/tmp/cv_a.scss", &CONVERGENCE),
("nested_merge", "/tmp/nm_app.scss", &NESTED_MERGE),
("chain", "/tmp/ch_driver.scss", &CHAIN),
("config_cycle", "/tmp/cy_driver.scss", &CONFIG_CYCLE),
];
#[test]
fn worklist_emits_byte_identical_diagnostics_to_rawallpaths() {
let mut exercised_non_empty = false;
for (label, entry, corpus) in BATTERY {
let worklist = diagnostic_fingerprint(entry, corpus);
let rawallpaths =
crate::style::with_rawallpaths_closure(|| diagnostic_fingerprint(entry, corpus));
assert_eq!(
worklist, rawallpaths,
"diagnostics diverge between the worklist and RawAllPaths on corpus `{label}`"
);
exercised_non_empty |= !worklist.is_empty();
}
assert!(
exercised_non_empty,
"battery produced no diagnostics — the differential is not exercising the closure"
);
}