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
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""Regression tests for gateway per-turn env reload preserving config authority.
|
|
|
|
Issue #19158: startup bridges config.yaml agent.max_turns into
|
|
HERMES_MAX_ITERATIONS, but a later per-turn load_dotenv(..., override=True)
|
|
can restore a stale .env HERMES_MAX_ITERATIONS value before the next turn.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from gateway import run as gateway_run
|
|
|
|
|
|
def test_reload_runtime_env_preserves_config_max_turns(tmp_path: Path, monkeypatch) -> None:
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir()
|
|
(hermes_home / "config.yaml").write_text(
|
|
yaml.safe_dump({"agent": {"max_turns": 9000}}),
|
|
encoding="utf-8",
|
|
)
|
|
(hermes_home / ".env").write_text(
|
|
"HERMES_MAX_ITERATIONS=90\nOPENROUTER_API_KEY=fresh-key\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
|
monkeypatch.setenv("HERMES_MAX_ITERATIONS", "9000")
|
|
monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)
|
|
|
|
gateway_run._reload_runtime_env_preserving_config_authority()
|
|
|
|
assert os.environ["OPENROUTER_API_KEY"] == "fresh-key"
|
|
assert os.environ["HERMES_MAX_ITERATIONS"] == "9000"
|
|
|
|
|
|
def test_reload_runtime_env_keeps_env_max_iterations_when_config_omits_key(
|
|
tmp_path: Path, monkeypatch
|
|
) -> None:
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir()
|
|
(hermes_home / "config.yaml").write_text(yaml.safe_dump({"agent": {}}), encoding="utf-8")
|
|
(hermes_home / ".env").write_text("HERMES_MAX_ITERATIONS=123\n", encoding="utf-8")
|
|
|
|
monkeypatch.setattr(gateway_run, "_hermes_home", hermes_home)
|
|
monkeypatch.delenv("HERMES_MAX_ITERATIONS", raising=False)
|
|
|
|
gateway_run._reload_runtime_env_preserving_config_authority()
|
|
|
|
assert os.environ["HERMES_MAX_ITERATIONS"] == "123"
|