//! Invariant: the inject_file tool must reject file paths that escape CWD.
//!
//! An AI agent must not be able to load mappings from arbitrary locations
//! on the host by supplying a `../`-prefixed or absolute file path.

#[tokio::test]
async fn rejects_dotdot_path_in_inject_file() {
    let result = envseal_mcp::tools::inject_file::execute(
        envseal_mcp::tools::inject_file::InjectFileParams {
            file: "../../etc/hosts".to_string(),
            command: vec!["/bin/echo".to_string(), "ok".to_string()],
        },
    )
    .await;

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

#[tokio::test]
async fn rejects_absolute_outside_cwd_in_inject_file() {
    let result = envseal_mcp::tools::inject_file::execute(
        envseal_mcp::tools::inject_file::InjectFileParams {
            file: "/etc/hosts".to_string(),
            command: vec!["/bin/echo".to_string(), "ok".to_string()],
        },
    )
    .await;

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