The ExportProvenance domain: resolve the target (URN/prefix/hash with the CLI resolver's exact semantics), load the explaining graphs (the REV_DEPS lookup with the disk-scan fallback, newest first), map each to the projection input, and pre-walk the prior-turn chain the human trace renders. The CLI projects/signs client-side over the bundles.
(
state: std::sync::Arc<DaemonState>,
request: Request<ExportProvenanceRequest>,
)
| 5291 | /// to the projection input, and pre-walk the prior-turn chain the human |
| 5292 | /// trace renders. The CLI projects/signs client-side over the bundles. |
| 5293 | async fn export_provenance_impl( |
| 5294 | state: std::sync::Arc<DaemonState>, |
| 5295 | request: Request<ExportProvenanceRequest>, |
| 5296 | ) -> Result<Response<ExportProvenanceResponse>, Status> { |
| 5297 | use atomic_core::types::Base32; |
| 5298 | let request = request.into_inner(); |
| 5299 | let handle = state.resolve(request.repository.as_ref().unwrap())?; |
| 5300 | state.log_rpc("ExportProvenance", Some(&handle)); |
| 5301 | let gate_handle = handle.clone(); |
| 5302 | let _gate = gate_handle.exclusive().await; |
| 5303 | let target = request.target.clone(); |
| 5304 | let exact = request.change.as_ref().and_then(|hash| { |
| 5305 | hash.value |
| 5306 | .clone() |
| 5307 | .try_into() |
| 5308 | .ok() |
| 5309 | .map(atomic_core::types::Merkle) |
| 5310 | }); |
| 5311 | let person_did = request.person_did.clone().unwrap_or_default(); |
| 5312 | let (resolved, bundles) = tokio::task::spawn_blocking(move || { |
| 5313 | let repo = handle.repository_readonly()?; |
| 5314 | // Resolve the target: the raw CLI string (URN / prefix / full |
| 5315 | // base32), else the request's exact hash. |
| 5316 | let change_hash = match &target { |
| 5317 | Some(target) => resolve_provenance_target(&repo, target)?, |
| 5318 | None => exact.ok_or_else(|| { |
| 5319 | domain_status(ErrorCode::InvalidArgument, "change target required") |
| 5320 | })?, |
| 5321 | }; |
| 5322 | // The graphs that explain the change, newest first (the CLI's |
| 5323 | // load_graphs: REV_DEPS first, disk-scan fallback, error when |
| 5324 | // nothing explains it). |
| 5325 | let mut graphs = repo |
| 5326 | .find_provenance_for_change(&change_hash) |
| 5327 | .map_err(repository_error)?; |
| 5328 | if graphs.is_empty() { |
| 5329 | graphs = repo |
| 5330 | .find_provenance_for_change_scan(&change_hash) |
| 5331 | .map_err(repository_error)?; |
| 5332 | } |
| 5333 | if graphs.is_empty() { |
| 5334 | return Err(domain_status( |
| 5335 | ErrorCode::InvalidArgument, |
| 5336 | format!( |
| 5337 | "no provenance graph explains change {}", |
| 5338 | change_hash.to_base32() |
| 5339 | ), |
| 5340 | )); |
| 5341 | } |
| 5342 | graphs.sort_by_key(|(_, graph)| { |
| 5343 | std::cmp::Reverse(atomic_core::types::timestamp::epoch_millis(graph.timestamp)) |
| 5344 | }); |
| 5345 | let mut bundles = Vec::with_capacity(graphs.len()); |
| 5346 | for (graph_hash, graph) in &graphs { |
| 5347 | let (input, previous) = provenance_map_input(&repo, graph, &change_hash, &person_did); |
| 5348 | // The prior-turn walk the trace render performs (≤64 hops; an |
| 5349 | // unloadable graph ends the chain with the empty marker, the |
| 5350 | // cap sets the truncated flag — the local render's two |
no test coverage detected