Skip to main content

xtalforge_modules/
stub.rs

1//! Test stub module (Task 5.10.5).
2//!
3//! A module that does nothing, so the registry, the parameter forms of front
4//! ends, cancellation and run folders can be exercised without a real
5//! calculation.
6
7use serde_json::json;
8use xtalforge_core::Error;
9
10use crate::registry::{Module, ModuleInfo};
11
12/// The stub module implementation.
13#[derive(Debug, Clone, Copy, Default)]
14pub struct TestModule;
15
16impl Module for TestModule {
17    fn info(&self) -> ModuleInfo {
18        ModuleInfo {
19            name: "test".to_owned(),
20            description: "Stub module that reports availability and does nothing.".to_owned(),
21            version: env!("CARGO_PKG_VERSION").to_owned(),
22            parameters: Vec::new(),
23        }
24    }
25
26    fn available(&self) -> bool {
27        true
28    }
29
30    fn run(&self, _parameters: &serde_json::Value) -> Result<serde_json::Value, Error> {
31        Ok(json!({
32            "ok": true,
33            "module": "test",
34            "message": "test module ran",
35        }))
36    }
37}
38
39/// Creates the stub module for registration and surface tests.
40#[must_use]
41pub fn test_module() -> Box<dyn Module> {
42    Box::new(TestModule)
43}