Skip to main content

oris_kernel/kernel/
stubs.rs

1//! Stub implementations for building a Kernel (e.g. for replay-only tests).
2//! Replay does not call ActionExecutor or StepFn; policy is used only when running.
3
4use crate::kernel::action::{Action, ActionExecutor, ActionResult};
5use crate::kernel::identity::RunId;
6use crate::kernel::policy::{Policy, PolicyCtx};
7use crate::kernel::state::KernelState;
8use crate::kernel::step::{Next, StepFn};
9use crate::kernel::KernelError;
10
11/// Action executor that never runs (for replay-only Kernel).
12pub struct NoopActionExecutor;
13
14impl ActionExecutor for NoopActionExecutor {
15    fn execute(&self, _run_id: &RunId, _action: &Action) -> Result<ActionResult, KernelError> {
16        Err(KernelError::Driver(
17            "action execution not used in replay".into(),
18        ))
19    }
20}
21
22/// Step function that always completes immediately (for replay-only Kernel).
23pub struct NoopStepFn;
24
25impl<S: KernelState> StepFn<S> for NoopStepFn {
26    fn next(&self, _state: &S) -> Result<Next, KernelError> {
27        Ok(Next::Complete)
28    }
29}
30
31/// Policy that allows all actions (for replay-only Kernel).
32pub struct AllowAllPolicy;
33
34impl Policy for AllowAllPolicy {
35    fn authorize(
36        &self,
37        _run_id: &RunId,
38        _action: &Action,
39        _ctx: &PolicyCtx,
40    ) -> Result<(), KernelError> {
41        Ok(())
42    }
43}