feat(display): add reuse flag to Display protocol

- Add reuse parameter to Display.init() for all backends
- PygameDisplay: reuse existing SDL window via class-level flag
- TerminalDisplay: skip re-init when reuse=True
- WebSocketDisplay: skip server start when reuse=True
- SixelDisplay, KittyDisplay, NullDisplay: ignore reuse (not applicable)
- MultiDisplay: pass reuse to child displays
- Update benchmark.py to reuse pygame display for effect benchmarks
- Add test_websocket_e2e.py with e2e marker
- Register e2e marker in pyproject.toml
This commit is contained in:
2026-03-16 00:30:52 -07:00
parent f9991c24af
commit f5de2c62e0
13 changed files with 309 additions and 34 deletions

View File

@@ -0,0 +1,78 @@
"""
End-to-end tests for WebSocket display using Playwright.
"""
import time
import pytest
class TestWebSocketE2E:
"""End-to-end tests for WebSocket display with browser."""
@pytest.mark.e2e
def test_websocket_server_starts(self):
"""Test that WebSocket server starts and serves HTTP."""
import threading
from engine.display.backends.websocket import WebSocketDisplay
display = WebSocketDisplay(host="127.0.0.1", port=18765)
server_thread = threading.Thread(target=display.start_http_server)
server_thread.daemon = True
server_thread.start()
time.sleep(1)
try:
import urllib.request
response = urllib.request.urlopen("http://127.0.0.1:18765", timeout=5)
assert response.status == 200
content = response.read().decode("utf-8")
assert len(content) > 0
finally:
display.cleanup()
time.sleep(0.5)
@pytest.mark.e2e
@pytest.mark.skipif(
not pytest.importorskip("playwright", reason="playwright not installed"),
reason="playwright not installed",
)
def test_websocket_browser_connection(self):
"""Test WebSocket connection with actual browser."""
import threading
from playwright.sync_api import sync_playwright
from engine.display.backends.websocket import WebSocketDisplay
display = WebSocketDisplay(host="127.0.0.1", port=18767)
server_thread = threading.Thread(target=display.start_server)
server_thread.daemon = True
server_thread.start()
http_thread = threading.Thread(target=display.start_http_server)
http_thread.daemon = True
http_thread.start()
time.sleep(1)
try:
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto("http://127.0.0.1:18767")
time.sleep(0.5)
title = page.title()
assert len(title) >= 0
browser.close()
finally:
display.cleanup()
time.sleep(0.5)