Fix Slack output dedup and chunk forwarding
This commit is contained in:
@@ -45,6 +45,7 @@ class FakePtyManager:
|
||||
self.session_name = session_name
|
||||
self.cli_name = cli_name
|
||||
self._alive = False
|
||||
self.sent_inputs: list[str] = []
|
||||
FakePtyManager.instances.append(self)
|
||||
|
||||
@property
|
||||
@@ -57,8 +58,8 @@ class FakePtyManager:
|
||||
def stop(self) -> None:
|
||||
self._alive = False
|
||||
|
||||
def send(self, _text: str) -> None:
|
||||
return None
|
||||
def send(self, text: str) -> None:
|
||||
self.sent_inputs.append(text)
|
||||
|
||||
def read_output(self, timeout: int = 5) -> str:
|
||||
return ""
|
||||
@@ -104,6 +105,18 @@ def test_start_codex_routes_to_codex_session(monkeypatch) -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_start_session_resets_output_dedup_state(monkeypatch) -> None:
|
||||
FakePtyManager.instances.clear()
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._last_sent_output = "stale"
|
||||
bridge._last_sent_fingerprint = "stale-fp"
|
||||
|
||||
bridge._handle_command("start", "codex", "C1")
|
||||
|
||||
assert bridge._last_sent_output == ""
|
||||
assert bridge._last_sent_fingerprint is None
|
||||
|
||||
|
||||
def test_unknown_target_is_rejected(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
|
||||
@@ -113,3 +126,174 @@ def test_unknown_target_is_rejected(monkeypatch) -> None:
|
||||
"C1",
|
||||
":warning: 지원하지 않는 대상입니다.",
|
||||
)
|
||||
|
||||
|
||||
def test_handle_message_resets_last_sent_output_after_input(monkeypatch) -> None:
|
||||
FakePtyManager.instances.clear()
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
|
||||
bridge._handle_command("start", "codex", "C1")
|
||||
pty = FakePtyManager.instances[-1]
|
||||
bridge._last_sent_output = "previous output"
|
||||
|
||||
bridge._handle_message("status", "C1")
|
||||
|
||||
assert pty.sent_inputs[-1] == "status"
|
||||
assert bridge._last_sent_output == ""
|
||||
assert bridge._last_sent_fingerprint is None
|
||||
|
||||
|
||||
def test_split_message_preserves_all_content(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
chunks = bridge._split_message("line1\nline2\nline3", max_length=7)
|
||||
assert "".join(chunks) == "line1\nline2\nline3"
|
||||
|
||||
|
||||
def test_split_message_preserves_trailing_whitespace_and_blank_line(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
text = "ab \n\ncd "
|
||||
chunks = bridge._split_message(text, max_length=4)
|
||||
assert "".join(chunks) == text
|
||||
|
||||
|
||||
def test_send_output_chunks_sends_multiple_messages(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge._send_output_chunks("1234567890")
|
||||
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", "```\n1234567890\n```"),
|
||||
]
|
||||
|
||||
bridge.config.max_message_length = 4
|
||||
bridge.slack.sent_messages.clear()
|
||||
bridge._send_output_chunks("abcdefghij")
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", "```\nabcd\n```"),
|
||||
("C1", "```\nefgh\n```"),
|
||||
("C1", "```\nij\n```"),
|
||||
]
|
||||
|
||||
|
||||
def test_send_output_chunks_skips_duplicate_snapshot(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 4
|
||||
|
||||
bridge._send_output_chunks("abcdefghij")
|
||||
first = list(bridge.slack.sent_messages)
|
||||
|
||||
bridge._send_output_chunks("abcdefghij")
|
||||
assert bridge.slack.sent_messages == first
|
||||
|
||||
|
||||
def test_send_output_chunks_skips_duplicate_with_volatile_status_line(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 1000
|
||||
|
||||
first_output = (
|
||||
"Would you like to make the following edits?\n"
|
||||
"src/main.py (+68 -1)\n"
|
||||
'odex] 0:node* [0,0] "jihoson-home" 05:12 17-Feb-26\n'
|
||||
"Press enter to confirm or esc to cancel\n"
|
||||
)
|
||||
second_output = (
|
||||
"Would you like to make the following edits?\n"
|
||||
"src/main.py (+68 -1)\n"
|
||||
'odex] 0:node* [0,0] "jihoson-home" 05:13 17-Feb-26\n'
|
||||
"Press enter to confirm or esc to cancel\n"
|
||||
)
|
||||
|
||||
bridge._send_output_chunks(first_output)
|
||||
first = list(bridge.slack.sent_messages)
|
||||
|
||||
bridge._send_output_chunks(second_output)
|
||||
assert bridge.slack.sent_messages == first
|
||||
|
||||
|
||||
def test_send_output_chunks_sends_first_when_fingerprint_is_empty(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
volatile_only = 'odex] 0:node* [0,0] "jihoson-home" 05:12 17-Feb-26\n'
|
||||
|
||||
bridge._send_output_chunks(volatile_only)
|
||||
assert bridge.slack.sent_messages == [("C1", f"```\n{volatile_only.rstrip()}\n```")]
|
||||
|
||||
bridge._send_output_chunks(volatile_only)
|
||||
assert bridge.slack.sent_messages == [("C1", f"```\n{volatile_only.rstrip()}\n```")]
|
||||
|
||||
|
||||
def test_send_output_chunks_keeps_non_tmux_timestamp_lines(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 1000
|
||||
|
||||
first_output = (
|
||||
"report generated at 05:12 17-Feb-26\n"
|
||||
"count=10\n"
|
||||
)
|
||||
second_output = (
|
||||
"report generated at 05:13 17-Feb-26\n"
|
||||
"count=10\n"
|
||||
)
|
||||
|
||||
bridge._send_output_chunks(first_output)
|
||||
bridge._send_output_chunks(second_output)
|
||||
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", f"```\n{first_output.rstrip()}\n```"),
|
||||
("C1", f"```\n{second_output.rstrip()}\n```"),
|
||||
]
|
||||
|
||||
|
||||
def test_send_output_chunks_preserves_whitespace_signals(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 1000
|
||||
|
||||
first_output = "def f():\n return 1\n"
|
||||
second_output = "def f():\n return 1\n"
|
||||
|
||||
bridge._send_output_chunks(first_output)
|
||||
bridge._send_output_chunks(second_output)
|
||||
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", f"```\n{first_output.rstrip()}\n```"),
|
||||
("C1", f"```\n{second_output.rstrip()}\n```"),
|
||||
]
|
||||
|
||||
|
||||
def test_send_output_chunks_keeps_standalone_time_lines(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 1000
|
||||
|
||||
bridge._send_output_chunks("[5:12 AM]\n")
|
||||
bridge._send_output_chunks("[5:13 AM]\n")
|
||||
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", "```\n[5:12 AM]\n```"),
|
||||
("C1", "```\n[5:13 AM]\n```"),
|
||||
]
|
||||
|
||||
|
||||
def test_send_output_chunks_keeps_non_tmux_status_like_lines(monkeypatch) -> None:
|
||||
bridge = _make_bridge(monkeypatch)
|
||||
bridge._channel = "C1"
|
||||
bridge.config.max_message_length = 1000
|
||||
|
||||
first_output = '[2,3] "job-runner" 05:12 17-Feb-26\n'
|
||||
second_output = '[2,3] "job-runner" 05:13 17-Feb-26\n'
|
||||
|
||||
bridge._send_output_chunks(first_output)
|
||||
bridge._send_output_chunks(second_output)
|
||||
|
||||
assert bridge.slack.sent_messages == [
|
||||
("C1", "```\n[2,3] \"job-runner\" 05:12 17-Feb-26\n```"),
|
||||
("C1", "```\n[2,3] \"job-runner\" 05:13 17-Feb-26\n```"),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user