test(cron): restore the routed-fire handoff test for _launch_external_cron_worker

The earlier trim dropped the only test of the `routed_profile_fire() and
not is_multiplex_active()` branch in the external-worker handoff: the
process flag is OFF (a desktop tick is not a multiplexer) yet a fire routed
to a sibling profile must serialize `multiplex_active=True` and hand the
worker an env without the launch profile's residue, and the context must
not outlive the handoff span. Without it that branch could regress to the
pre-fix behaviour unnoticed.
This commit is contained in:
kshitijk4poor
2026-09-14 23:40:45 +05:30
committed by kshitij
parent 042b9830b4
commit 5850a50a81

View File

@@ -258,6 +258,49 @@ def _stub_external_worker_launch(scheduler, monkeypatch):
return spawned, payloads, handoff, get
def test_launch_external_worker_treats_a_routed_fire_as_multiplexed(tmp_path, monkeypatch):
"""A fire routed to another profile is multiplexed at the handoff boundary (#107695 review on
f5f88d5058). ``run_one_job`` only enables the context in ``_install_fire_secret_scope``, which runs
AFTER this handoff, so a routed desktop fire on the managed path serialized ``multiplex_active=False``
and the worker inherited the launch profile's residue. The payload must carry ``True`` and the
worker env must not carry a launch-only value — and the context must not outlive the handoff."""
import cron.scheduler as scheduler
import hermes_constants
from agent import secret_scope
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
from tools.process_registry import GatewayChildDispatch
launch = tmp_path / "launch"
routed = tmp_path / "routed"
launch.mkdir()
routed.mkdir()
(launch / ".env").write_text("LAUNCH_ONLY_SECRET=launch-secret\n", encoding="utf-8")
(routed / ".env").write_text("", encoding="utf-8")
monkeypatch.setenv("LAUNCH_ONLY_SECRET", "launch-secret")
monkeypatch.setattr(scheduler, "_get_hermes_home", lambda: routed)
monkeypatch.setattr(hermes_constants, "get_process_hermes_home", lambda: launch)
monkeypatch.setattr("cron.scheduler_provider.routed_profile_fire", lambda: True)
monkeypatch.setattr(
"tools.process_registry.restart_safe_gateway_child_argv",
lambda command, *, unit_suffix, require_restart_safe_scope=False: GatewayChildDispatch(
"scoped", ["scope", "--", *command]),
)
spawned, payloads, _handoff, _get = _stub_external_worker_launch(scheduler, monkeypatch)
assert not secret_scope.is_multiplex_active() # the desktop tick itself is NOT a multiplexer
home_token = set_hermes_home_override(str(routed))
try:
assert scheduler._launch_external_cron_worker(
{"id": "job-r", "execution_id": "exec-1", "prompt": "work"}) is True
finally:
reset_hermes_home_override(home_token)
assert payloads[0]["multiplex_active"] is True
assert "LAUNCH_ONLY_SECRET" not in spawned[0][1]["env"]
assert not secret_scope.is_multiplex_active() # enabled for the handoff span only
assert os.environ["LAUNCH_ONLY_SECRET"] == "launch-secret" # parent untouched
def test_launch_external_worker_uses_restart_safe_scope_and_acknowledges(
tmp_path, monkeypatch
):