use std::fs;
use std::path::PathBuf;

#[test]
fn scene_generator_server_files_exist() {
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let server_js = manifest_dir
        .join("frontend")
        .join("scene-generator")
        .join("server.js");
    let config_loader = manifest_dir
        .join("frontend")
        .join("scene-generator")
        .join("config-loader.js");

    assert!(
        server_js.exists(),
        "server.js not found at {:?}",
        server_js
    );
    assert!(
        config_loader.exists(),
        "config-loader.js not found at {:?}",
        config_loader
    );
}

#[test]
fn sgclaw_config_is_readable() {
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let config_path = manifest_dir.join("sgclaw_config.json");
    let content = fs::read_to_string(&config_path)
        .unwrap_or_else(|err| panic!("sgclaw_config.json not found: {}", err));
    let parsed: serde_json::Value =
        serde_json::from_str(&content).expect("should be valid JSON");
    assert!(parsed.get("apiKey").is_some(), "missing apiKey");
    assert!(parsed.get("baseUrl").is_some(), "missing baseUrl");
    assert!(parsed.get("model").is_some(), "missing model");
}
