fix: reject blank unknown delivery destinations too
This commit is contained in:
@@ -134,7 +134,7 @@ class DeliveryTarget:
|
||||
"""Convert back to string format."""
|
||||
if self.is_origin:
|
||||
return "origin"
|
||||
if self.unknown_platform:
|
||||
if self.unknown_platform is not None:
|
||||
return self.unknown_platform
|
||||
if self.platform == Platform.LOCAL:
|
||||
return "local"
|
||||
@@ -168,7 +168,7 @@ class DeliveryRouter:
|
||||
"""Deliver content to all targets; returns per-target results keyed by target string."""
|
||||
results = {}
|
||||
for target in targets:
|
||||
if target.unknown_platform:
|
||||
if target.unknown_platform is not None:
|
||||
results[target.to_string()] = {
|
||||
"success": False, "error": f"unknown_platform: {target.unknown_platform}"}
|
||||
continue
|
||||
|
||||
@@ -9,11 +9,13 @@ from gateway.delivery import DeliveryRouter, DeliveryTarget
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unknown_destination_fails_without_writing_and_local_still_works(tmp_path, monkeypatch):
|
||||
@pytest.mark.parametrize("raw", ["MisspelledPlatform:ChatID:ThreadID", "", " "])
|
||||
async def test_unknown_destination_fails_without_writing_and_local_still_works(tmp_path, monkeypatch, raw):
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
router = DeliveryRouter(GatewayConfig())
|
||||
raw = "MisspelledPlatform:ChatID:ThreadID"
|
||||
result = await router.deliver("must not save", [DeliveryTarget.parse(raw)], job_id="bad")
|
||||
target = DeliveryTarget.parse(raw)
|
||||
raw = raw.strip()
|
||||
result = await router.deliver("must not save", [target], job_id="bad")
|
||||
assert not any(receipt["success"] for receipt in result.values()), result
|
||||
assert raw in result
|
||||
assert result[raw]["error"] == f"unknown_platform: {raw}"
|
||||
|
||||
Reference in New Issue
Block a user