29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
"""Channel unit-test fixtures and environment compatibility patches."""
|
|
|
|
from __future__ import annotations
|
|
|
|
# Some local SQLAlchemy installations do not re-export flag_modified from
|
|
# sqlalchemy.orm, even though SQLAlchemy 2.0 documents it there. Patch it
|
|
# early so channel modules can be imported in test environments.
|
|
import sqlalchemy.orm
|
|
from sqlalchemy.orm.attributes import flag_modified
|
|
|
|
if not hasattr(sqlalchemy.orm, "flag_modified"):
|
|
sqlalchemy.orm.flag_modified = flag_modified
|
|
|
|
|
|
# `yuxi.channel.message.dispatcher` imports `create_agent_run_view` from
|
|
# `yuxi.services.agent_run_service`, which in turn pulls in the heavy and
|
|
# partially-broken `yuxi.agents` / `yuxi.knowledge` import chain in some local
|
|
# environments. Stub the service module early so channel tests can be collected
|
|
# without modifying production source code.
|
|
import sys
|
|
import types
|
|
from unittest.mock import AsyncMock
|
|
|
|
_agent_run_service_pkg = "yuxi.services.agent_run_service"
|
|
if _agent_run_service_pkg not in sys.modules:
|
|
_agent_run_service_mod = types.ModuleType(_agent_run_service_pkg)
|
|
_agent_run_service_mod.create_agent_run_view = AsyncMock()
|
|
sys.modules[_agent_run_service_pkg] = _agent_run_service_mod
|