Spaces:
Paused
Paused
Download tests/test_agent_union.py from mega345evolutions/Ultroid: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/spaces/mega345evolutions/Ultroid/resolve/main/tests/test_agent_union.py
- Command line
-
hf download hf://spaces/mega345evolutions/Ultroid/tests/test_agent_union.py
-
curl -L -o test_agent_union.py https://huggingface.co/spaces/mega345evolutions/Ultroid/resolve/main/tests/test_agent_union.py
3.7 kB
| """The Agent union: no collisions, no singletons, correct layer order.""" | |
| from __future__ import annotations | |
| import asyncio | |
| import pytest | |
| from pyUltroid.agent import ( | |
| Agent, | |
| AgentConfig, | |
| AgentLifecycle, | |
| AgentRuntime, | |
| MiniAI, | |
| ProviderRegistry, | |
| SessionStore, | |
| UltroidAgent, | |
| agent, | |
| miniai, | |
| ) | |
| def test_mro_covers_every_subsystem(): | |
| for cls in ( | |
| AgentRuntime, | |
| MiniAI, | |
| UltroidAgent, | |
| ProviderRegistry, | |
| AgentLifecycle, | |
| SessionStore, | |
| AgentConfig, | |
| ): | |
| assert cls in Agent.__mro__ | |
| def test_weakest_base_is_last(): | |
| """Otherwise the cooperative __init__ unwinds in the wrong order.""" | |
| mro = Agent.__mro__ | |
| assert mro.index(AgentConfig) > mro.index(SessionStore) | |
| assert mro.index(SessionStore) > mro.index(AgentLifecycle) | |
| assert mro.index(AgentLifecycle) > mro.index(ProviderRegistry) | |
| assert mro.index(ProviderRegistry) > mro.index(MiniAI) | |
| def test_constructs(): | |
| assert isinstance(Agent(), Agent) | |
| def test_every_capability_is_reachable(method): | |
| assert hasattr(Agent(), method) | |
| def test_the_two_dangerous_collisions_are_gone_by_construction(): | |
| """These pointed at different databases; one silently won under MRO.""" | |
| a = Agent() | |
| assert a.CONFIG_KEY != a.SESSION_KEY | |
| assert a.CONFIG_KEY == "AGENT_ENV_MIGRATED" | |
| assert a.SESSION_KEY.startswith("AGENT_DM_SESSIONS") | |
| def test_no_shadowing_between_layers(): | |
| """Each name resolves to exactly one class in the MRO.""" | |
| mro = Agent.__mro__ | |
| for name in ("status", "register", "respond", "stream", "run", "set_provider"): | |
| owners = [c.__name__ for c in mro if name in vars(c)] | |
| assert len(owners) <= 1, f"{name} defined on {owners}" | |
| def test_miniai_returns_an_agent(): | |
| result = asyncio.run(miniai()) | |
| assert isinstance(result, Agent) | |
| def test_the_process_agent_is_one_instance(): | |
| assert agent() is agent() | |
| assert isinstance(agent(), Agent) | |
| def test_legacy_provider_registry_facade_uses_the_process_agent(): | |
| from pyUltroid.agent import registry | |
| provider = registry.by_name("gemini") | |
| assert provider is agent().provider_by_name("gemini") | |
| registry.register(provider) | |
| assert registry.by_name("gemini") is provider | |
| def test_there_are_no_module_singletons_left(): | |
| from pyUltroid.agent import _config, _lifecycle, _mini, _providers, _sessions | |
| for module, gone in ( | |
| (_config, ("agent_config", "get_field", "set_field", "_udb", "_var")), | |
| (_sessions, ("session_store", "create_session", "sessions_for", "_udb")), | |
| (_providers, ("registry", "ollama", "cloudflare")), | |
| (_mini, ("mini",)), | |
| (_lifecycle, ("engine_lifecycle",)), | |
| ): | |
| for name in gone: | |
| assert not hasattr(module, name), f"{module.__name__}.{name}" | |
| def test_the_config_var_hook_is_patchable(): | |
| """It was a function-local import, so nothing could reach it.""" | |
| from pyUltroid.agent import _config | |
| assert hasattr(_config, "Var") | |