fix: Fix session API format and missing client methods
This commit is contained in:
@@ -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."""
|
||||||
|
|||||||
@@ -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:
|
||||||
"""
|
time.sleep(5.0)
|
||||||
Stress test: Inject many session entries and verify performance doesn't degrade.
|
client = ApiHookClient()
|
||||||
"""
|
time.sleep(2.0)
|
||||||
# 0. Warmup
|
baseline_resp = client.get_performance()
|
||||||
time.sleep(5.0)
|
baseline = baseline_resp.get("performance", {})
|
||||||
client = ApiHookClient()
|
baseline_ft = baseline.get("last_frame_time_ms", 0.0)
|
||||||
# 1. Capture baseline
|
large_session = []
|
||||||
time.sleep(2.0) # Wait for stability
|
for i in range(50):
|
||||||
baseline_resp = client.get_performance()
|
large_session.append(
|
||||||
baseline = baseline_resp.get('performance', {})
|
{
|
||||||
baseline_ft = baseline.get('last_frame_time_ms', 0.0)
|
"role": "User",
|
||||||
# 2. Inject 50 "dummy" session entries
|
"content": f"Stress test entry {i} " * 5,
|
||||||
# Role must match DISC_ROLES in gui_2.py (User, AI, Vendor API, System)
|
"ts": time.time(),
|
||||||
large_session = []
|
"collapsed": False,
|
||||||
for i in range(50):
|
}
|
||||||
large_session.append({
|
)
|
||||||
"role": "User",
|
client.post_session(large_session)
|
||||||
"content": f"Stress test entry {i} " * 5,
|
time.sleep(1.0)
|
||||||
"ts": time.time(),
|
stress_resp = client.get_performance()
|
||||||
"collapsed": False
|
stress = stress_resp.get("performance", {})
|
||||||
})
|
stress_ft = stress.get("last_frame_time_ms", 0.0)
|
||||||
client.post_session(large_session)
|
print(f"Baseline FT: {baseline_ft:.2f}ms, Stress FT: {stress_ft:.2f}ms")
|
||||||
# Give it a moment to process UI updates
|
if stress_ft > 0:
|
||||||
time.sleep(1.0)
|
assert stress_ft < 100.0, (
|
||||||
# 3. Capture stress performance
|
f"Stress frame time {stress_ft:.2f}ms exceeds 10fps threshold"
|
||||||
stress_resp = client.get_performance()
|
)
|
||||||
stress = stress_resp.get('performance', {})
|
session_data = client.get_session()
|
||||||
stress_ft = stress.get('last_frame_time_ms', 0.0)
|
entries = session_data.get("session", {}).get("entries", [])
|
||||||
print(f"Baseline FT: {baseline_ft:.2f}ms, Stress FT: {stress_ft:.2f}ms")
|
assert len(entries) >= 50, f"Expected at least 50 entries, got {len(entries)}"
|
||||||
# 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
|
|
||||||
session_data = client.get_session()
|
|
||||||
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 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 = [
|
||||||
|
|||||||
Reference in New Issue
Block a user