Replay already-read manifest bytes. The caller supplies the base directory for relative artifact roots so an RPC caller can name the same directory on the service host.
(
bytes: &[u8],
base: &Path,
checker: &Path,
context: &EvidenceContext,
node: &CanonicalNode,
)
| 229 | /// for relative artifact roots so an RPC caller can name the same directory on |
| 230 | /// the service host. |
| 231 | pub fn replay_bytes( |
| 232 | bytes: &[u8], |
| 233 | base: &Path, |
| 234 | checker: &Path, |
| 235 | context: &EvidenceContext, |
| 236 | node: &CanonicalNode, |
| 237 | ) -> Result<EvidenceReport, EvidenceError> { |
| 238 | if context.intent_id != node.id || context.intent_substance_hash != intent_substance_hash(node) |
| 239 | { |
| 240 | return Err(EvidenceError::NodeChanged); |
| 241 | } |
| 242 | if bytes.len() as u64 > MANIFEST_LIMIT { |
| 243 | return Err(EvidenceError::ManifestTooLarge); |
| 244 | } |
| 245 | let value = atomic_canonical::jcs::admit_document(bytes) |
| 246 | .map_err(|error| EvidenceError::ManifestAdmission(error.to_string()))?; |
| 247 | let manifest: Manifest = serde_json::from_value(value) |
| 248 | .map_err(|error| EvidenceError::InvalidManifest(error.to_string()))?; |
| 249 | validate_manifest(&manifest, context, node)?; |
| 250 | let mut decisions = Vec::new(); |
| 251 | for mut claim in manifest.claims { |
| 252 | // Canonicalize the root once; checker paths remain relative to this |
| 253 | // root, not its working directory. Missing roots remain unknown. |
| 254 | let artifact_root = base.join(&claim.artifact_root); |
| 255 | match artifact_root.canonicalize() { |
| 256 | Ok(root) if root.is_dir() => claim.artifact_root = root, |
| 257 | _ => { |
| 258 | let request = serde_json::json!({ |
| 259 | "schema_version": "atomic-evidence-replay-request/v1", |
| 260 | "context": context, |
| 261 | "claim": claim, |
| 262 | }); |
| 263 | let digest = atomic_canonical::hash::content_hash(&request); |
| 264 | decisions.push(unknown(&claim, &digest, "artifact_root_unavailable")); |
| 265 | continue; |
| 266 | } |
| 267 | } |
| 268 | let request = serde_json::json!({ |
| 269 | "schema_version": "atomic-evidence-replay-request/v1", |
| 270 | "context": context, |
| 271 | "claim": claim, |
| 272 | }); |
| 273 | let request_digest = atomic_canonical::hash::content_hash(&request); |
| 274 | let input = serde_json::to_vec(&serde_json::json!({ |
| 275 | "request": request, |
| 276 | "request_digest": request_digest, |
| 277 | }))?; |
| 278 | let decision = match invoke_checker(checker, &input, CHECKER_TIMEOUT) { |
| 279 | Ok(bytes) => match atomic_canonical::jcs::admit_document(&bytes) |
| 280 | .ok() |
| 281 | .and_then(|value| serde_json::from_value::<EvidenceDecision>(value).ok()) |
| 282 | { |
| 283 | Some(decision) if valid_decision(&decision, &claim, &request_digest) => decision, |
| 284 | _ => unknown( |
| 285 | &claim, |
| 286 | &request_digest, |
| 287 | "invalid_or_unbound_checker_response", |
| 288 | ), |
no test coverage detected