#[test]
fn vendored_openapi_spec_exists_inside_crate() {
    let spec = include_str!("../openapi/openapi.yaml");
    assert!(spec.contains("openapi: 3."));
    assert!(spec.contains("/api/v1/auth/challenge"));
}

/// The vendored spec is resynced from the canonical generated spec by
/// `openapi-postprocess`'s `sync-rust-sdk-spec` binary (see `make docs-gen`).
/// These assertions fail if the vendored copy drifts back to its old, narrow,
/// pre-resync shape — a backstop in addition to the CI drift gate.
#[test]
fn vendored_spec_includes_margin_and_perp_surface() {
    let spec = include_str!("../openapi/openapi.yaml");
    // Operations that only exist post-resync (were absent from the old vendored
    // spec, which lacked the entire margin-accounts + perp/market surface).
    for op in [
        "operationId: list_margin_accounts",
        "operationId: get_perp_market_summary",
        "operationId: list_positions",
        "operationId: get_funding_state",
        "operationId: reduce_position_margin",
    ] {
        assert!(spec.contains(op), "vendored spec is missing `{op}`");
    }
}

#[test]
fn vendored_spec_has_no_fallback_operation_ids() {
    let spec = include_str!("../openapi/openapi.yaml");
    // Clean operationIds are all-lowercase snake_case; a `Service_Method`
    // fallback would leak an uppercase letter into the line.
    for line in spec.lines() {
        let trimmed = line.trim_start();
        if let Some(id) = trimmed.strip_prefix("operationId: ") {
            assert!(
                !id.chars().any(|c| c.is_ascii_uppercase()),
                "vendored spec has a non-snake_case operationId: `{id}`"
            );
        }
    }
}

#[test]
fn vendored_spec_uses_refresh_session_not_refresh_token() {
    // The JWT-era `refresh_token` operation was repurposed into the session-key
    // `refresh_session` endpoint (same path) during the v0.8.8 auth cutover.
    let spec = include_str!("../openapi/openapi.yaml");
    assert!(spec.contains("operationId: refresh_session"));
    assert!(!spec.contains("operationId: refresh_token"));
}

#[test]
fn cargo_toml_uses_tls_enabled_reqwest() {
    let manifest = include_str!("../Cargo.toml");
    assert!(manifest.contains("reqwest = { version = \"0.13\""));
    assert!(manifest.contains("\"rustls\""));
}

#[test]
fn readme_authenticated_example_includes_chain_id_fields() {
    let readme = include_str!("../README.md");
    assert!(readme.contains("chain_id: None"));
}
