fix: Fix session API format and missing client methods

This commit is contained in:
2026-03-05 19:55:54 -05:00
parent 4da88a4274
commit e02ebf7a65
3 changed files with 44 additions and 39 deletions

View File

@@ -53,6 +53,10 @@ class ApiHookClient:
return {} return {}
return res return res
def post_project(self, project_data: dict) -> dict[str, Any]:
return self._make_request('POST', '/api/project', data=project_data) or {}
def get_project(self) -> dict[str, Any]: def get_project(self) -> dict[str, Any]:
"""Retrieves the current project state.""" """Retrieves the current project state."""
return self._make_request('GET', '/api/project') or {} return self._make_request('GET', '/api/project') or {}
@@ -63,7 +67,15 @@ class ApiHookClient:
def post_session(self, session_entries: list[dict]) -> dict[str, Any]: def post_session(self, session_entries: list[dict]) -> dict[str, Any]:
"""Updates the session history.""" """Updates the session history."""
return self._make_request('POST', '/api/session', data={"entries": session_entries}) or {} return self._make_request('POST', '/api/session', data={"session": {"entries": session_entries}}) or {}
def get_events(self) -> list[dict[str, Any]]:
res = self._make_request('GET', '/api/events')
return res.get("events", []) if res else []
def clear_events(self) -> list[dict[str, Any]]:
return self.get_events()
def post_gui(self, payload: dict) -> dict[str, Any]: def post_gui(self, payload: dict) -> dict[str, Any]:
"""Pushes an event to the GUI's SyncEventQueue via the /api/gui endpoint.""" """Pushes an event to the GUI's SyncEventQueue via the /api/gui endpoint."""

View File

@@ -2,46 +2,39 @@ import time
import sys import sys
import os import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src"))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from src.api_hook_client import ApiHookClient from src.api_hook_client import ApiHookClient
def test_comms_volume_stress_performance(live_gui) -> None: def test_comms_volume_stress_performance(live_gui) -> None:
"""
Stress test: Inject many session entries and verify performance doesn't degrade.
"""
# 0. Warmup
time.sleep(5.0) time.sleep(5.0)
client = ApiHookClient() client = ApiHookClient()
# 1. Capture baseline time.sleep(2.0)
time.sleep(2.0) # Wait for stability
baseline_resp = client.get_performance() baseline_resp = client.get_performance()
baseline = baseline_resp.get('performance', {}) baseline = baseline_resp.get("performance", {})
baseline_ft = baseline.get('last_frame_time_ms', 0.0) baseline_ft = baseline.get("last_frame_time_ms", 0.0)
# 2. Inject 50 "dummy" session entries
# Role must match DISC_ROLES in gui_2.py (User, AI, Vendor API, System)
large_session = [] large_session = []
for i in range(50): for i in range(50):
large_session.append({ large_session.append(
{
"role": "User", "role": "User",
"content": f"Stress test entry {i} " * 5, "content": f"Stress test entry {i} " * 5,
"ts": time.time(), "ts": time.time(),
"collapsed": False "collapsed": False,
}) }
)
client.post_session(large_session) client.post_session(large_session)
# Give it a moment to process UI updates
time.sleep(1.0) time.sleep(1.0)
# 3. Capture stress performance
stress_resp = client.get_performance() stress_resp = client.get_performance()
stress = stress_resp.get('performance', {}) stress = stress_resp.get("performance", {})
stress_ft = stress.get('last_frame_time_ms', 0.0) stress_ft = stress.get("last_frame_time_ms", 0.0)
print(f"Baseline FT: {baseline_ft:.2f}ms, Stress FT: {stress_ft:.2f}ms") print(f"Baseline FT: {baseline_ft:.2f}ms, Stress FT: {stress_ft:.2f}ms")
# If we got valid timing, assert it's within reason
if stress_ft > 0: if stress_ft > 0:
assert stress_ft < 100.0, f"Stress frame time {stress_ft:.2f}ms exceeds 10fps threshold" assert stress_ft < 100.0, (
# Ensure the session actually updated f"Stress frame time {stress_ft:.2f}ms exceeds 10fps threshold"
)
session_data = client.get_session() session_data = client.get_session()
entries = session_data.get('session', {}).get('entries', []) entries = session_data.get("session", {}).get("entries", [])
assert len(entries) >= 50, f"Expected at least 50 entries, got {len(entries)}" assert len(entries) >= 50, f"Expected at least 50 entries, got {len(entries)}"

View File

@@ -1,6 +1,6 @@
from typing import Any from typing import Any
from pathlib import Path from pathlib import Path
from aggregate import build_tier1_context, build_tier2_context, build_tier3_context from src.aggregate import build_tier1_context, build_tier2_context, build_tier3_context
def test_build_tier1_context_exists() -> None: def test_build_tier1_context_exists() -> None:
file_items = [ file_items = [