Separate input from enter submission in Slack bridge
This commit is contained in:
@@ -46,6 +46,7 @@ class FakePtyManager:
|
||||
self.cli_name = cli_name
|
||||
self._alive = False
|
||||
self.sent_inputs: list[str] = []
|
||||
self.enter_count = 0
|
||||
FakePtyManager.instances.append(self)
|
||||
|
||||
@property
|
||||
@@ -61,6 +62,9 @@ class FakePtyManager:
|
||||
def send(self, text: str) -> None:
|
||||
self.sent_inputs.append(text)
|
||||
|
||||
def send_enter(self) -> None:
|
||||
self.enter_count += 1
|
||||
|
||||
def read_output(self, timeout: float = 5) -> str:
|
||||
return ""
|
||||
|
||||
@@ -143,6 +147,19 @@ def test_handle_message_resets_last_sent_output_after_input(monkeypatch) -> None
|
||||
assert bridge._last_sent_fingerprint is None
|
||||
|
||||
|
||||
def test_handle_message_enter_command_sends_enter_only(monkeypatch) -> None:
|
||||
FakePtyManager.instances.clear()
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
|
||||
bridge._handle_command("start", "codex", "C1")
|
||||
pty = FakePtyManager.instances[-1]
|
||||
|
||||
bridge._handle_message("!enter", "C1")
|
||||
|
||||
assert pty.sent_inputs == []
|
||||
assert pty.enter_count == 1
|
||||
|
||||
|
||||
def test_split_message_preserves_all_content(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
chunks = bridge._split_message("line1\nline2\nline3", max_length=7)
|
||||
|
||||
@@ -13,11 +13,18 @@ class FakeSpawn:
|
||||
def __init__(self, *_args: object, **_kwargs: object) -> None:
|
||||
self.before = ""
|
||||
self._alive = True
|
||||
self.sent: list[str] = []
|
||||
self.sentline: list[str] = []
|
||||
|
||||
def isalive(self) -> bool:
|
||||
return self._alive
|
||||
|
||||
def sendline(self, _text: str) -> None:
|
||||
self.sentline.append(_text)
|
||||
return None
|
||||
|
||||
def send(self, _text: str) -> None:
|
||||
self.sent.append(_text)
|
||||
return None
|
||||
|
||||
def expect(self, *_args: object, **_kwargs: object) -> None:
|
||||
@@ -82,3 +89,33 @@ def test_start_and_stop_attach(monkeypatch: pytest.MonkeyPatch):
|
||||
|
||||
pty.stop()
|
||||
assert not pty.is_alive
|
||||
|
||||
|
||||
def test_send_and_send_enter_are_separated(monkeypatch: pytest.MonkeyPatch):
|
||||
def fake_run(
|
||||
_cmd: Sequence[str],
|
||||
check: bool,
|
||||
capture_output: bool,
|
||||
text: bool,
|
||||
):
|
||||
assert check is False
|
||||
assert capture_output is True
|
||||
assert text is True
|
||||
|
||||
class Result:
|
||||
returncode = 0
|
||||
|
||||
return Result()
|
||||
|
||||
monkeypatch.setattr("lazy_enter.pty_manager.subprocess.run", fake_run)
|
||||
monkeypatch.setattr("lazy_enter.pty_manager.pexpect.spawn", FakeSpawn)
|
||||
|
||||
pty = PtyManager("claude")
|
||||
pty.start()
|
||||
assert pty._process is not None
|
||||
|
||||
pty.send("status")
|
||||
pty.send_enter()
|
||||
|
||||
assert pty._process.sent == ["status"]
|
||||
assert pty._process.sentline == [""]
|
||||
|
||||
Reference in New Issue
Block a user