Skip to content

The agent that grows with you

test(cron): main's pinned-fallback tests run through the owner bridge

teknium12256961cadb8
diff --git a/tests/cron/test_bot_chat_own_profile_multiplex_home.py b/tests/cron/test_bot_chat_own_profile_multiplex_home.py
deleted file mode 100644
index 1f28984181b..00000000000
--- a/tests/cron/test_bot_chat_own_profile_multiplex_home.py
+++ /dev/null
@@ -1,73 +0,0 @@
-"""``deliver: bot-chat`` (the job's OWN profile, no ``-p``) from a multiplexed tick runs the delivery
-turn in the ticking profile's home, never the gateway's launch home (#119858).
-
-The multiplexed ticker binds the served profile as a ``HERMES_HOME`` override that never reaches
-``os.environ``; the child env must be derived from the override-aware home (``served_profile_child_env``),
-never from ``os.environ.copy()``.
-"""
-from __future__ import annotations
-
-import subprocess
-
-import pytest
-
-import cron.scheduler_delivery as delivery
-from agent.secret_scope import set_multiplex_active
-from hermes_constants import reset_hermes_home_override, set_hermes_home_override
-
-
-def multiplexer(tmp_path, monkeypatch):
- """A default-hosted multiplexer whose launch ``.env`` is in ``os.environ``, serving alpha and beta."""
- root = tmp_path / "hermes"
- for name in ("alpha", "beta"):
- home = root / "profiles" / name
- home.mkdir(parents=True)
- (home / ".env").write_text(f"ANTHROPIC_API_KEY=sk-{name}\n{name.upper()}_ONLY=1\n", encoding="utf-8")
- (root / ".env").write_text("ANTHROPIC_API_KEY=sk-root\nLAUNCH_ONLY_MARKER=1\n", encoding="utf-8")
- monkeypatch.setenv("HERMES_HOME", str(root))
- monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-root")
- monkeypatch.setenv("LAUNCH_ONLY_MARKER", "1")
- captured: dict = {}
-
- def _fake_turn(argv, env, report_path, timeout):
- captured.update(env=dict(env), argv=list(argv))
- return subprocess.CompletedProcess(argv, 0, stdout="", stderr="")
-
- monkeypatch.setattr(delivery, "_run_bot_chat_turn", _fake_turn)
- set_multiplex_active(True)
- try:
- yield root, captured
- finally:
- set_multiplex_active(False)
-
-
-def test_an_own_profile_bot_chat_turn_runs_in_the_ticking_profiles_home(multiplexer):
- """A→B→A: each served profile's bare ``bot-chat`` child carries THAT profile's home and
- credentials; the launch profile's marker is absent; no ``-p`` is synthesised."""
- root, captured = multiplexer
- for name in ("alpha", "beta", "alpha"):
- home = root / "profiles" / name
- token = set_hermes_home_override(str(home))
- try:
- assert delivery._deliver_to_bot_chat({"id": f"j-{name}", "name": "nightly"}, "the brief", "") is None
- finally:
- reset_hermes_home_override(token)
- env = captured["env"]
- assert env["HERMES_HOME"] == str(home)
- assert env["ANTHROPIC_API_KEY"] == f"sk-{name}"
- assert "LAUNCH_ONLY_MARKER" not in env, "the launch profile's env reached a served profile's turn"
- assert "-p" not in captured["argv"]
-
-
-def test_an_explicit_target_profile_still_wins_over_the_ticking_profile(multiplexer):
- """Control: ``bot-chat:beta`` fired from alpha's tick is built for beta, not for alpha."""
- root, captured = multiplexer
- token = set_hermes_home_override(str(root / "profiles" / "alpha"))
- try:
- assert delivery._deliver_to_bot_chat({"id": "j", "name": "nightly"}, "the brief", "beta") is None
- finally:
- reset_hermes_home_override(token)
- assert captured["env"]["HERMES_HOME"] == str(root / "profiles" / "beta")
- assert captured["env"]["ANTHROPIC_API_KEY"] == "sk-beta"
- assert "ALPHA_ONLY" not in captured["env"]
diff --git a/tests/cron/test_cron_pinned_job_fallback.py b/tests/cron/test_cron_pinned_job_fallback.py
index a3ad92b0d5e..6d1f6a21d96 100644
--- a/tests/cron/test_cron_pinned_job_fallback.py
+++ b/tests/cron/test_cron_pinned_job_fallback.py
@@ -13,14 +13,56 @@ the chain at both points. Drives the real ``run_job`` with AIAgent and
``resolve_runtime_provider`` mocked.
"""
+import asyncio
+import json
+from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import pytest
from cron import scheduler
-from cron.scheduler import _CronJobConfig, _resolve_job_runtime, run_job
+from cron.scheduler import _CronJobConfig, _resolve_job_runtime
from hermes_cli.auth import AuthError
+
+def _run_owned_job(job, tmp_path):
+ """Run the job through the production owner bridge (cron turns execute inside the gateway
+ owner, which lends its canonical store); returns run_job's ``(success, output, final,
+ error)`` tuple."""
+ from gateway.session_contract import SessionRef
+ from gateway.session_cron import current_execution, execute
+ from hermes_state_registry import acquire, release
+
+ ref = SessionRef("test-profile", "cron-owner-session")
+ admission_id = "cron-owner-admission"
+ db = acquire(tmp_path / "state.db")
+ db.create_session(ref.session_id, source="cron")
+ authority = SimpleNamespace(
+ db=db, pending_results={},
+ sessions={ref.session_id: SimpleNamespace(source=SimpleNamespace(user_id="cron-owner"))},
+ )
+ row = {"admission_id": admission_id, "request_id": "cron-owner-request",
+ "principal_id": "cron-owner", "payload": {"text": ""}}
+ policy = SimpleNamespace(request_json=json.dumps(
+ {"cron_job": job, "extra_prompt": None, "request_id": "cron-owner-request"}))
+
+ async def run():
+ previous = current_execution()
+ try:
+ await execute(authority, ref, row, policy)
+ except RuntimeError as exc:
+ saved = authority.pending_results.get(admission_id)
+ if saved is None:
+ raise
+ assert str(exc) == saved["result"]["cron_result"][3]
+ assert current_execution() is previous
+ return tuple(authority.pending_results[admission_id]["result"]["cron_result"])
+
+ try:
+ return asyncio.run(run())
+ finally:
+ release(db)
+
_CONFIG = (
"model:\n"
" default: gpt-5.6-sol\n"
@@ -56,12 +98,11 @@ def _run(tmp_path, job, *, primary_error=None):
patch("cron.scheduler_delivery._resolve_origin", return_value=None), \
patch("hermes_cli.env_loader.load_hermes_dotenv"), \
patch("hermes_cli.env_loader.reset_secret_source_cache"), \
- patch("hermes_state_registry.acquire", return_value=MagicMock()), \
patch("hermes_cli.runtime_provider.resolve_runtime_provider", side_effect=resolve), \
patch("tools.mcp_tool_discovery.discover_mcp_tools", return_value=[]), \
patch("run_agent.AIAgent") as agent_cls:
agent_cls.return_value.run_conversation.return_value = {"final_response": "ok"}
- success, _output, _final, error = run_job(dict(job))
+ success, _output, _final, error = _run_owned_job(dict(job), tmp_path)
kwargs = agent_cls.call_args.kwargs if agent_cls.called else {}
return success, error, requested, kwargs
diff --git a/tests/cron/test_preflight_config.py b/tests/cron/test_preflight_config.py
index 45ed19c33ac..d3786345381 100644
--- a/tests/cron/test_preflight_config.py
+++ b/tests/cron/test_preflight_config.py
@@ -178,7 +178,8 @@ class TestMissingProviderKeyBlocks:
raise AuthError("no key")
return {**_RUNTIME, "provider": "openrouter"}
- job = _job()
+ # Unpinned: a job carrying its own model is pinned (#100437) and gets no chain.
+ job = _job(model=None)
with cron_jobs.use_cron_store(tmp_path):
cron_jobs.save_jobs([job])
success, output, final_response, error, agent_constructed = \