refactor: unify durable event topics

This commit is contained in:
jxxghp
2026-08-24 06:55:50 +08:00
parent 8e669d415e
commit 138a48770c
11 changed files with 172 additions and 64 deletions
+5 -2
View File
@@ -13,8 +13,8 @@
"runtime_to_db": [],
"workflow_to_db": []
},
"edge_count": 6546,
"edge_sha256": "64bd673bda7224d371b91e229d23eeea6ac14655301357a209dff510e30e151b",
"edge_count": 6549,
"edge_sha256": "280799d1a7d3a993096834b5e0f961fcc82319d437b4d5f568c78d8a7bfa07a2",
"edges": [
"app -> app.runtime",
"app -> app.runtime.compat",
@@ -2699,6 +2699,8 @@
"app.application.notification -> app.schemas",
"app.application.notification -> app.schemas.system",
"app.application.notification -> app.schemas.types",
"app.application.outbox -> app.schemas",
"app.application.outbox -> app.schemas.types",
"app.application.plugin.config -> app.schemas",
"app.application.plugin.config -> app.schemas.exception",
"app.application.plugin.folders -> app.application",
@@ -3432,6 +3434,7 @@
"app.chain.transfer -> app.application.directory",
"app.chain.transfer -> app.application.formatting",
"app.chain.transfer -> app.application.history",
"app.chain.transfer -> app.application.outbox",
"app.chain.transfer -> app.application.transfer",
"app.chain.transfer -> app.chain",
"app.chain.transfer -> app.chain._transfer",
+28 -10
View File
@@ -2,6 +2,12 @@
from unittest.mock import patch
import pytest
from app.application.outbox import (
DURABLE_EVENT_TOPICS,
validate_durable_event_handlers,
)
from app.runtime.event.contracts import (
EVENT_CONTRACTS,
EventDelivery,
@@ -69,16 +75,28 @@ def test_invalid_typed_payload_is_diagnostic_only() -> None:
def test_selected_user_side_effects_are_marked_durable_required() -> None:
"""订阅、下载和整理完成事件必须明确暴露后续 durable pilot 要求"""
for event_type in (
EventType.SubscribeAdded,
EventType.SubscribeModified,
EventType.SubscribeDeleted,
EventType.DownloadAdded,
EventType.TransferComplete,
EventType.TransferFailed,
):
assert get_event_contract(event_type).delivery is EventDelivery.DURABLE_REQUIRED
"""所有 durable-required 事件必须一一登记唯一的恢复 topic"""
durable_events = {
event_type
for event_type, contract in EVENT_CONTRACTS.items()
if contract.delivery is EventDelivery.DURABLE_REQUIRED
}
assert set(DURABLE_EVENT_TOPICS) == durable_events
assert len(set(DURABLE_EVENT_TOPICS.values())) == len(durable_events)
def test_durable_event_dispatcher_requires_every_recovery_handler() -> None:
"""恢复 dispatcher 缺少任一登记 topic 时必须在构造边界失败。"""
handlers = {
topic: lambda _message: None
for topic in DURABLE_EVENT_TOPICS.values()
}
validate_durable_event_handlers(handlers)
handlers.pop(next(iter(DURABLE_EVENT_TOPICS.values())))
with pytest.raises(RuntimeError, match="缺少 durable 事件 handler"):
validate_durable_event_handlers(handlers)
def test_download_and_transfer_typed_contracts_accept_legacy_runtime_objects() -> None: