test(gateway): status readers flush the queued write before reading the file
Runtime-status publication is now queued to the writer thread, so tests that read gateway_state.json right after a production publish must flush_runtime_status() first (the same line test_status.py already gained). test_multiplex_shared_ingress patched the old write_runtime_status seam; the adapter publishes now, so the patch target follows the rename.
This commit is contained in:
@@ -11,6 +11,7 @@ import cron.scheduler as sched
|
||||
from gateway.run import GatewayRunner
|
||||
from gateway.session_state import SessionState
|
||||
from hermes_cli.update_cmd_drain_report import drain_progress_reporter
|
||||
from gateway.status import flush_runtime_status
|
||||
|
||||
|
||||
class _FakeAgent:
|
||||
@@ -39,6 +40,7 @@ def test_draining_status_names_chat_and_cron_units_and_clears_when_running(tmp_p
|
||||
with sched._running_lock:
|
||||
sched._running_worker_pids["job-a"] = 4242
|
||||
runner._update_runtime_status("draining")
|
||||
flush_runtime_status()
|
||||
record = json.loads((tmp_path / "gateway_state.json").read_text())
|
||||
by_kind = {unit["kind"]: unit for unit in record["active_work"]}
|
||||
assert by_kind["chat"]["session"] == "telegram:dm:1" and by_kind["chat"]["current_tool"] == "terminal"
|
||||
@@ -48,6 +50,7 @@ def test_draining_status_names_chat_and_cron_units_and_clears_when_running(tmp_p
|
||||
sched.release_running_job("job-a")
|
||||
assert sched.get_running_job_details() == []
|
||||
runner._update_runtime_status("running")
|
||||
flush_runtime_status()
|
||||
assert json.loads((tmp_path / "gateway_state.json").read_text())["active_work"] is None
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import pytest
|
||||
import gateway.run as gateway_run
|
||||
from gateway.config import GatewayConfig, Platform, PlatformConfig
|
||||
from gateway.run import GatewayRunner
|
||||
from gateway.status import flush_runtime_status
|
||||
|
||||
|
||||
class _FakeAdapter:
|
||||
@@ -880,6 +881,7 @@ class TestSecondaryProfileConfigHandling:
|
||||
runner.config = GatewayConfig(multiplex_profiles=False)
|
||||
|
||||
assert await runner._start_secondary_profile_adapters() == 0
|
||||
flush_runtime_status()
|
||||
assert read_runtime_status(tmp_path / "gateway_state.json")["served_profiles"] == []
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -15,6 +15,7 @@ import pytest
|
||||
from gateway.config import GatewayConfig, Platform
|
||||
from gateway.run import GatewayRunner
|
||||
from gateway.run_profile_reconcile import profile_serve_signature
|
||||
from gateway.status import flush_runtime_status
|
||||
|
||||
|
||||
class _Adapter:
|
||||
@@ -75,6 +76,7 @@ def _mkprofile(home, name, env=""):
|
||||
|
||||
|
||||
def _served_record(home):
|
||||
flush_runtime_status()
|
||||
return json.loads((home / "gateway_state.json").read_text(encoding="utf-8")).get("served_profiles")
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ async def test_prefixed_line_webhook_is_verified_by_the_named_profiles_secret_un
|
||||
async def test_shared_listener_adapter_records_its_public_ingress_url(mux_home, monkeypatch):
|
||||
"""Runtime status carries the /p/<profile>/ URL so `gateway status` / the dashboard can show it."""
|
||||
writes: list[dict] = []
|
||||
monkeypatch.setattr("gateway.status.write_runtime_status", lambda **kw: writes.append(kw))
|
||||
monkeypatch.setattr("gateway.status.publish_runtime_status", lambda **kw: writes.append(kw))
|
||||
coder = _line_adapter("secret-coder", "coder")
|
||||
coder._runtime_status_platform_key = "coder:line"
|
||||
runner = _Runner({"coder": {Platform("line"): coder}})
|
||||
|
||||
Reference in New Issue
Block a user