fix: Fix session API format and missing client methods
This commit is contained in:
@@ -53,6 +53,10 @@ class ApiHookClient:
|
||||
return {}
|
||||
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]:
|
||||
"""Retrieves the current project state."""
|
||||
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]:
|
||||
"""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]:
|
||||
"""Pushes an event to the GUI's SyncEventQueue via the /api/gui endpoint."""
|
||||
|
||||
@@ -2,46 +2,39 @@ import time
|
||||
import sys
|
||||
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__), "..", "src")))
|
||||
|
||||
from src.api_hook_client import ApiHookClient
|
||||
|
||||
|
||||
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)
|
||||
client = ApiHookClient()
|
||||
# 1. Capture baseline
|
||||
time.sleep(2.0) # Wait for stability
|
||||
time.sleep(2.0)
|
||||
baseline_resp = client.get_performance()
|
||||
baseline = baseline_resp.get('performance', {})
|
||||
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)
|
||||
baseline = baseline_resp.get("performance", {})
|
||||
baseline_ft = baseline.get("last_frame_time_ms", 0.0)
|
||||
large_session = []
|
||||
for i in range(50):
|
||||
large_session.append({
|
||||
large_session.append(
|
||||
{
|
||||
"role": "User",
|
||||
"content": f"Stress test entry {i} " * 5,
|
||||
"ts": time.time(),
|
||||
"collapsed": False
|
||||
})
|
||||
"collapsed": False,
|
||||
}
|
||||
)
|
||||
client.post_session(large_session)
|
||||
# Give it a moment to process UI updates
|
||||
time.sleep(1.0)
|
||||
# 3. Capture stress performance
|
||||
stress_resp = client.get_performance()
|
||||
stress = stress_resp.get('performance', {})
|
||||
stress_ft = stress.get('last_frame_time_ms', 0.0)
|
||||
stress = stress_resp.get("performance", {})
|
||||
stress_ft = stress.get("last_frame_time_ms", 0.0)
|
||||
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:
|
||||
assert stress_ft < 100.0, f"Stress frame time {stress_ft:.2f}ms exceeds 10fps threshold"
|
||||
# Ensure the session actually updated
|
||||
assert stress_ft < 100.0, (
|
||||
f"Stress frame time {stress_ft:.2f}ms exceeds 10fps threshold"
|
||||
)
|
||||
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)}"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Any
|
||||
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:
|
||||
file_items = [
|
||||
|
||||
Reference in New Issue
Block a user