Skip to main content

katana_canvas_forge/renderer/
runtime_path.rs

1use super::api::{DiagramKind, RenderError};
2use crate::markdown::{drawio_renderer::DrawioRendererOps, mermaid_renderer::MermaidBinaryOps};
3use std::path::PathBuf;
4
5pub struct RuntimePathResolver;
6
7impl RuntimePathResolver {
8    pub fn resolve(
9        kind: DiagramKind,
10        runtime_path: Option<PathBuf>,
11    ) -> Result<PathBuf, RenderError> {
12        if let Some(path) = runtime_path {
13            return Ok(path);
14        }
15        match kind {
16            DiagramKind::Mermaid => MermaidBinaryOps::resolve_mermaid_js(),
17            DiagramKind::Drawio => DrawioRendererOps::resolve_drawio_js(),
18        }
19        .map_err(RenderError::RuntimeResolution)
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::RuntimePathResolver;
26    use crate::renderer::api::DiagramKind;
27    use std::path::PathBuf;
28
29    #[test]
30    fn explicit_runtime_path_wins_at_surface_boundary() -> Result<(), Box<dyn std::error::Error>> {
31        let path = PathBuf::from("/tmp/runtime.js");
32        let resolved = RuntimePathResolver::resolve(DiagramKind::Mermaid, Some(path.clone()))?;
33
34        assert_eq!(resolved, path);
35        Ok(())
36    }
37}