feat: JSON-lines protocol with command and event dataclasses
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_workbench(tmp_path):
|
||||
"""Provide a temporary ~/Kitty-Workbench directory."""
|
||||
wb = tmp_path / "Kitty-Workbench"
|
||||
wb.mkdir()
|
||||
return wb
|
||||
|
||||
@pytest.fixture
|
||||
def socket_path(tmp_path):
|
||||
"""Provide a temporary socket path."""
|
||||
return str(tmp_path / "test.sock")
|
||||
@@ -0,0 +1,48 @@
|
||||
import json
|
||||
from kitty_workbench.protocol import (
|
||||
DisplayCmd, ImageCmd, LogCmd, ClearCmd, LayoutCmd, InitCmd, ShutdownCmd,
|
||||
ReadyEvent, ChecklistToggleEvent, ButtonClickEvent, InputSubmitEvent,
|
||||
encode_message, decode_message,
|
||||
)
|
||||
|
||||
|
||||
def test_display_cmd_round_trip():
|
||||
cmd = DisplayCmd(widget="markdown", content="# Hello", pane="main", clear=False)
|
||||
line = encode_message(cmd)
|
||||
decoded = decode_message(line)
|
||||
assert decoded == cmd
|
||||
|
||||
|
||||
def test_init_cmd_round_trip():
|
||||
cmd = InitCmd(project="io102", title="Test Project", image_protocol="sixel")
|
||||
line = encode_message(cmd)
|
||||
decoded = decode_message(line)
|
||||
assert decoded == cmd
|
||||
assert decoded.project == "io102"
|
||||
|
||||
|
||||
def test_checklist_event_round_trip():
|
||||
evt = ChecklistToggleEvent(pane="sidebar", index=2, label="Check R412", checked=True)
|
||||
line = encode_message(evt)
|
||||
decoded = decode_message(line)
|
||||
assert decoded == evt
|
||||
assert decoded.checked is True
|
||||
|
||||
|
||||
def test_ready_event_round_trip():
|
||||
evt = ReadyEvent()
|
||||
line = encode_message(evt)
|
||||
decoded = decode_message(line)
|
||||
assert isinstance(decoded, ReadyEvent)
|
||||
|
||||
|
||||
def test_encode_produces_single_line():
|
||||
cmd = LogCmd(entry="test entry", level="info")
|
||||
line = encode_message(cmd)
|
||||
assert "\n" not in line
|
||||
assert json.loads(line)["cmd"] == "log"
|
||||
|
||||
|
||||
def test_decode_unknown_message_returns_none():
|
||||
result = decode_message('{"cmd": "unknown_thing", "data": 123}')
|
||||
assert result is None
|
||||
Reference in New Issue
Block a user