fix: identify WebUI sessions as webui platform (#948)
* fix: use webui platform for webui sessions * test: harden WebUI platform hint regression coverage
This commit is contained in:
@@ -2707,7 +2707,9 @@ def _handle_chat_sync(handler, body):
|
||||
provider=_provider,
|
||||
base_url=_base_url,
|
||||
api_key=_api_key,
|
||||
platform="cli",
|
||||
# Identify browser-originated sessions as WebUI so Hermes Agent
|
||||
# does not inject CLI-specific terminal/output guidance.
|
||||
platform="webui",
|
||||
quiet_mode=True,
|
||||
enabled_toolsets=_resolve_cli_toolsets(),
|
||||
session_id=s.session_id,
|
||||
@@ -3297,7 +3299,9 @@ def _handle_session_compress(handler, body):
|
||||
provider=resolved_provider,
|
||||
base_url=resolved_base_url,
|
||||
api_key=resolved_api_key,
|
||||
platform="cli",
|
||||
# Identify browser-originated sessions as WebUI so Hermes Agent
|
||||
# does not inject CLI-specific terminal/output guidance.
|
||||
platform="webui",
|
||||
quiet_mode=True,
|
||||
enabled_toolsets=_resolve_cli_toolsets(),
|
||||
session_id=sid,
|
||||
|
||||
@@ -1212,7 +1212,9 @@ def _run_agent_streaming(session_id, msg_text, model, workspace, stream_id, atta
|
||||
provider=resolved_provider,
|
||||
base_url=resolved_base_url,
|
||||
api_key=resolved_api_key,
|
||||
platform='cli',
|
||||
# Identify browser-originated sessions as WebUI so Hermes Agent
|
||||
# does not inject CLI-specific terminal/output guidance.
|
||||
platform='webui',
|
||||
quiet_mode=True,
|
||||
enabled_toolsets=_toolsets,
|
||||
fallback_model=_fallback_resolved,
|
||||
|
||||
47
tests/test_webui_platform_hint.py
Normal file
47
tests/test_webui_platform_hint.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Regression: WebUI AIAgent call sites must use platform='webui', not 'cli'.
|
||||
|
||||
These are static source-level checks that will catch any future regression where
|
||||
a developer accidentally reverts the platform kwarg back to 'cli'.
|
||||
"""
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
REPO_ROOT = pathlib.Path(__file__).parent.parent
|
||||
PLATFORM_KWARG_RE = r'platform\s*=\s*["\']{platform}["\']'
|
||||
|
||||
|
||||
def _load_source(relative_path: str) -> str:
|
||||
"""Load a repository source file with a focused assertion on missing files."""
|
||||
path = REPO_ROOT / relative_path
|
||||
assert path.exists(), f"{relative_path} does not exist"
|
||||
return path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _count_platform_kwargs(source: str, platform: str) -> int:
|
||||
return len(re.findall(PLATFORM_KWARG_RE.format(platform=re.escape(platform)), source))
|
||||
|
||||
|
||||
def test_streaming_uses_webui_platform():
|
||||
"""api/streaming.py must pass platform='webui' when constructing AIAgent."""
|
||||
streaming_py = _load_source("api/streaming.py")
|
||||
webui_count = _count_platform_kwargs(streaming_py, "webui")
|
||||
cli_count = _count_platform_kwargs(streaming_py, "cli")
|
||||
assert cli_count == 0, (
|
||||
f"streaming.py still has {cli_count} platform='cli' AIAgent call(s); convert to 'webui'"
|
||||
)
|
||||
assert webui_count >= 1, (
|
||||
f"streaming.py expected ≥1 platform='webui' call, found {webui_count}"
|
||||
)
|
||||
|
||||
|
||||
def test_routes_uses_webui_platform_for_all_agent_calls():
|
||||
"""api/routes.py must use platform='webui' for all AIAgent instantiations."""
|
||||
routes_py = _load_source("api/routes.py")
|
||||
webui_count = _count_platform_kwargs(routes_py, "webui")
|
||||
cli_count = _count_platform_kwargs(routes_py, "cli")
|
||||
assert cli_count == 0, (
|
||||
f"routes.py still has {cli_count} platform='cli' AIAgent call(s); convert to 'webui'"
|
||||
)
|
||||
assert webui_count >= 2, (
|
||||
f"routes.py expected ≥2 platform='webui' calls, found {webui_count}"
|
||||
)
|
||||
Reference in New Issue
Block a user