"""Tests for CLI client auth helpers."""

from __future__ import annotations

from unittest.mock import patch


def test_get_authenticated_client_uses_env_token(monkeypatch):
    """TERMINALUSE_API_KEY should allow non-interactive CLI usage (no `tu login`)."""
    monkeypatch.setenv("TERMINALUSE_API_KEY", "sk_tu_test_token_123")

    from terminaluse.lib.cli.utils import client as client_utils

    with patch.object(client_utils, "get_stored_token", side_effect=AssertionError("should not read stored creds")):
        with patch.object(client_utils, "TerminalUse") as mock_client:
            client_utils.get_authenticated_client()

            mock_client.assert_called_once()
            _, kwargs = mock_client.call_args
            assert kwargs["token"] == "sk_tu_test_token_123"
            assert kwargs["auto_refresh_token"] is False
