Skip to main content

lsp_max/runtime/
mod.rs

1//! Runtime utilities for lsp-max servers.
2//!
3//! Provides SHA-256 hashing, the `ConformanceVector` (Admitted/Refused/Unknown
4//! tallies), and the `MaxServer` wrapper that wires a `LanguageServer` impl into
5//! the five-layer AMI execution model used by lsp-max.
6
7pub mod ledger;
8pub mod mesh;
9pub mod mesh_hooks;
10pub mod mesh_types;
11pub mod rpc;
12pub mod sha256;
13pub mod typestate;
14
15pub use mesh::{build_conformance_vector, AutonomicMesh, MaxMesh};
16pub use mesh_hooks::{
17    CustomerRequestClassifierHook, IntakeClearHook, IntakeDiagnosticHook, OcelProcessHook,
18    PolicyEvaluationHook, ReceiptRoutingHook,
19};
20pub use mesh_types::{
21    AutonomicMeshState, ConformanceDeltaEntry, ConformanceGrade, FailureMode, Hook, HookDescriptor,
22    HookEvent, InstanceId, LspInstance, LspPhase, MaxDiagnostic, MaxMethod, MeshAction,
23    PolicyState, Receipt,
24};
25pub use sha256::{sha256, validate_and_reconstruct_chain_checked};
26pub use typestate::{
27    AccessAdmissionLaw, ChainError, Data, DeterministicSnapshot, EmptyData, Exited, Initialized,
28    InitializedData, Initializing, InitializingData, Law, Machine, Phase, ShutDown,
29    TypestateKernel, Uninitialized,
30};
31
32pub mod control_plane;
33pub use control_plane::replay;
34pub use control_plane::views;
35
36#[cfg(test)]
37mod hook_descriptor_tests {
38    use super::*;
39
40    #[test]
41    fn all_hooks_have_non_empty_descriptors() {
42        let mut mesh = AutonomicMesh::new();
43        mesh.register_hook(Box::new(mesh_hooks::IntakeDiagnosticHook));
44        mesh.register_hook(Box::new(mesh_hooks::IntakeClearHook));
45        mesh.register_hook(Box::new(mesh_hooks::CustomerRequestClassifierHook::new()));
46        mesh.register_hook(Box::new(mesh_hooks::PolicyEvaluationHook::new()));
47        mesh.register_hook(Box::new(mesh_hooks::ReceiptRoutingHook::new()));
48        mesh.register_hook(Box::new(mesh_hooks::OcelProcessHook::new()));
49
50        let descriptors = mesh.hook_descriptors();
51        assert_eq!(descriptors.len(), 6, "expected exactly 6 registered hooks");
52
53        for d in &descriptors {
54            assert!(!d.name.is_empty(), "hook name must not be empty");
55            assert!(
56                !d.input_type.is_empty(),
57                "input_type must not be empty for {}",
58                d.name
59            );
60            assert!(
61                !d.output_type.is_empty(),
62                "output_type must not be empty for {}",
63                d.name
64            );
65            assert!(
66                !d.trigger_law.is_empty(),
67                "trigger_law must not be empty for {}",
68                d.name
69            );
70        }
71    }
72
73    #[test]
74    fn hook_names_match_struct_names() {
75        let hooks: Vec<Box<dyn mesh_types::Hook>> = vec![
76            Box::new(mesh_hooks::IntakeDiagnosticHook),
77            Box::new(mesh_hooks::IntakeClearHook),
78            Box::new(mesh_hooks::CustomerRequestClassifierHook::new()),
79            Box::new(mesh_hooks::PolicyEvaluationHook::new()),
80            Box::new(mesh_hooks::ReceiptRoutingHook::new()),
81            Box::new(mesh_hooks::OcelProcessHook::new()),
82        ];
83        let expected_names = [
84            "IntakeDiagnosticHook",
85            "IntakeClearHook",
86            "CustomerRequestClassifierHook",
87            "PolicyEvaluationHook",
88            "ReceiptRoutingHook",
89            "OcelProcessHook",
90        ];
91        for (hook, expected) in hooks.iter().zip(expected_names.iter()) {
92            assert_eq!(hook.name(), *expected);
93            assert_eq!(hook.descriptor().name, *expected);
94        }
95    }
96}