conductor(checkpoint): Checkpoint end of Phase 2: Test Suite Migration

This commit is contained in:
2026-02-23 15:56:46 -05:00
parent be20d80453
commit 6677a6e55b
14 changed files with 301 additions and 580 deletions

View File

@@ -1,14 +1,15 @@
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import pytest
from unittest.mock import patch
import gui
import api_hooks
import urllib.request
import requests
import json
import threading
import time
from unittest.mock import patch
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from api_hook_client import ApiHookClient
import gui
def test_hooks_enabled_via_cli():
with patch.object(sys, 'argv', ['gui.py', '--enable-test-hooks']):
@@ -22,81 +23,29 @@ def test_hooks_disabled_by_default():
app = gui.App()
assert getattr(app, 'test_hooks_enabled', False) is False
def test_hooks_enabled_via_env():
with patch.object(sys, 'argv', ['gui.py']):
with patch.dict(os.environ, {'SLOP_TEST_HOOKS': '1'}):
app = gui.App()
assert app.test_hooks_enabled is True
def test_ipc_server_starts_and_responds():
app_mock = gui.App()
app_mock.test_hooks_enabled = True
server = api_hooks.HookServer(app_mock, port=0)
server.start()
def test_live_hook_server_responses(live_gui):
"""
Verifies the live hook server (started via fixture) responds correctly to all major endpoints.
"""
client = ApiHookClient()
# Wait for server to start
time.sleep(0.5)
# Test /status
status = client.get_status()
assert status == {'status': 'ok'}
actual_port = server.server.server_address[1]
base_url = f"http://127.0.0.1:{actual_port}"
# Test /api/project
project = client.get_project()
assert 'project' in project
try:
req = urllib.request.Request(f"{base_url}/status")
with urllib.request.urlopen(req) as response:
assert response.status == 200
data = json.loads(response.read().decode())
assert data.get("status") == "ok"
# Test project GET
req = urllib.request.Request(f"{base_url}/api/project")
with urllib.request.urlopen(req) as response:
assert response.status == 200
data = json.loads(response.read().decode())
assert "project" in data
# Test session GET
req = urllib.request.Request(f"{base_url}/api/session")
with urllib.request.urlopen(req) as response:
assert response.status == 200
data = json.loads(response.read().decode())
assert "session" in data
# Test project POST
project_data = {"project": {"foo": "bar"}}
req = urllib.request.Request(
f"{base_url}/api/project",
method="POST",
data=json.dumps(project_data).encode("utf-8"),
headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req) as response:
assert response.status == 200
assert app_mock.project == {"foo": "bar"}
# Test session POST
session_data = {"session": {"entries": [{"role": "User", "content": "hi"}]}}
req = urllib.request.Request(
f"{base_url}/api/session",
method="POST",
data=json.dumps(session_data).encode("utf-8"),
headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req) as response:
assert response.status == 200
assert app_mock.disc_entries == [{"role": "User", "content": "hi"}]
# Test GUI queue hook
gui_data = {"action": "set_value", "item": "test_item", "value": "test_value"}
req = urllib.request.Request(
f"{base_url}/api/gui",
method="POST",
data=json.dumps(gui_data).encode("utf-8"),
headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req) as response:
assert response.status == 200
# Instead of checking DPG (since we aren't running the real main loop in tests),
# check if it got queued in app_mock
assert hasattr(app_mock, '_pending_gui_tasks')
assert len(app_mock._pending_gui_tasks) == 1
assert app_mock._pending_gui_tasks[0] == gui_data
finally:
server.stop()
# Test /api/session
session = client.get_session()
assert 'session' in session
# Test /api/performance
perf = client.get_performance()
assert 'performance' in perf
# Test POST /api/gui
gui_data = {"action": "test_action", "value": 42}
resp = client.post_gui(gui_data)
assert resp == {'status': 'queued'}