fix(triggers): reject deliveries to disabled channels
This commit is contained in:
@@ -2748,7 +2748,7 @@ def test_gateway_local_trigger_queue_submits_agent_turns(
|
||||
enabled_channels: list[str] = []
|
||||
|
||||
def __init__(self, *_args, **_kwargs) -> None:
|
||||
return None
|
||||
self.channels: dict[str, object] = {}
|
||||
|
||||
async def start_all(self) -> None:
|
||||
await asyncio.Event().wait()
|
||||
@@ -2776,6 +2776,7 @@ def test_gateway_local_trigger_queue_submits_agent_turns(
|
||||
assert kwargs["store"] is agent_kwargs["local_trigger_store"]
|
||||
assert "bus" not in kwargs
|
||||
assert kwargs["submit_turn"] is agent.submit_local_trigger_turn
|
||||
assert kwargs["is_channel_available"]("websocket") is False
|
||||
|
||||
|
||||
def test_gateway_workspace_override_does_not_migrate_legacy_cron(
|
||||
|
||||
@@ -299,6 +299,52 @@ async def test_local_trigger_queue_submits_bound_inbound_message(tmp_path: Path)
|
||||
assert record["trigger_id"] == trigger.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_local_trigger_queue_rejects_unavailable_target_channel(tmp_path: Path) -> None:
|
||||
store = LocalTriggerStore(tmp_path)
|
||||
trigger = store.create(
|
||||
name="PR review",
|
||||
channel="telegram",
|
||||
chat_id="chat-1",
|
||||
session_key="telegram:chat-1",
|
||||
)
|
||||
delivery = store.enqueue(trigger.id, "Review PR #4502")
|
||||
submitted: list[InboundMessage] = []
|
||||
|
||||
async def _submit_turn(msg: InboundMessage):
|
||||
submitted.append(msg)
|
||||
return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id, content="done")
|
||||
|
||||
task = asyncio.create_task(
|
||||
run_local_trigger_queue(
|
||||
store=store,
|
||||
submit_turn=_submit_turn,
|
||||
is_channel_available=lambda name: name == "websocket",
|
||||
poll_interval_s=0.01,
|
||||
)
|
||||
)
|
||||
try:
|
||||
for _ in range(100):
|
||||
stored = store.get(trigger.id)
|
||||
if stored and stored.last_status == "error":
|
||||
break
|
||||
await asyncio.sleep(0.01)
|
||||
finally:
|
||||
task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await task
|
||||
|
||||
stored = store.get(trigger.id)
|
||||
assert submitted == []
|
||||
assert stored is not None
|
||||
assert stored.last_status == "error"
|
||||
assert stored.last_error == "target channel is not enabled: telegram"
|
||||
assert store.claim_deliveries() == []
|
||||
record = _read_run_record(store, delivery.id)
|
||||
assert record["status"] == "error"
|
||||
assert record["error"] == "target channel is not enabled: telegram"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_local_trigger_queue_waits_for_submitted_turn_before_ack(
|
||||
tmp_path: Path,
|
||||
|
||||
Reference in New Issue
Block a user