pub fn select(ctx: &Context, graph: &Graph, req: &Request<'_>) -> SelectionExpand description
Reach every candidate the request implies: the seeds, the graph around them, the paths they declare, the governance the layer applies, the session that ran before, and — when the request gave an intent — what its words match.
Nothing is read here. graph is crate::graph::COMPOSED already derived over the
index, so every typed reference the layer declares is an edge before this function
starts, and the walk is over two values the process is holding. That is what lets a
request be answered inside a handler rather than at load time.
It returns a Selection and never an error: an intent that matches nothing, a seed
whose scope is empty, a reference the layer declares and nothing answers — each of those
is a fact about the repository, carried in unresolved or diagnostics, and not a
failure of the call.
The governance selector is why a request that names nothing still gets an answer: the policy and the scope apply to everything, so they are reached without a seed.
use std::collections::BTreeSet;
use majordomus_cli::devcontext::select::{select, Request};
use majordomus_cli::devcontext::{DEFAULT_FLOOR, DEFAULT_MAX_DEPTH};
use majordomus_cli::graph;
use majordomus_cli::synthetic::SyntheticRepository;
let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let composed = graph::composed_complete(&ctx.registry, ctx.index.as_ref());
// a request that names nothing at all
let empty = Request {
seeds: Vec::new(),
paths: BTreeSet::new(),
terms: BTreeSet::new(),
max_depth: DEFAULT_MAX_DEPTH,
floor: DEFAULT_FLOOR,
all_blocking_rules: false,
branch: None,
};
let selection = select(&ctx, &composed, &empty);
// it still reaches the governance, because the governance applies without being asked for
assert!(
selection.candidates.values().any(|c| c.kind == "policy"),
"a request that names nothing still gets what every session is held to",
);
// and every candidate carries at least one recorded way in: nothing is in the
// selection without something that says how it got there
for c in selection.candidates.values() {
assert!(!c.discovered_by.is_empty(), "{} arrived unexplained", c.uri);
assert!(c.confidence() > 0.0, "{} is vouched for by nothing", c.uri);
}