import pytest
from cpex import PluginManager
def _build_generic_payload(value: dict) -> dict:
return value
@pytest.mark.asyncio
async def test_flat_dict_round_trip(manager: PluginManager):
payload = {"key": "value", "num": 42, "flag": True}
result = await manager.invoke_hook("custom.hook", payload)
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_nested_dict_round_trip(manager: PluginManager):
payload = {"outer": {"inner": [1, 2, 3]}, "text": "hello"}
result = await manager.invoke_hook("custom.hook", payload)
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_mixed_scalar_types(manager: PluginManager):
payload = {"b": True, "i": 7, "f": 3.14, "s": "text", "n": None}
result = await manager.invoke_hook("custom.hook", payload)
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_empty_dict(manager: PluginManager):
result = await manager.invoke_hook("custom.hook", {})
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_empty_list_in_payload(manager: PluginManager):
result = await manager.invoke_hook("custom.hook", {"items": []})
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_nesting_at_128_levels_succeeds(manager: PluginManager):
payload: dict = {}
current = payload
for _ in range(128): current["child"] = {}
current = current["child"]
result = await manager.invoke_hook("custom.hook", payload)
assert result.continue_processing is True
@pytest.mark.asyncio
async def test_nesting_at_129_levels_raises(manager: PluginManager):
payload: dict = {}
current = payload
for _ in range(129): current["child"] = {}
current = current["child"]
with pytest.raises(ValueError, match="nesting exceeds maximum depth"):
await manager.invoke_hook("custom.hook", payload)
@pytest.mark.asyncio
async def test_non_string_key_raises(manager: PluginManager):
bad_payload = {1: "value"} with pytest.raises((ValueError, TypeError)):
await manager.invoke_hook("custom.hook", bad_payload)
@pytest.mark.asyncio
async def test_unconvertible_type_raises(manager: PluginManager):
bad_payload = {"items": {1, 2, 3}} with pytest.raises(ValueError, match="cannot convert Python object"):
await manager.invoke_hook("custom.hook", bad_payload)