b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
"""Tests for Anthropic OAuth setup flow behavior."""
|
|
|
|
from hermes_cli.config import load_env, save_env_value
|
|
|
|
|
|
def test_run_anthropic_oauth_flow_prefers_claude_code_credentials(tmp_path, monkeypatch, capsys):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
monkeypatch.setattr(
|
|
"agent.anthropic_adapter.run_oauth_setup_token",
|
|
lambda: "sk-ant-oat01-from-claude-setup",
|
|
)
|
|
monkeypatch.setattr(
|
|
"agent.anthropic_adapter.read_claude_code_credentials",
|
|
lambda: {
|
|
"accessToken": "cc-access-token",
|
|
"refreshToken": "cc-refresh-token",
|
|
"expiresAt": 9999999999999,
|
|
},
|
|
)
|
|
monkeypatch.setattr(
|
|
"agent.anthropic_adapter.is_claude_code_token_valid",
|
|
lambda creds: True,
|
|
)
|
|
|
|
from hermes_cli.main import _run_anthropic_oauth_flow
|
|
|
|
save_env_value("ANTHROPIC_TOKEN", "stale-env-token")
|
|
assert _run_anthropic_oauth_flow(save_env_value) is True
|
|
|
|
env_vars = load_env()
|
|
assert env_vars["ANTHROPIC_TOKEN"] == ""
|
|
assert env_vars["ANTHROPIC_API_KEY"] == ""
|
|
output = capsys.readouterr().out
|
|
assert "Claude Code credentials linked" in output
|
|
|
|
|
|
def test_run_anthropic_oauth_flow_manual_token_still_persists(tmp_path, monkeypatch, capsys):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
monkeypatch.setattr("agent.anthropic_adapter.run_oauth_setup_token", lambda: None)
|
|
monkeypatch.setattr("agent.anthropic_adapter.read_claude_code_credentials", lambda: None)
|
|
monkeypatch.setattr("agent.anthropic_adapter.is_claude_code_token_valid", lambda creds: False)
|
|
monkeypatch.setattr("builtins.input", lambda _prompt="": "sk-ant-oat01-manual-token")
|
|
monkeypatch.setattr(
|
|
"hermes_cli.secret_prompt.masked_secret_prompt",
|
|
lambda _prompt="": "sk-ant-oat01-manual-token",
|
|
)
|
|
|
|
from hermes_cli.main import _run_anthropic_oauth_flow
|
|
|
|
assert _run_anthropic_oauth_flow(save_env_value) is True
|
|
|
|
env_vars = load_env()
|
|
assert env_vars["ANTHROPIC_TOKEN"] == "sk-ant-oat01-manual-token"
|
|
output = capsys.readouterr().out
|
|
assert "Setup-token saved" in output
|