The dual-read classification, pure over its inputs: the tracked entry parses to a `CanonicalNode` and its `sourceContentHash` anchor decides fresh vs stale; a malformed tracked entry warns and falls through to the sidecar; a missing or unreadable sidecar degrades to `None` with a warning. Both the local body (repo-read sources) and the routed path (wire-carried sources) run this SAME code.
(sources: AttestationSources, inputs: &LiftInputs)
| 351 | /// warning. Both the local body (repo-read sources) and the routed path |
| 352 | /// (wire-carried sources) run this SAME code. |
| 353 | pub fn classify_attestation(sources: AttestationSources, inputs: &LiftInputs) -> Attestation { |
| 354 | if let Some(tracked) = sources.tracked { |
| 355 | let raw = String::from_utf8_lossy(&tracked.content); |
| 356 | match serde_json::from_str::<CanonicalNode>(raw.trim_end()) { |
| 357 | Ok(node) => { |
| 358 | // Staleness: prefer the frontmatter anchor `sourceContentHash`; |
| 359 | // frontmatter_json round-trips as a flat-scalar JSON object. |
| 360 | let recorded = serde_json::from_str::<Value>(&tracked.frontmatter_json) |
| 361 | .ok() |
| 362 | .and_then(|v| { |
| 363 | v.get("sourceContentHash") |
| 364 | .and_then(Value::as_str) |
| 365 | .map(str::to_owned) |
| 366 | }); |
| 367 | let current = source_content_hash(inputs); |
| 368 | return match recorded { |
| 369 | Some(h) if h == current => Attestation::Fresh(Box::new(node)), |
| 370 | _ => Attestation::Stale(Box::new(node)), |
| 371 | }; |
| 372 | } |
| 373 | Err(e) => { |
| 374 | eprintln!( |
| 375 | "warning: ignoring malformed tracked attestation {}: {e}", |
| 376 | tracked.vault_path |
| 377 | ); |
| 378 | // fall through to the legacy sidecar |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | let Some(sidecar) = sources.sidecar else { |
| 383 | return Attestation::None; |
| 384 | }; |
| 385 | let artifact: Value = match serde_json::from_str(&sidecar.text) { |
| 386 | Ok(v) => v, |
| 387 | Err(e) => { |
| 388 | eprintln!( |
| 389 | "warning: ignoring unreadable attestation sidecar {}: {e}", |
| 390 | sidecar.path |
| 391 | ); |
| 392 | return Attestation::None; |
| 393 | } |
| 394 | }; |
| 395 | let node_val = match artifact.get("node") { |
| 396 | Some(n) => n.clone(), |
| 397 | None => { |
| 398 | eprintln!( |
| 399 | "warning: attestation sidecar {} has no 'node' — ignoring", |
| 400 | sidecar.path |
| 401 | ); |
| 402 | return Attestation::None; |
| 403 | } |
| 404 | }; |
| 405 | let node: CanonicalNode = match serde_json::from_value(node_val) { |
| 406 | Ok(n) => n, |
| 407 | Err(e) => { |
| 408 | eprintln!( |
| 409 | "warning: ignoring malformed attestation node in {}: {e}", |
| 410 | sidecar.path |
no test coverage detected