Skip to main content

doctor_at

Function doctor_at 

Source
pub fn doctor_at(
    declaration: Option<Result<MeshConfig, MeshError>>,
    root: Option<&Path>,
    runtime: Option<&MeshStatus>,
) -> MeshDoctorReport
Expand description

doctor for the repository at root, in the process whose mesh runtime decided runtime: adds whether the repository has a mesh identity cooperation can match on, and judges what the runtime decided about the declaration.

Discovery works without a repository identity — two nodes can hear each other while belonging to different repositories — but a link does not, so a report that omits this check can say every prerequisite holds while cooperation is unreachable. root is optional because the caller may have no repository at hand, and then the check is not run rather than failed.

runtime is the status of a runtime a shared server decided on — activated, or declined with a reason — and None in any process no server runs in (MeshRuntime::decided). The runtime check fails exactly when the declaration is enabled and a server’s mesh is not active.

use majordomus_cli::mesh::doctor::doctor_at;
use majordomus_cli::mesh::manager::MeshRuntime;
use majordomus_cli::mesh::MeshConfig;

// a directory holding no history has no identity to match on, and the check says so
let nowhere = tempfile::tempdir().unwrap();
let report = doctor_at(None, Some(nowhere.path()), None);
let repository = report.checks.iter().find(|c| c.check == "repository").unwrap();
assert!(!repository.ok);
assert!(repository.remediation.as_deref().unwrap().contains("cooperation.repository"));

// with no root to ask about, the question is not asked at all
assert!(doctor_at(None, None, None).checks.iter().all(|c| c.check != "repository"));

// an enabled declaration a server declined is the runtime's failure, with the reason
let enabled: MeshConfig = serde_json::from_value(serde_json::json!({
    "schema": "mesh/v1", "kind": "mesh-declaration", "id": "doc", "enabled": true,
})).unwrap();
let server = MeshRuntime::new();
server.decline("the node identity did not load");
let report = doctor_at(Some(Ok(enabled)), None, Some(&server.status()));
let runtime = report.checks.iter().find(|c| c.check == "runtime").unwrap();
assert!(!runtime.ok && !report.ok);
assert!(runtime.detail.ends_with("the node identity did not load"));