Skip to main content

Situation

Struct Situation 

Source
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: AdvisorCatalogue

The advisor catalogue.

§refs: References

What it references.

§mode: ModeResolution

The mode in force.

§states: Vec<AdvisorState>

Every advisor’s standing now.

§store: Store

The record store.

§loaded: Loaded

Its records.

§diagnostics: Vec<String>

The catalogue’s own findings.

Implementations§

Source§

impl Situation

Source

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());
Source

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));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more