vc-runtime 0.1.0

Runtime backend for Visual Compiler
Documentation
//! Tests for the TOML configuration loader.

use crate::config::loader::load_config;
use std::io::Write;
use tempfile::NamedTempFile;

fn write_toml(content: &str) -> NamedTempFile {
    let mut file = NamedTempFile::new().unwrap();
    file.write_all(content.as_bytes()).unwrap();
    file
}

#[test]
fn valid_config_loads() {
    let toml = r#"
[global]
log_level = "info"

[profiles.local]
backend_name = "comfy"

[backends.comfy]
enabled = true

[backends.comfy.options]
kind = "comfyui"

[backends.comfy.options.options]
base_url = "http://127.0.0.1:8188/"
timeout_secs = 30
poll_timeout_secs = 300
poll_interval_ms = 500
workflow_template_path = "workflow.json"
"#;
    let file = write_toml(toml);
    let config = load_config(file.path()).unwrap();

    assert_eq!(config.global.log_level, Some("info".to_string()));
    assert_eq!(config.profiles.len(), 1);
    assert_eq!(config.backends.len(), 1);
}

#[test]
fn invalid_toml_fails() {
    let toml = "this is not valid toml [";
    let file = write_toml(toml);
    let result = load_config(file.path());
    assert!(result.is_err());
}

#[test]
fn semantic_validation_fails() {
    let toml = r#"
[profiles.local]
backend_name = "missing"

[backends.comfy]
enabled = true

[backends.comfy.options]
kind = "comfyui"

[backends.comfy.options.options]
base_url = "http://127.0.0.1:8188/"
timeout_secs = 30
poll_timeout_secs = 300
poll_interval_ms = 500
workflow_template_path = "workflow.json"
"#;
    let file = write_toml(toml);
    let result = load_config(file.path());
    assert!(result.is_err());
}

#[test]
fn missing_file_returns_error() {
    let result = load_config("this-file-does-not-exist.toml");
    assert!(result.is_err());
}