pub struct Situation {
pub catalogue: AdvisorCatalogue,
pub refs: References,
pub mode: ModeResolution,
pub states: Vec<AdvisorState>,
pub store: Store,
pub loaded: Loaded,
pub diagnostics: Vec<String>,
}Expand description
Everything reasoning reads about this checkout, resolved once: the catalogue and the references it resolves against, the mode, every advisor’s standing and the records. Each surface — the capabilities, the environment snapshot — starts here, so none of them derives availability a second way.
use majordomus_cli::reasoning::Situation;
use majordomus_cli::share::ProviderDeclarations;
// no share: no catalogue, no advisor, and still a situation to reason in
let root = tempfile::tempdir().unwrap();
let s = Situation::resolve(root.path(), None, &ProviderDeclarations::default(), &[]).unwrap();
assert!(s.catalogue.advisors.is_empty() && s.states.is_empty());
assert!(s.diagnostics.is_empty());
assert_eq!(s.available(), 0);Fields§
§catalogue: AdvisorCatalogueThe advisor catalogue.
refs: ReferencesWhat it references.
mode: ModeResolutionThe mode in force.
states: Vec<AdvisorState>Every advisor’s standing now.
store: StoreThe record store.
loaded: LoadedIts records.
diagnostics: Vec<String>The catalogue’s own findings.
Implementations§
Source§impl Situation
impl Situation
Sourcepub fn resolve(
root: &Path,
share: Option<&Path>,
providers: &ProviderDeclarations,
peers: &[LinkedPeer],
) -> Result<Self, String>
pub fn resolve( root: &Path, share: Option<&Path>, providers: &ProviderDeclarations, peers: &[LinkedPeer], ) -> Result<Self, String>
Resolve the situation of the checkout at root: no network, no model, no build.
The catalogue comes from share (none without one), the mode from the environment,
a CI runner or the open task’s profile, availability from presence, the disable
list, the recorded consultations and the linked peers. Only a catalogue that
cannot be read is an error.
use majordomus_cli::reasoning::{ReasoningMode, Situation};
use majordomus_cli::share::ProviderDeclarations;
std::env::set_var("MAJORDOMUS_REASONING_MODE", "offline");
let root = tempfile::tempdir().unwrap();
let s = Situation::resolve(root.path(), None, &ProviderDeclarations::default(), &[]).unwrap();
assert_eq!(s.mode.mode, ReasoningMode::Offline);
assert_eq!(s.mode.source, "MAJORDOMUS_REASONING_MODE");
let share = tempfile::tempdir().unwrap();
std::fs::write(share.path().join("advisors.yaml"), "version: one\n").unwrap();
let refused = Situation::resolve(root.path(), Some(share.path()), &ProviderDeclarations::default(), &[]);
assert!(refused.is_err());Sourcepub fn available(&self) -> usize
pub fn available(&self) -> usize
How many advisors may be asked now: those whose status is available, whatever
the number declared. Zero is an ordinary answer.
use majordomus_cli::reasoning::availability::LinkedPeer;
use majordomus_cli::reasoning::Situation;
use majordomus_cli::share::ProviderDeclarations;
std::env::set_var("MAJORDOMUS_REASONING_MODE", "ci");
let root = tempfile::tempdir().unwrap();
let share = tempfile::tempdir().unwrap();
std::fs::write(
share.path().join("advisors.yaml"),
"version: 1\ncapabilities:\n - id: code_review\n description: x\npeers:\n feature: reviews\n adapter: mesh-review\n capabilities: [code_review]\n",
).unwrap();
let peer = LinkedPeer { runtime: "n1-r1".into(), name: "one".into(), features: vec!["reviews".into()] };
let s = Situation::resolve(root.path(), Some(share.path()), &ProviderDeclarations::default(), &[peer]).unwrap();
// mode ci admits no advisor, linked or not
assert_eq!((s.states.len(), s.available()), (1, 0));