BUG-1 (critical): api/profiles.py _DEFAULT_HERMES_HOME used Path.home()/.hermes
hardcoded, ignoring the HERMES_HOME env var. conftest.py sets HERMES_HOME to a
test-isolated state dir -- but profiles.py bypassed it and read/wrote real ~/.hermes
during every test run (active_profile file, .env loading). Fixed by reading
os.getenv('HERMES_HOME', ...) at module load time.
BUG-7 (medium): api/workspace.py load_workspaces() fell back to the global
workspaces.json for ALL profiles when their profile-local file didn't exist yet.
New named profiles silently inherited the default profile's workspace list instead
of starting clean. Fixed: the global file fallback now only applies to the default
profile (migration path); named profiles start with a fresh default entry.
BUG-4 (high): test_sessions_list_includes_profile had a vacuous 'if matching:'
guard -- if the session wasn't found the assert was silently skipped and the test
passed. Fixed with hard assert. Also changed to use /api/session?session_id=
directly instead of scanning /api/sessions (which filters out empty Untitled
sessions with 0 messages, causing the test to always see an empty match list).
BUG-5 / test ordering regression: test_profile_switch_returns_default_model_and_workspace
failed with 409 because test_chat_stream_opens_successfully (runs earlier in the
suite) starts a real LLM stream that stays alive in STREAMS. Added a wait loop
(up to 30s) polling /health active_streams before attempting the profile switch.
BUG-8 (low): Removed dead import _profile_default_workspace in switch_profile()
-- was imported but never used (get_last_workspace() already delegates to it).
Also: test_profile_active_endpoint hardcoded assert data['name'] == 'default'
which fails if a prior run left a non-default active_profile on disk. Changed
to assert name is a non-empty string (the endpoint contract), not a specific value.
Tests: 423 passed, 0 failed.
125 lines
5.3 KiB
Python
125 lines
5.3 KiB
Python
"""Sprint 23 tests: profile/workspace/model coherence."""
|
|
import json, pathlib, re, urllib.request, urllib.error
|
|
|
|
BASE = "http://127.0.0.1:8788"
|
|
|
|
def get(path):
|
|
with urllib.request.urlopen(BASE + path, timeout=10) as r:
|
|
return json.loads(r.read()), r.status
|
|
|
|
def post(path, body=None):
|
|
data = json.dumps(body or {}).encode()
|
|
req = urllib.request.Request(BASE + path, data=data, headers={"Content-Type": "application/json"})
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
return json.loads(r.read()), r.status
|
|
except urllib.error.HTTPError as e:
|
|
return json.loads(e.read()), e.code
|
|
|
|
|
|
# ── Workspace profile-locality ──────────────────────────────────────────────
|
|
|
|
def test_workspace_list_returns_data():
|
|
"""Workspace list endpoint works after profile-local refactor."""
|
|
data, status = get("/api/workspaces")
|
|
assert status == 200
|
|
assert "workspaces" in data
|
|
assert isinstance(data["workspaces"], list)
|
|
assert "last" in data
|
|
|
|
|
|
def test_workspace_add_remove_roundtrip():
|
|
"""Workspace add/remove still works with profile-local storage."""
|
|
import os
|
|
# Use a path that won't resolve differently (macOS /tmp -> /private/tmp)
|
|
resolved_tmp = str(pathlib.Path("/tmp").resolve())
|
|
# Clean slate
|
|
post("/api/workspaces/remove", {"path": resolved_tmp})
|
|
# Add
|
|
data, status = post("/api/workspaces/add", {"path": "/tmp", "name": "Temp"})
|
|
assert status == 200
|
|
assert any(w["path"] == resolved_tmp for w in data.get("workspaces", []))
|
|
# Remove
|
|
data, status = post("/api/workspaces/remove", {"path": resolved_tmp})
|
|
assert status == 200
|
|
assert not any(w["path"] == resolved_tmp for w in data.get("workspaces", []))
|
|
|
|
|
|
# ── Profile switch response fields ─────────────────────────────────────────
|
|
|
|
def test_profile_switch_returns_default_model_and_workspace():
|
|
"""switch_profile() response includes default_model and default_workspace."""
|
|
# Prior tests (test_chat_stream_opens_successfully) may leave a live LLM stream in
|
|
# STREAMS. The server-side thread keeps running until the LLM response completes.
|
|
# Wait up to 30 seconds for it to drain before attempting the profile switch.
|
|
import time
|
|
for _ in range(60):
|
|
health, _ = get("/health")
|
|
if health.get("active_streams", 0) == 0:
|
|
break
|
|
time.sleep(0.5)
|
|
data, status = post("/api/profile/switch", {"name": "default"})
|
|
assert status == 200, f"Profile switch returned {status}: {data}"
|
|
assert "active" in data
|
|
assert data["active"] == "default"
|
|
# default_workspace should always be present (may be null for model)
|
|
assert "default_workspace" in data
|
|
assert isinstance(data["default_workspace"], str)
|
|
assert "default_model" in data # can be None
|
|
|
|
|
|
def test_profile_active_endpoint():
|
|
"""GET /api/profile/active returns name and path."""
|
|
data, status = get("/api/profile/active")
|
|
assert status == 200
|
|
assert "name" in data, "Response missing 'name' field"
|
|
assert isinstance(data["name"], str) and data["name"], "Profile name should be a non-empty string"
|
|
assert "path" in data
|
|
|
|
|
|
# ── Session profile tagging ────────────────────────────────────────────────
|
|
|
|
def test_new_session_has_profile_field():
|
|
"""Sessions created after Sprint 22 should have a profile field."""
|
|
data, status = post("/api/session/new", {})
|
|
assert status == 200
|
|
session = data["session"]
|
|
assert "profile" in session
|
|
# Clean up
|
|
post("/api/session/delete", {"session_id": session["session_id"]})
|
|
|
|
|
|
def test_sessions_list_includes_profile():
|
|
"""Sessions created after Sprint 22 expose a profile field."""
|
|
# Create a session and check via the direct session endpoint
|
|
# (/api/sessions filters out empty Untitled sessions; use /api/session instead)
|
|
create_data, _ = post("/api/session/new", {})
|
|
sid = create_data["session"]["session_id"]
|
|
try:
|
|
data, status = get(f"/api/session?session_id={sid}")
|
|
assert status == 200
|
|
session = data.get("session", data)
|
|
assert "profile" in session, f"'profile' field missing from session: {list(session.keys())}"
|
|
finally:
|
|
post("/api/session/delete", {"session_id": sid})
|
|
|
|
|
|
# ── Static JS analysis ─────────────────────────────────────────────────────
|
|
|
|
REPO_ROOT = pathlib.Path(__file__).parent.parent.resolve()
|
|
|
|
def test_sessions_js_has_profile_filter():
|
|
"""sessions.js should filter sessions by active profile."""
|
|
content = (REPO_ROOT / "static" / "sessions.js").read_text()
|
|
assert "_showAllProfiles" in content
|
|
assert "profileFiltered" in content
|
|
assert "S.activeProfile" in content
|
|
|
|
|
|
def test_panels_js_clears_model_on_switch():
|
|
"""switchToProfile() must clear localStorage model key."""
|
|
content = (REPO_ROOT / "static" / "panels.js").read_text()
|
|
assert "localStorage.removeItem('hermes-webui-model')" in content
|
|
assert "loadWorkspaceList" in content
|
|
assert "renderSessionList" in content
|