feat: Complete pipeline hot-rebuild implementation with acceptance tests

- Implements pipeline hot-rebuild with state preservation (issue #43)
- Adds auto-injection of MVP stages for missing capabilities
- Adds radial camera mode for polar coordinate scanning
- Adds afterimage and motionblur effects using framebuffer history
- Adds comprehensive acceptance tests for camera modes and pipeline rebuild
- Updates presets.toml with new effect configurations

Related to: #35 (Pipeline Mutation API epic)
Closes: #43, #44, #45
This commit is contained in:
2026-03-19 03:34:06 -07:00
parent 0eb5f1d5ff
commit 238bac1bb2
30 changed files with 3438 additions and 378 deletions

View File

@@ -20,6 +20,7 @@ except ImportError:
from engine.display.backends.multi import MultiDisplay
from engine.display.backends.null import NullDisplay
from engine.display.backends.pygame import PygameDisplay
from engine.display.backends.replay import ReplayDisplay
from engine.display.backends.terminal import TerminalDisplay
from engine.display.backends.websocket import WebSocketDisplay
@@ -90,6 +91,7 @@ class DisplayRegistry:
return
cls.register("terminal", TerminalDisplay)
cls.register("null", NullDisplay)
cls.register("replay", ReplayDisplay)
cls.register("websocket", WebSocketDisplay)
cls.register("pygame", PygameDisplay)
if _MODERNGL_AVAILABLE:
@@ -278,6 +280,7 @@ __all__ = [
"BorderMode",
"TerminalDisplay",
"NullDisplay",
"ReplayDisplay",
"WebSocketDisplay",
"MultiDisplay",
"PygameDisplay",

View File

@@ -2,7 +2,10 @@
Null/headless display backend.
"""
import json
import time
from pathlib import Path
from typing import Any
class NullDisplay:
@@ -10,7 +13,8 @@ class NullDisplay:
This display does nothing - useful for headless benchmarking
or when no display output is needed. Captures last buffer
for testing purposes.
for testing purposes. Supports frame recording for replay
and file export/import.
"""
width: int = 80
@@ -19,6 +23,9 @@ class NullDisplay:
def __init__(self):
self._last_buffer = None
self._is_recording = False
self._recorded_frames: list[dict[str, Any]] = []
self._frame_count = 0
def init(self, width: int, height: int, reuse: bool = False) -> None:
"""Initialize display with dimensions.
@@ -37,7 +44,6 @@ class NullDisplay:
from engine.display import get_monitor, render_border
# Get FPS for border (if available)
fps = 0.0
frame_time = 0.0
monitor = get_monitor()
@@ -49,26 +55,28 @@ class NullDisplay:
fps = 1000.0 / avg_ms
frame_time = avg_ms
# Apply border if requested (same as terminal display)
if border:
buffer = render_border(buffer, self.width, self.height, fps, frame_time)
self._last_buffer = buffer
# For debugging: print first few frames to stdout
if hasattr(self, "_frame_count"):
self._frame_count += 1
else:
self._frame_count = 0
if self._is_recording:
self._recorded_frames.append(
{
"frame_number": self._frame_count,
"buffer": buffer,
"width": self.width,
"height": self.height,
}
)
# Only print first 5 frames or every 10th frame
if self._frame_count <= 5 or self._frame_count % 10 == 0:
sys.stdout.write("\n" + "=" * 80 + "\n")
sys.stdout.write(
f"Frame {self._frame_count} (buffer height: {len(buffer)})\n"
)
sys.stdout.write("=" * 80 + "\n")
for i, line in enumerate(buffer[:30]): # Show first 30 lines
for i, line in enumerate(buffer[:30]):
sys.stdout.write(f"{i:2}: {line}\n")
if len(buffer) > 30:
sys.stdout.write(f"... ({len(buffer) - 30} more lines)\n")
@@ -80,6 +88,78 @@ class NullDisplay:
elapsed_ms = (time.perf_counter() - t0) * 1000
monitor.record_effect("null_display", elapsed_ms, chars_in, chars_in)
self._frame_count += 1
def start_recording(self) -> None:
"""Begin recording frames."""
self._is_recording = True
self._recorded_frames = []
def stop_recording(self) -> None:
"""Stop recording frames."""
self._is_recording = False
def get_frames(self) -> list[list[str]]:
"""Get recorded frames as list of buffers.
Returns:
List of buffers, each buffer is a list of strings (lines)
"""
return [frame["buffer"] for frame in self._recorded_frames]
def get_recorded_data(self) -> list[dict[str, Any]]:
"""Get full recorded data including metadata.
Returns:
List of frame dicts with 'frame_number', 'buffer', 'width', 'height'
"""
return self._recorded_frames
def clear_recording(self) -> None:
"""Clear recorded frames."""
self._recorded_frames = []
def save_recording(self, filepath: str | Path) -> None:
"""Save recorded frames to a JSON file.
Args:
filepath: Path to save the recording
"""
path = Path(filepath)
data = {
"version": 1,
"display": "null",
"width": self.width,
"height": self.height,
"frame_count": len(self._recorded_frames),
"frames": self._recorded_frames,
}
path.write_text(json.dumps(data, indent=2))
def load_recording(self, filepath: str | Path) -> list[dict[str, Any]]:
"""Load recorded frames from a JSON file.
Args:
filepath: Path to load the recording from
Returns:
List of frame dicts
"""
path = Path(filepath)
data = json.loads(path.read_text())
self._recorded_frames = data.get("frames", [])
self.width = data.get("width", 80)
self.height = data.get("height", 24)
return self._recorded_frames
def replay_frames(self) -> list[list[str]]:
"""Get frames for replay.
Returns:
List of buffers for replay
"""
return self.get_frames()
def clear(self) -> None:
pass

View File

@@ -0,0 +1,122 @@
"""
Replay display backend - plays back recorded frames.
"""
from typing import Any
class ReplayDisplay:
"""Replay display - plays back recorded frames.
This display reads frames from a recording (list of frame data)
and yields them sequentially, useful for testing and demo purposes.
"""
width: int = 80
height: int = 24
def __init__(self):
self._frames: list[dict[str, Any]] = []
self._current_frame = 0
self._playback_index = 0
self._loop = False
def init(self, width: int, height: int, reuse: bool = False) -> None:
"""Initialize display with dimensions.
Args:
width: Terminal width in characters
height: Terminal height in rows
reuse: Ignored for ReplayDisplay
"""
self.width = width
self.height = height
def set_frames(self, frames: list[dict[str, Any]]) -> None:
"""Set frames to replay.
Args:
frames: List of frame dicts with 'buffer', 'width', 'height'
"""
self._frames = frames
self._current_frame = 0
self._playback_index = 0
def set_loop(self, loop: bool) -> None:
"""Set loop playback mode.
Args:
loop: True to loop, False to stop at end
"""
self._loop = loop
def show(self, buffer: list[str], border: bool = False) -> None:
"""Display a frame (ignored in replay mode).
Args:
buffer: Buffer to display (ignored)
border: Border flag (ignored)
"""
pass
def get_next_frame(self) -> list[str] | None:
"""Get the next frame in the recording.
Returns:
Buffer list of strings, or None if playback is done
"""
if not self._frames:
return None
if self._playback_index >= len(self._frames):
if self._loop:
self._playback_index = 0
else:
return None
frame = self._frames[self._playback_index]
self._playback_index += 1
return frame.get("buffer")
def reset(self) -> None:
"""Reset playback to the beginning."""
self._playback_index = 0
def seek(self, index: int) -> None:
"""Seek to a specific frame.
Args:
index: Frame index to seek to
"""
if 0 <= index < len(self._frames):
self._playback_index = index
def is_finished(self) -> bool:
"""Check if playback is finished.
Returns:
True if at end of frames and not looping
"""
return not self._loop and self._playback_index >= len(self._frames)
def clear(self) -> None:
pass
def cleanup(self) -> None:
pass
def get_dimensions(self) -> tuple[int, int]:
"""Get current dimensions.
Returns:
(width, height) in character cells
"""
return (self.width, self.height)
def is_quit_requested(self) -> bool:
"""Check if quit was requested (optional protocol method)."""
return False
def clear_quit_request(self) -> None:
"""Clear quit request (optional protocol method)."""
pass