import asyncio import json from tamq import service from tamq.service import Service from tamq.store import Store def test_send_rejects_unknown_target(tmp_path, monkeypatch): monkeypatch.setattr(service, "validate_targets", lambda repos: (_ for _ in ()).throw(service.RegistryError("unknown"))) async def run(): socket = tmp_path / "tamq.sock" instance = Service(socket, Store(tmp_path / "queue.sqlite3")) server = await asyncio.start_unix_server(instance.handle, path=str(socket)) try: reader, writer = await asyncio.open_unix_connection(str(socket)) writer.write(b'{"op":"send","sender_repo":"a","target_repo":"missing","body":"hello"}\n'); await writer.drain() assert json.loads(await reader.readline())["ok"] is False writer.close(); await writer.wait_closed() finally: server.close(); await server.wait_closed(); instance.close() asyncio.run(run())