1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Edge provenance classes.
use serde::{Deserialize, Serialize};
/// How an edge or node in the graph was produced.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Provenance {
/// Deterministically extracted from source ASTs (tree-sitter). The default:
/// the overwhelmingly common node/edge, and the correct value when a legacy
/// cached fact set (serialized before nodes carried provenance) omits it.
#[default]
Derived,
/// Authored by a human or agent in an ADR, blueprint, or annotation.
Authored,
/// Heuristically inferred (docs, embeddings); carries a confidence score.
Inferred,
}
impl Provenance {
/// Parse a provenance from its stable string token, returning `None` for an
/// unrecognised value (e.g. a corrupt database row).
#[must_use]
pub fn from_token(s: &str) -> Option<Self> {
match s {
"derived" => Some(Self::Derived),
"authored" => Some(Self::Authored),
"inferred" => Some(Self::Inferred),
_ => None,
}
}
/// Stable string form used in the `SQLite` store.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Derived => "derived",
Self::Authored => "authored",
Self::Inferred => "inferred",
}
}
}
#[cfg(test)]
mod tests {
use super::Provenance;
#[test]
fn stable_string_forms() {
assert_eq!(Provenance::Derived.as_str(), "derived");
assert_eq!(Provenance::Authored.as_str(), "authored");
assert_eq!(Provenance::Inferred.as_str(), "inferred");
}
#[test]
fn from_token_round_trips_and_rejects_unknown() {
for p in [
Provenance::Derived,
Provenance::Authored,
Provenance::Inferred,
] {
assert_eq!(Provenance::from_token(p.as_str()), Some(p));
}
assert_eq!(Provenance::from_token("bogus"), None);
}
}