//! Invariant: the import tool must reject env_file paths that escape CWD.
//!
//! An AI agent must not be able to read (or write adjacent to) arbitrary
//! files on the host by supplying a `../`-prefixed env_file path.

#[tokio::test]
async fn rejects_dotdot_path_in_import_env_file() {
    let result = envseal_mcp::tools::import::execute(envseal_mcp::tools::import::ImportParams {
        env_file: "../../etc/passwd".to_string(),
        delete_after: false,
    })
    .await;

    let err = result.expect_err("expected path traversal to be rejected");
    assert!(
        err.contains("must not escape the working directory"),
        "Fix: import env_file must reject traversal paths, got: {err}"
    );
}

#[tokio::test]
async fn rejects_absolute_outside_cwd_in_import_env_file() {
    let result = envseal_mcp::tools::import::execute(envseal_mcp::tools::import::ImportParams {
        env_file: "/etc/passwd".to_string(),
        delete_after: false,
    })
    .await;

    let err = result.expect_err("expected absolute path outside CWD to be rejected");
    assert!(
        err.contains("must not escape the working directory"),
        "Fix: import env_file must reject absolute paths outside CWD, got: {err}"
    );
}
