Files
红尘 d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
Initial import of NousResearch/hermes-agent
2026-05-31 09:36:58 +08:00

62 lines
1.8 KiB
Python

"""Test that HERMES_SESSION_ID is exposed as an env var and ContextVar."""
import os
import sys
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../.."))
from run_agent import AIAgent
@pytest.fixture(autouse=True)
def _cleanup_env():
"""Remove HERMES_SESSION_ID before/after each test."""
os.environ.pop("HERMES_SESSION_ID", None)
yield
os.environ.pop("HERMES_SESSION_ID", None)
def test_session_id_env_set_on_init():
"""AIAgent.__init__ sets HERMES_SESSION_ID in the environment."""
agent = AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert os.environ.get("HERMES_SESSION_ID") == agent.session_id
assert len(agent.session_id) > 0
def test_session_id_env_uses_provided_id():
"""When session_id is passed explicitly, HERMES_SESSION_ID reflects it."""
custom_id = "20260511_120000_abc12345"
agent = AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
session_id=custom_id,
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert os.environ["HERMES_SESSION_ID"] == custom_id
assert agent.session_id == custom_id
def test_session_id_contextvar_set():
"""AIAgent.__init__ also sets the ContextVar for concurrency safety."""
custom_id = "20260511_130000_def67890"
AIAgent(
api_key="test-key",
base_url="https://openrouter.ai/api/v1",
session_id=custom_id,
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
from gateway.session_context import get_session_env
assert get_session_env("HERMES_SESSION_ID") == custom_id