mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 03:54:08 +00:00
Reverts 93889b770d ("named profiles no longer inherit the root
profile's auth.json"). After the Desktop update every bot profile that had
relied on the root OpenAI Codex login failed with "No Codex credentials
stored. Run `hermes -p <bot> auth add openai-codex --type oauth`", and users
had to re-run the device-code flow once per bot (5-6 times in the field
report). Sharing one grant across profiles is the intended design: OAuth
refresh tokens are single-use, so ONE grant lives at the root, profiles
resolve it read-only, and a refresh under a profile writes the rotated chain
back to root (Codex / xAI write-through, borrowed-row pool bookkeeping,
forked-grant heal) — never a per-profile copy.
Restored: `_global_auth_file_path` / `_load_global_auth_store` fallback in
`_load_provider_state*` / `read_credential_pool` / `_provider_state_transaction`,
Codex + xAI root write-through, `credential_pool` borrowed-root persistence,
`heal_forked_single_use_oauth_grants`, `share_auth` on profile creation
(Desktop create dialog checkbox), and the docs. `profile_credential_audit.py`
(the `hermes update` "profiles without a provider" notice) is removed with it.
Kept from after #111724: `_save_codex_tokens(set_active=...)` for image gen,
the plugin-auth `status` dispatch and the external-login notice in
`hermes auth list`, and the registry-derived env-var hint in agent_init.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""Regression tests for xAI OAuth auth resolution in profile/cron contexts."""
|
|
|
|
import pytest
|
|
|
|
from hermes_cli import auth
|
|
from hermes_cli.auth import AuthError
|
|
|
|
|
|
def test_read_xai_oauth_tokens_uses_credential_pool_when_provider_tokens_empty(monkeypatch):
|
|
"""Profile auth can have fresh pool tokens while singleton provider state is empty.
|
|
|
|
This mirrors profiled cron after re-auth/credential-pool sync: the xAI
|
|
OAuth credential is usable, but `providers.xai-oauth.tokens` may be empty
|
|
or stale. Treating that as missing auth makes cron keep failing after the
|
|
user has successfully re-authenticated.
|
|
"""
|
|
store = {
|
|
"providers": {"xai-oauth": {"tokens": {}, "last_auth_error": {}}},
|
|
"credential_pool": {
|
|
"xai-oauth": [
|
|
{
|
|
"access_token": "pool-access",
|
|
"refresh_token": "pool-refresh",
|
|
"token_type": "Bearer",
|
|
"last_refresh": "2026-06-03T19:00:00Z",
|
|
}
|
|
]
|
|
},
|
|
}
|
|
monkeypatch.setattr(auth, "_load_auth_store", lambda: store)
|
|
monkeypatch.setattr(auth, "_load_global_auth_store", lambda: {})
|
|
|
|
resolved = auth._read_xai_oauth_tokens(_lock=False)
|
|
|
|
assert resolved["tokens"]["access_token"] == "pool-access"
|
|
assert resolved["tokens"]["refresh_token"] == "pool-refresh"
|
|
assert resolved["tokens"]["token_type"] == "Bearer"
|
|
assert resolved["last_refresh"] == "2026-06-03T19:00:00Z"
|
|
|
|
|