pub struct Selection {
pub candidates: BTreeMap<String, Candidate>,
pub unresolved: Vec<(String, String)>,
pub diagnostics: Vec<Diagnostic>,
}Expand description
The candidates a request reaches, and everything the walk learned on the way.
Keyed by canonical identifier, which is what makes structural deduplication a property
of the type rather than a step: one identifier cannot be in here twice, so the question
“was this reached more than once” is answered by a candidate’s discovered_by and never
by scanning for duplicates.
The other two fields are what the walk could not do, and neither is an error.
unresolved is a name the layer declares and this repository holds nothing under — a
dangling reference, which is a fact about the repository worth reporting. diagnostics
is what could not be read. The budget turns both into rows of the answer rather than
swallowing them.
use std::collections::BTreeMap;
use majordomus_cli::devcontext::select::{Candidate, Selection};
use majordomus_cli::devcontext::{Discovery, Selector, Tier};
let uri = "majordomus://adr/0052";
let candidate = Candidate {
uri: uri.into(),
kind: "adr".into(),
title: None,
tier: Tier::Decision,
relevance: 0.8,
depth: 1,
discovered_by: vec![Discovery {
selector: Selector::Relation,
reason: "the decision in force over this scope".into(),
via: Some("majordomus://issue/I0301".into()),
edge: Some("governed_by".into()),
depth: 1,
confidence: 1.0,
weight: 0.9,
}],
object: None,
path: None,
status: None,
facts: BTreeMap::new(),
};
let selection = Selection {
candidates: BTreeMap::from([(uri.to_string(), candidate)]),
// a reference the layer declares and nothing answers: reported, not dropped
unresolved: vec![("majordomus://rule/gone@1".into(), "depends_on".into())],
diagnostics: Vec::new(),
};
// the identifier is the key, so one thing is one entry however many paths found it
assert_eq!(selection.candidates.len(), 1);
assert_eq!(selection.candidates[uri].discovered_by.len(), 1);
assert!(selection.candidates.contains_key(uri));
// and a dangling reference survives to be reported as one
assert_eq!(selection.unresolved[0].0, "majordomus://rule/gone@1");Fields§
§candidates: BTreeMap<String, Candidate>By canonical identifier.
unresolved: Vec<(String, String)>Names the layer declares that resolve to nothing this repository holds.
diagnostics: Vec<Diagnostic>What could not be read, never an error.