Skip to main content

cellos_host_stub/
lib.rs

1//! In-memory stub for [`cellos_core::ports::CellBackend`] — no real isolation.
2
3use async_trait::async_trait;
4use tracing::instrument;
5
6use cellos_core::ports::{CellBackend, CellHandle, TeardownReport};
7use cellos_core::{CellosError, ExecutionCellDocument};
8
9/// Stub backend: always reports successful create/destroy (for wiring tests only).
10pub struct StubCellBackend;
11
12#[async_trait]
13impl CellBackend for StubCellBackend {
14    #[instrument(skip(self, spec))]
15    async fn create(&self, spec: &ExecutionCellDocument) -> Result<CellHandle, CellosError> {
16        if spec.spec.id.is_empty() {
17            return Err(CellosError::InvalidSpec("spec.id must be non-empty".into()));
18        }
19        Ok(CellHandle {
20            cell_id: spec.spec.id.clone(),
21            cgroup_path: None,
22            // Stub backend does not manage network enforcement; the supervisor's
23            // host-subprocess path surfaces the signal via `run_cell_command`.
24            nft_rules_applied: None,
25            // FC-08: stub backend has no boot artifact manifest.
26            kernel_digest_sha256: None,
27            rootfs_digest_sha256: None,
28            firecracker_digest_sha256: None,
29        })
30    }
31
32    #[instrument(skip(self, handle))]
33    async fn destroy(&self, handle: &CellHandle) -> Result<TeardownReport, CellosError> {
34        Ok(TeardownReport {
35            cell_id: handle.cell_id.clone(),
36            destroyed: true,
37            peers_tracked_after: 0,
38        })
39    }
40}