Skip to content

Commit f2a6a70

Browse files
Fix recon's real baseline and simplify ledger verification (#271)
The committed recon baseline includes an `_comment` array. The native comparator previously tried to deserialize that metadata as scanner counts, so scheduled recon and `just recon` failed before reading reports. Read a typed assail/pons envelope, preserve strict count validation, and exercise the actual committed baseline through the CLI. Split ledger derivation into inventory, taxonomy, assignment, grading and absence checks without changing its report or exit-code contracts. This addresses the follow-up review on #270 and contributes to hyperpolymath/echo-types#362. Validation: Windows native helper tests (10 test executions) and all-target Clippy with warnings denied passed. The CLI checks successful comparison, regression exit 1, malformed input/unavailable report exit 2, metadata tolerance and withholding a baseline proposal on missing reports. Hosted checks and final review remain required before merge. Creusot/Pearlite and Verus remain OPEN/not run as documented; these are regression tests, not formal proof.
1 parent 9d823cb commit f2a6a70

4 files changed

Lines changed: 101 additions & 9 deletions

File tree

‎docs/native-ci-helper-migration.adoc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ all-targets Clippy with warnings denied before testing the real inventory.
3737
Creusot with Pearlite contracts: `OPEN`, not run for these CI utilities.
3838
Verus: `OPEN`, not run. Executable contract tests are not formal proofs;
3939
framework provenance tiers are retained and no independent witness is claimed.
40+
41+
== Review follow-up
42+
43+
The recon reader uses a typed baseline envelope for `assail` and `pons`.
44+
Descriptive metadata such as the repository's `_comment` array is ignored;
45+
malformed scanner counts remain input errors. The CLI regression loads the
46+
actual committed baseline as well as invalid counts and unavailable reports.
47+
Ledger derivation is split into inventory, taxonomy, assignment, grading and
48+
absence checks with the same claim/input exit codes and report semantics.

