Files
nousresearch--hermes-agent/tests/tools/test_browser_camofox_ensure_tab.py
T
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

67 lines
2.4 KiB
Python

"""Regression test: _ensure_tab must send ``listItemId`` (not ``sessionKey``).
The Camoufox REST API server requires ``listItemId`` in the ``POST /tabs``
body. A previous version sent ``sessionKey`` which caused a 400 Bad Request
on every ``browser_navigate`` call. See issue #37960.
"""
from unittest.mock import patch, MagicMock
def test_ensure_tab_sends_list_item_id():
"""POST /tabs body must contain ``listItemId``, not ``sessionKey``."""
# Import the module under test
from tools import browser_camofox as mod
fake_session = {
"user_id": "hermes_test123",
"tab_id": None,
"session_key": "task_my-session",
"managed": False,
"adopt_existing_tab": False,
}
mock_response = MagicMock()
mock_response.json.return_value = {"tabId": "tab-42"}
mock_response.raise_for_status = MagicMock()
with patch.object(mod, "_get_session", return_value=fake_session), \
patch.object(mod, "get_camofox_url", return_value="http://localhost:9377"), \
patch("tools.browser_camofox.requests.post", return_value=mock_response) as mock_post:
result = mod._ensure_tab("test-task", url="https://example.com")
# Verify the POST was called
mock_post.assert_called_once()
call_kwargs = mock_post.call_args
body = call_kwargs.kwargs.get("json") or call_kwargs[1].get("json")
# Core assertion: listItemId present, sessionKey absent
assert "listItemId" in body, f"Expected 'listItemId' in POST body, got: {body}"
assert "sessionKey" not in body, f"'sessionKey' should not be in POST body: {body}"
assert body["listItemId"] == "task_my-session"
assert body["userId"] == "hermes_test123"
assert body["url"] == "https://example.com"
# Verify tab_id was set from response
assert result["tab_id"] == "tab-42"
def test_ensure_tab_skips_creation_when_tab_exists():
"""If session already has a tab_id, no POST should be made."""
from tools import browser_camofox as mod
fake_session = {
"user_id": "hermes_test123",
"tab_id": "existing-tab",
"session_key": "task_my-session",
"managed": False,
}
with patch.object(mod, "_get_session", return_value=fake_session), \
patch("tools.browser_camofox.requests.post") as mock_post:
result = mod._ensure_tab("test-task")
# No POST should be made — tab already exists
mock_post.assert_not_called()
assert result["tab_id"] == "existing-tab"