mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Systematic prune per AGENTS.md test policy, one pass over every major test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, honcho/openviking, root-level): - DELETE: source-reading tests (read_text/getsource on prod files), change-detector tests (exact catalog counts, model-name snapshots, config version literals), mock-echo tests (assert a mock returns what it was told), assertion-free/trivial tests, near-duplicate parametrizations (boundaries + one representative kept), async/sync twin duplicates, cosmetic within-file variations. - KEEP (mandatory): security/redaction/approval guards, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests. - 6 test files deleted outright (script-style/no-assert or fully redundant); conftest.py, fakes/, fixtures/ untouched. - tests/acp/conftest.py added: autouse fixture stubs the live models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server tests performed on every session create — test_server.py 147s → 3.4s, and the tests are now genuinely hermetic. - Sleep-based slowness shrunk where safe (codex_ttfb_watchdog, compression_concurrent_fork, etc.); no wall-clock assertion tightened. Verification: full hermetic suite via scripts/run_tests.sh — 2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall (baseline: 583s wall, 13,564s subprocess CPU).
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.web_server import _save_anthropic_oauth_creds
|
|
|
|
|
|
class _DummyPool:
|
|
def entries(self):
|
|
return []
|
|
|
|
def remove_entry(self, _id):
|
|
return None
|
|
|
|
def add_entry(self, _entry):
|
|
return None
|
|
|
|
|
|
@pytest.fixture
|
|
def oauth_file(monkeypatch, tmp_path):
|
|
target = tmp_path / '.anthropic_oauth.json'
|
|
monkeypatch.setattr('agent.anthropic_adapter._get_hermes_oauth_file', lambda: target)
|
|
monkeypatch.setattr('agent.credential_pool.load_pool', lambda _provider: _DummyPool())
|
|
return target
|
|
|
|
|
|
def test_dashboard_oauth_write_uses_owner_only_permissions(oauth_file):
|
|
old_umask = os.umask(0o022)
|
|
try:
|
|
_save_anthropic_oauth_creds('access-token', 'refresh-token', 123456)
|
|
finally:
|
|
os.umask(old_umask)
|
|
|
|
assert oauth_file.exists()
|
|
mode = oauth_file.stat().st_mode & 0o777
|
|
assert mode == 0o600
|
|
|
|
|
|
def test_dashboard_oauth_write_uses_atomic_json_write_with_owner_only_mode(oauth_file, monkeypatch):
|
|
"""The OAuth token file must be written 0o600 from creation via
|
|
``atomic_json_write(mode=0o600)``, so it is never briefly world-readable
|
|
(the old ``os.replace`` + post-hoc ``chmod`` TOCTOU)."""
|
|
import utils
|
|
|
|
calls = {}
|
|
real = utils.atomic_json_write
|
|
|
|
def spy(path, data, **kwargs):
|
|
calls['mode'] = kwargs.get('mode')
|
|
return real(path, data, **kwargs)
|
|
|
|
monkeypatch.setattr(utils, 'atomic_json_write', spy)
|
|
|
|
_save_anthropic_oauth_creds('access-token', 'refresh-token', 123456)
|
|
|
|
assert calls.get('mode') == 0o600, \
|
|
'OAuth creds must be written 0o600 atomically (no chmod-after-replace window)'
|
|
assert oauth_file.exists()
|