//! Invariant: when `ENVSEAL_MCP_DISABLE_IMPORT` is set, `envseal_import` is refused
//! so the MCP layer cannot be used to bulk-ingest a `.env` from agent-chosen paths.

use std::sync::Mutex;

static ENV_LOCK: Mutex<()> = Mutex::new(());

#[test]
fn import_returns_error_when_disabled() {
    let _guard = ENV_LOCK
        .lock()
        .expect("serialize env var tests; env is process-global");

    std::env::set_var("ENVSEAL_MCP_DISABLE_IMPORT", "1");
    let runtime = tokio::runtime::Runtime::new().expect("create tokio runtime");
    let result = runtime.block_on(envseal_mcp::tools::import::execute(
        envseal_mcp::tools::import::ImportParams {
            env_file: ".env".to_string(),
            delete_after: false,
        },
    ));

    std::env::remove_var("ENVSEAL_MCP_DISABLE_IMPORT");

    let err = result.expect_err("envseal_import should be disabled");
    assert_eq!(
        err,
        envseal_mcp::settings::IMPORT_DISABLED_MESSAGE,
        "must match IMPORT_DISABLED_MESSAGE for operators and tests"
    );
}
