iter ms.1: pipeline.rs format!("check: {e}") → {e:#} preserves anyhow Caused-by chain in JSON-cohort feedback

Inline pinning test in pipeline.rs constructs the same chain
shape module_name_from_json produces on serde-parse failure
(leaf wrapped with "parsing JSON in <path>" context) and
asserts both layers survive the formatter. RED→GREEN against
the property, not against production line bytes — for a
two-character fix, extracting a helper just for testability
would be over-engineering.

The strip_locations regex collapses \nCaused by: chains; the
{:#} alternate Display joins with ': ' on one line, so the
collapser is a no-op on the fixed output. AILX cohort
unaffected — only the harness-side anyhow path (module
rename pre-check) was dropping cause information.

Harness suite: 14/14 green (was 13/13 + 1 new pin).
This commit is contained in:
2026-05-12 13:28:48 +02:00
parent 2efaee07f0
commit 614fd8bc93
4 changed files with 83 additions and 1 deletions
@@ -115,7 +115,7 @@ pub fn run_pipeline(
}
Err(e) => {
return Ok(PipelineCapture {
error: Some(format!("check: {e}")),
error: Some(format!("check: {e:#}")),
stdout: String::new(),
stderr: e.to_string(),
});
@@ -217,3 +217,30 @@ fn run_with_timeout(bin: &Path, timeout: Duration) -> Result<RunOutput> {
std::thread::sleep(Duration::from_millis(25));
}
}
#[cfg(test)]
mod tests {
use anyhow::{anyhow, Context, Error};
/// Constructs the same chain shape `module_name_from_json`
/// produces on a serde-parse failure: a leaf error wrapped
/// with a "parsing JSON in <path>" context. Asserts that the
/// format string used at pipeline.rs error-emission preserves
/// both layers.
#[test]
fn check_format_preserves_anyhow_chain() {
let leaf: Error = anyhow!("expected value at line 1 column 1");
let chained = Err::<(), _>(leaf)
.context("parsing JSON in /tmp/x.ail.json")
.unwrap_err();
let formatted = format!("check: {chained:#}");
assert!(
formatted.contains("parsing JSON in /tmp/x.ail.json"),
"top-level context missing; got: {formatted}",
);
assert!(
formatted.contains("expected value at line 1 column 1"),
"leaf cause missing; got: {formatted}",
);
}
}