From d1c06eee96da842e16f963791a82642e440bc152 Mon Sep 17 00:00:00 2001 From: hataa <79907651+hata33@users.noreply.github.com> Date: Sun, 30 Aug 2026 14:30:16 +0800 Subject: [PATCH] test(gateway): sweep mcp_tasks and subagent_batches in thread_id route contract, fixes #5061 (#5098) --- .../tests/test_thread_id_route_contract.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/backend/tests/test_thread_id_route_contract.py b/backend/tests/test_thread_id_route_contract.py index adb91feb7..150e52b67 100644 --- a/backend/tests/test_thread_id_route_contract.py +++ b/backend/tests/test_thread_id_route_contract.py @@ -73,16 +73,31 @@ def _collect_thread_id_routes(): artifacts, browser, feedback, + mcp_tasks, runs, scheduled_tasks, skills, + subagent_batches, suggestions, thread_runs, threads, uploads, ) - routers = [artifacts, browser, feedback, runs, scheduled_tasks, skills, suggestions, thread_runs, threads, uploads] + routers = [ + artifacts, + browser, + feedback, + mcp_tasks, + runs, + scheduled_tasks, + skills, + subagent_batches, + suggestions, + thread_runs, + threads, + uploads, + ] cases = [] for module in routers: for route in module.router.routes: @@ -121,6 +136,26 @@ def test_sweep_covers_expected_surface(): """Sanity: the sweep must actually see the known thread_id routes.""" assert len(_THREAD_ID_ROUTES) >= 30 assert any("suggestions" in name for name, _, _ in _THREAD_ID_ROUTES) + assert any("mcp_tasks" in name for name, _, _ in _THREAD_ID_ROUTES) + assert any("subagent_batches" in name for name, _, _ in _THREAD_ID_ROUTES) + + +def test_sweep_covers_every_router_module_with_thread_id_routes(): + """No router module declaring ``{thread_id}`` route paths may fall out of + the runtime sweep (a file merely mentioning thread_id in a body field + does not count).""" + import importlib + + swept = {name for name, _, _ in _THREAD_ID_ROUTES} + missing = [] + for path in sorted(ROUTERS_DIR.glob("*.py")): + module = importlib.import_module(f"app.gateway.routers.{path.stem}") + routes = getattr(getattr(module, "router", None), "routes", None) or [] + if not any("{thread_id}" in getattr(route, "path", "") for route in routes): + continue + if path.stem not in swept: + missing.append(path.stem) + assert not missing, f"routers with thread_id routes missing from the runtime sweep: {missing}" @pytest.mark.parametrize(