‎tools/ci/src/bin/recon-compare.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ struct Args {
1717
#[arg(long)]
1818
no_fail: bool,
1919
}
20+
#[derive(Default, serde::Deserialize)]
21+
struct Baseline {
22+
#[serde(default)]
23+
assail: BTreeMap<String, u64>,
24+
#[serde(default)]
25+
pons: BTreeMap<String, u64>,
26+
}
2027
fn run() -> Result<()> {
2128
let args = Args::parse();
22-
let baseline: BTreeMap<String, BTreeMap<String, u64>> = if args.baseline.exists() {
29+
let baseline: Baseline = if args.baseline.exists() {
2330
serde_json::from_slice(&fs::read(&args.baseline)?)?
2431
} else {
25-
BTreeMap::new()
32+
Baseline::default()
2633
};
2734
let mut text = String::from("## Recon: two independent scans\n\n");
2835
let mut observed = BTreeMap::new();
@@ -48,8 +55,12 @@ fn run() -> Result<()> {
4855
continue;
4956
}
5057
};
51-
let frozen = baseline.get(name).cloned().unwrap_or_default();
52-
regressions += regression_count(&counts, &frozen);
58+
let frozen = if name == "assail" {
59+
&baseline.assail
60+
} else {
61+
&baseline.pons
62+
};
63+
regressions += regression_count(&counts, frozen);
5364
text.push_str("| category | observed | baseline | verdict |\n|---|---|---|---|\n");
5465
for (category, count) in &counts {
5566
let old = frozen.get(category);

‎tools/ci/src/lib.rs‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ fn regex(pattern: Option<&str>) -> Result<Option<Regex>> {
8989
.map_err(|e| input(format!("invalid selection regex: {e}")))
9090
}
9191

92-
pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<Value> {
92+
type Inventory = BTreeMap<String, BTreeSet<String>>;
93+
type Assignments<'a> = BTreeMap<(String, String), (&'a Cell, bool)>;
94+
type Coordinates = BTreeSet<(String, String)>;
95+
96+
fn parse_inventory(inventory: &Value) -> Result<Inventory> {
9397
let inventory: BTreeMap<String, BTreeSet<String>> = serde_json::from_value(inventory.clone())?;
9498
if inventory
9599
.iter()
@@ -100,19 +104,26 @@ pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<V
100104
if inventory.values().map(BTreeSet::len).sum::<usize>() == 0 {
101105
return Err(input("inventory contains no executed tests"));
102106
}
103-
let ledger: Ledger = serde_json::from_value(ledger.clone())?;
107+
Ok(inventory)
108+
}
109+
110+
fn check_taxonomy(ledger: &Ledger) -> Result<()> {
104111
for cell in ledger.entries.iter().chain(&ledger.buckets) {
105112
if !ledger.taxonomy.categories.contains(&cell.category)
106113
|| !ledger.taxonomy.aspects.contains(&cell.aspect)
107114
{
108115
return Err(input("a ledger cell is outside the declared taxonomy"));
109116
}
110117
}
118+
Ok(())
119+
}
120+
121+
fn assign_entries<'a>(ledger: &'a Ledger, inventory: &Inventory) -> Result<Assignments<'a>> {
111122
let mut assignments = BTreeMap::<(String, String), (&Cell, bool)>::new();
112123
for cell in &ledger.entries {
113124
let pattern = regex(cell.pattern.as_deref())?;
114125
let mut matched = 0;
115-
for (binary, names) in &inventory {
126+
for (binary, names) in inventory {
116127
if !cell.bins.contains(binary) {
117128
continue;
118129
}
@@ -133,6 +144,14 @@ pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<V
133144
)));
134145
}
135146
}
147+
Ok(assignments)
148+
}
149+
150+
fn assign_buckets<'a>(
151+
ledger: &'a Ledger,
152+
inventory: &Inventory,
153+
assignments: &mut Assignments<'a>,
154+
) -> Result<()> {
136155
let buckets: Vec<_> = ledger
137156
.buckets
138157
.iter()
@@ -144,7 +163,7 @@ pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<V
144163
.map(|d| Regex::new(&d.r#match).map_err(|e| input(e.to_string())))
145164
.collect::<Result<_>>()?;
146165
let mut remainder = 0;
147-
for (binary, names) in &inventory {
166+
for (binary, names) in inventory {
148167
for name in names {
149168
let key = (binary.clone(), name.clone());
150169
if assignments.contains_key(&key) {
@@ -170,6 +189,13 @@ pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<V
170189
"{remainder} tests exceed the declared remainder ratchet"
171190
)));
172191
}
192+
Ok(())
193+
}
194+
195+
fn grade(
196+
assignments: Assignments<'_>,
197+
root: &Path,
198+
) -> Result<([usize; 3], Coordinates, Vec<Value>)> {
173199
let mut tiers = [0usize; 3];
174200
let mut cells = BTreeSet::new();
175201
let mut entries = Vec::new();
@@ -200,11 +226,26 @@ pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<V
200226
cells.insert((cell.category.clone(), cell.aspect.clone()));
201227
entries.push(json!({"test_id":format!("{binary}::{name}"), "category":cell.category, "aspect":cell.aspect, "provenance":tier, "proof_ladder":[], "result":"passed"}));
202228
}
229+
Ok((tiers, cells, entries))
230+
}
231+
232+
fn check_absent(ledger: &Ledger, cells: &Coordinates) -> Result<()> {
203233
for absent in &ledger.declared_absent {
204234
if cells.contains(&(absent.category.clone(), absent.aspect.clone())) {
205235
return Err(claim("a coordinate is both declared absent and covered"));
206236
}
207237
}
238+
Ok(())
239+
}
240+
241+
pub fn derive_report(inventory: &Value, ledger: &Value, root: &Path) -> Result<Value> {
242+
let inventory = parse_inventory(inventory)?;
243+
let ledger: Ledger = serde_json::from_value(ledger.clone())?;
244+
check_taxonomy(&ledger)?;
245+
let mut assignments = assign_entries(&ledger, &inventory)?;
246+
assign_buckets(&ledger, &inventory, &mut assignments)?;
247+
let (tiers, cells, entries) = grade(assignments, root)?;
248+
check_absent(&ledger, &cells)?;
208249
Ok(
209250
json!({"schema_version":1, "suite":ledger.suite.as_deref().unwrap_or("unknown"),
210251
"summary":{"passed":entries.len(), "total":entries.len(), "actually_proven":tiers[0], "provisionally_proven":tiers[1], "unproven":tiers[2], "covered_cells":cells.len(), "cat_aspect_cells":ledger.taxonomy.categories.len()*ledger.taxonomy.aspects.len(), "lattice_covered":cells.len()}, "entries":entries}),

‎tools/ci/tests/cli.rs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ fn recon_cli_distinguishes_regressions_and_unavailable_reports() -> Result<()> {
8080
&json!({"weak_points":[{"category":"A"},{"category":"A"}]}),
8181
)?;
8282
let pons = temp.write("pons.json", &json!({"findings":[]}))?;
83-
let baseline = temp.write("baseline.json", &json!({"assail":{"A":1},"pons":{}}))?;
83+
let baseline = temp.write(
84+
"baseline.json",
85+
&json!({"_comment":["metadata is not a scanner"],"assail":{"A":1},"pons":{}}),
86+
)?;
8487
let run = |advisory: bool| {
8588
let mut command = Command::new(env!("CARGO_BIN_EXE_recon-compare"));
8689
command
@@ -134,3 +137,31 @@ fn repository_ledger_taxonomy_and_selectors_are_readable() -> Result<()> {
134137
}
135138
Ok(())
136139
}
140+
141+
#[test]
142+
fn recon_cli_accepts_the_actual_repository_baseline() -> Result<()> {
143+
let temp = Temp::new()?;
144+
let assail = temp.write("assail.json", &json!({"weak_points":[]}))?;
145+
let pons = temp.write("pons.json", &json!({"findings":[]}))?;
146+
let baseline: Value = serde_json::from_str(include_str!("../../../recon/baseline.json"))?;
147+
let baseline = temp.write("baseline.json", &baseline)?;
148+
let run = || {
149+
Command::new(env!("CARGO_BIN_EXE_recon-compare"))
150+
.args([
151+
"--baseline",
152+
baseline.to_str().unwrap(),
153+
"--assail",
154+
assail.to_str().unwrap(),
155+
"--pons",
156+
pons.to_str().unwrap(),
157+
])
158+
.output()
159+
};
160+
assert!(run()?.status.success());
161+
temp.write(
162+
"baseline.json",
163+
&json!({"_comment":[], "assail":{"A":"invalid"},"pons":{}}),
164+
)?;
165+
assert_eq!(run()?.status.code(), Some(2));
166+
Ok(())
167+
}

0 commit comments

Comments
 (0)