Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(server): 修 HTTP 路由表的两处不一致,补路由落点与跨表守护

zhangfuzhibb465fa5b403
diff --git a/jiuwenswarm/gateway/routing/agent_rest_map.py b/jiuwenswarm/gateway/routing/agent_rest_map.py
index 5d45b3c49e..f31ed921d4 100644
--- a/jiuwenswarm/gateway/routing/agent_rest_map.py
+++ b/jiuwenswarm/gateway/routing/agent_rest_map.py
@@ -150,8 +150,6 @@ _ROUTE_ROWS: tuple[tuple[str, str, str], ...] = (
("issue.delete", "DELETE", "/issues/{issue_id}"),
("harness.packages.get", "GET", "/harness/packages"),
("harness.packages.scan", "POST", "/harness/packages/scan"),
- ("harness.packages.import", "POST", "/harness/packages/import"),
- ("harness.packages.export", "POST", "/harness/packages/export"),
("harness.packages.activate", "POST", "/harness/packages/{name}/actions/activate"),
("harness.packages.deactivate", "POST", "/harness/packages/{name}/actions/deactivate"),
("harness.packages.delete", "DELETE", "/harness/packages/{name}"),
@@ -180,8 +178,6 @@ _ROUTE_ROWS: tuple[tuple[str, str, str], ...] = (
("browser.runtime_restart", "POST", "/runtime/browser/actions/restart"),
("proactive.tick", "POST", "/proactive/actions/tick"),
("acp.tool_response", "POST", "/acp/tool-responses"),
- ("files.list", "GET", "/files"),
- ("files.get", "GET", "/files/content"),
("symphony.plan", "POST", "/symphony/actions/plan"),
("symphony.build_score", "POST", "/symphony/actions/build-score"),
("symphony.pause_build", "POST", "/symphony/actions/pause-build"),
diff --git a/jiuwenswarm/server/agent_http_routes.py b/jiuwenswarm/server/agent_http_routes.py
index 1bd245448a..0c0ce419b4 100644
--- a/jiuwenswarm/server/agent_http_routes.py
+++ b/jiuwenswarm/server/agent_http_routes.py
@@ -298,8 +298,6 @@ ROUTES: list[RouteSpec] = [
# --- Harness 包 ---
RouteSpec("GET", "/harness/packages", ReqMethod.HARNESS_PACKAGES_GET.value),
RouteSpec("POST", "/harness/packages/scan", ReqMethod.HARNESS_PACKAGES_SCAN.value),
- RouteSpec("POST", "/harness/packages/import", ReqMethod.HARNESS_PACKAGES_IMPORT.value),
- RouteSpec("POST", "/harness/packages/export", ReqMethod.HARNESS_PACKAGES_EXPORT.value),
RouteSpec(
"POST",
"/harness/packages/{name}/actions/activate",
@@ -343,6 +341,16 @@ ROUTES: list[RouteSpec] = [
"/permissions/file-guard/workspace",
ReqMethod.PERMISSIONS_WORKSPACE_ENABLE_SET.value,
),
+ RouteSpec(
+ "GET",
+ "/permissions/file-guard/workspace/access",
+ ReqMethod.PERMISSIONS_WORKSPACE_ACCESS_GET.value,
+ ),
+ RouteSpec(
+ "PUT",
+ "/permissions/file-guard/workspace/access",
+ ReqMethod.PERMISSIONS_WORKSPACE_ACCESS_SET.value,
+ ),
# --- 配置与运维 ---
RouteSpec("POST", "/config/actions/cache-clear", ReqMethod.CONFIG_CACHE_CLEAR.value),
RouteSpec("POST", "/config/actions/agent-reload", ReqMethod.AGENT_RELOAD_CONFIG.value),
@@ -351,8 +359,6 @@ ROUTES: list[RouteSpec] = [
RouteSpec("POST", "/runtime/browser/actions/restart", ReqMethod.BROWSER_RUNTIME_RESTART.value),
RouteSpec("POST", "/proactive/actions/tick", ReqMethod.PROACTIVE_TICK.value),
RouteSpec("POST", "/acp/tool-responses", ReqMethod.ACP_TOOL_RESPONSE.value),
- RouteSpec("GET", "/files", ReqMethod.FILES_LIST.value),
- RouteSpec("GET", "/files/content", ReqMethod.FILES_GET.value),
# --- Symphony(乐谱式编排)---
RouteSpec("POST", "/symphony/actions/plan", ReqMethod.SYMPHONY_PLAN.value),
RouteSpec("POST", "/symphony/actions/build-score", ReqMethod.SYMPHONY_BUILD_SCORE.value),
diff --git a/tests/transport/test_dispatch_matrix.py b/tests/transport/test_dispatch_matrix.py
index df28baa589..764dd37701 100644
--- a/tests/transport/test_dispatch_matrix.py
+++ b/tests/transport/test_dispatch_matrix.py
@@ -522,3 +522,39 @@ def test_server_has_no_dangling_self_attribute_calls() -> None:
"调用方留在原地):\n "
+ "\n ".join(f"agent_ws_server.py:{ln} self.{n}" for ln, n in dangling)
)
+
+
+def test_sandbox_bootstrap_helpers_callable_from_server() -> None:
+ from jiuwenswarm.server.agent_ws_server import AgentWebSocketServer
+ from jiuwenswarm.server.context import AgentServerServices
+ from jiuwenswarm.server.handlers.sandbox import (
+ allocate_internal_jiuwenbox_port,
+ parse_sandbox_host_port,
+ )
+
+ host, port = parse_sandbox_host_port("http://127.0.0.1:8321")
+ assert (host, port) == ("127.0.0.1", 8321)
+
+ server = AgentWebSocketServer.__new__(AgentWebSocketServer)
+
+ class _Runner:
+ def is_owned_listener(self, host: str, port: int) -> bool:
+ return True # 已拥有该监听 → 应直接复用 preferred_port
+
+ server._jiuwenbox_runner = _Runner() # type: ignore[attr-defined]
+
+ # 与 agent_ws_server._bootstrap_internal_jiuwenbox 里的调用形态完全一致
+ got = allocate_internal_jiuwenbox_port(AgentServerServices(server), host, port)
+ assert got == port, f"已拥有监听时应复用 preferred_port,实际 {got}"
+
+ # 端口被占 → 走 pick_free_tcp_port;这条同时验证门面对方法的解析
+ class _BusyRunner:
+ def is_owned_listener(self, host: str, port: int) -> bool:
+ return False
+
+ server._jiuwenbox_runner = _BusyRunner() # type: ignore[attr-defined]
+ server._is_tcp_port_bindable = lambda h, p: False # type: ignore[attr-defined]
+ server._pick_free_tcp_port = lambda h: 54321 # type: ignore[attr-defined]
+
+ got = allocate_internal_jiuwenbox_port(AgentServerServices(server), host, port)
+ assert got == 54321, f"端口被占时应改用内核分配的空闲端口,实际 {got}"
diff --git a/tests/transport/test_route_matrix.py b/tests/transport/test_route_matrix.py
index aedfd044b3..f7452fe570 100644
--- a/tests/transport/test_route_matrix.py
+++ b/tests/transport/test_route_matrix.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import pytest
from jiuwenswarm.common.schema.message import ReqMethod
+from jiuwenswarm.server import agent_http_routes as agent_http_routes_module
from jiuwenswarm.server.agent_http_routes import ROUTES, RouteSpec
from tests.transport.conftest import fill_path
@@ -487,3 +488,87 @@ def test_schedule_logs_coerces_numeric_params() -> None:
for name, default in (("history_index", "-1"), ("offset", "0"), ("limit", "500")):
expected = f'_coerce_int(params.get("{name}"), {default})'
assert expected in src, f"schedule logs 未归一化 {name} —— 期望 `{expected}`"
+
+
+def test_gateway_rest_map_paths_all_exist_on_server() -> None:
+ from jiuwenswarm.gateway.routing.agent_rest_map import REST_ROUTES
+ registered = {(spec.verb, spec.path) for spec in ROUTES}
+ registered_paths = {spec.path for spec in ROUTES}
+ missing = []
+ for method, (verb, path) in sorted(REST_ROUTES.items()):
+ if (verb, path) in registered:
+ continue
+ why = "路径未注册 → 404" if path not in registered_paths else "路径在、动词不符 → 405"
+ missing.append(f"{verb:6s} {path} ({method}) [{why}]")
+
+ assert not missing, (
+ "Gateway 南向会打这些路径,但 AgentServer 没注册。切 HTTP 后必挂,且不会降级:\n "
+ + "\n ".join(missing)
+ )
+
+
+def test_server_routes_all_reachable_from_gateway_map() -> None:
+ from jiuwenswarm.gateway.routing.agent_rest_map import REST_ROUTES
+
+ server_map = {spec.method: (spec.verb, spec.path) for spec in ROUTES}
+ drifted = [
+ f"{method}: server={server_map[method]} gateway={REST_ROUTES[method]}"
+ for method in sorted(server_map.keys() & REST_ROUTES.keys())
+ if server_map[method] != REST_ROUTES[method]
+ ]
+ assert not drifted, "同一 method 两张表路径不一致:\n " + "\n ".join(drifted)
+
+_KNOWN_UNIMPLEMENTED_ON_SERVER = frozenset({
+ # --- Gateway 本地实现(app_web_handlers.register_method),Gateway 不转发 ---
+ "channel.dingtalk.get_conf", "channel.dingtalk.set_conf",
+ "channel.feishu.get_conf", "channel.feishu.set_conf",
+ "channel.slack.get_conf", "channel.slack.set_conf",
+ "channel.telegram.get_conf", "channel.telegram.set_conf",
+ "channel.wechat.get_conf", "channel.wechat.set_conf",
+ "channel.wechat.get_login_ui", "channel.wechat.unbind",
+ "channel.whatsapp.get_conf", "channel.whatsapp.set_conf",
+ "channel.xiaoyi.get_conf", "channel.xiaoyi.set_conf",
+ "heartbeat.get_conf", "heartbeat.set_conf",
+ "updater.check", "updater.download",
+ "updater.get_conf", "updater.set_conf", "updater.get_status",
+ # --- TUI 本地实现(tui_connect.register_local_handler)---
+ "history.list_turns",
+ "session.restore_files",
+})
+
+
+def _methods_with_server_landing_spot() -> set[str]:
+ import re
+ from pathlib import Path
+
+ from jiuwenswarm.server import dispatch as dispatch_mod
+
+ found = {m.value for m in dispatch_mod.HANDLERS}
+
+ server_dir = Path(agent_http_routes_module.__file__).parent
+ attr = re.compile(r"ReqMethod\.([A-Z0-9_]+)")
+ for path in server_dir.rglob("*.py"):
+ if "__pycache__" in path.parts or path.name == "agent_http_routes.py":
+ continue
+ for name in set(attr.findall(path.read_text(encoding="utf-8"))):
+ member = getattr(ReqMethod, name, None)
+ if member is not None:
+ found.add(member.value)
+ return found
+
+
+def test_every_route_has_a_server_landing_spot_or_is_registered_as_missing() -> None:
+ landing = _methods_with_server_landing_spot()
+ unhandled = {spec.method for spec in ROUTES} - landing
+
+ new = sorted(unhandled - _KNOWN_UNIMPLEMENTED_ON_SERVER)
+ assert not new, (
+ "这些路由声明了,但 AgentServer 上没有落点,调用方会拿到模型回的『收到』而不是错误:\n "
+ + "\n ".join(new)
+ + "\n补 handler,或写进 _KNOWN_UNIMPLEMENTED_ON_SERVER 并注明归属。"
+ )
+
+ stale = sorted(_KNOWN_UNIMPLEMENTED_ON_SERVER - unhandled)
+ assert not stale, (
+ "这些方法已经有落点了(或路由已删),清单该同步删掉:\n " + "\n ".join(stale)
+ )
diff --git a/tests/unit_tests/gateway/test_agent_rest_map.py b/tests/unit_tests/gateway/test_agent_rest_map.py
index 6312e11327..fa5b5de4ac 100644
--- a/tests/unit_tests/gateway/test_agent_rest_map.py
+++ b/tests/unit_tests/gateway/test_agent_rest_map.py
@@ -50,6 +50,11 @@ _RPC_ALLOWLIST = frozenset(
"3rdagent.switch",
"3rdagent.list",
"skills.enterprise.list",
+ # 下面全仓无任何实现(只有ReqMethod枚举),与logging.set同类遗留
+ "files.list",
+ "files.get",
+ "harness.packages.import",
+ "harness.packages.export",
}
)