Skip to main content

drft/rules/
mod.rs

1//! v0.8 rules over the composed graph: staleness (drift vs the lockfile) and
2//! structural findings, orchestrated by [`check`].
3
4pub mod check;
5pub mod staleness;
6pub mod structural;
7
8use crate::model::{Edge, Metadata, PROVENANCE_KEY};
9
10/// A hash truncated for display in findings: the `b3:` prefix plus the first 10
11/// hex chars. Comparisons always use the full hash; this is cosmetic.
12pub(crate) fn short_hash(hash: &str) -> &str {
13    &hash[..hash.len().min(13)]
14}
15
16/// The `_graphs` provenance list from a node's or edge's metadata.
17pub(crate) fn provenance(metadata: &Metadata) -> Vec<String> {
18    metadata
19        .get(PROVENANCE_KEY)
20        .and_then(|v| v.as_array())
21        .map(|entries| {
22            entries
23                .iter()
24                .filter_map(|e| e.as_str().map(String::from))
25                .collect()
26        })
27        .unwrap_or_default()
28}
29
30/// The `_graphs` provenance list for an edge.
31pub(crate) fn edge_provenance(edge: &Edge) -> Vec<String> {
32    provenance(&edge.metadata)
33}