Discovery
Surfaced during #4522 (schema correction tests) and documented in `autobot-backend/conftest.py`.
Importing anything from `chat_workflow/` in a test triggers the module-level imports in `chat_workflow/init.py`:
```python
from .manager import ChatWorkflowManager # pulls in Redis, LLM clients, ...
from .models import WorkflowSession
from .graph import ChatState, build_chat_graph, get_compiled_graph # LangGraph metaclasses
```
The LangGraph `.graph` import causes a metaclass conflict in the test environment. Even though it is wrapped in `try/except ImportError`, the conflict surfaces as a runtime `TypeError` rather than an `ImportError`.
Impact
Any test that imports a module from `chat_workflow/` (e.g. `tool_handler`, `cot_events`, `models`) cannot do so via the normal package path. The `#4522` test used this workaround:
```python
import importlib.util
_spec = importlib.util.spec_from_file_location(
"chat_workflow.tool_handler",
str(_th_path)
)
_th_mod = importlib.util.module_from_spec(_spec)
_th_mod.package = "chat_workflow"
_spec.loader.exec_module(_th_mod)
```
This is fragile, obscures import errors, and makes tests harder to write and maintain. The same pattern is documented in `autobot-backend/conftest.py`.
Fix needed
Make `chat_workflow/init.py` test-friendly by deferring heavy imports:
- Remove module-level `from .manager import ChatWorkflowManager` — expose it via lazy getter only (`get_chat_workflow_manager` already exists)
- Keep the `try/except` LangGraph block but gate it behind an `AUTOBOT_ENABLE_GRAPH` env flag or move it into `build_chat_graph()` itself
- Update `all` to import lazily or remove from top-level exports
Tests should be able to `from chat_workflow.tool_handler import ToolHandler` without side effects.
Discovered during post-implementation review of #4522.
Discovery
Surfaced during #4522 (schema correction tests) and documented in `autobot-backend/conftest.py`.
Importing anything from `chat_workflow/` in a test triggers the module-level imports in `chat_workflow/init.py`:
```python
from .manager import ChatWorkflowManager # pulls in Redis, LLM clients, ...
from .models import WorkflowSession
from .graph import ChatState, build_chat_graph, get_compiled_graph # LangGraph metaclasses
```
The LangGraph `.graph` import causes a metaclass conflict in the test environment. Even though it is wrapped in `try/except ImportError`, the conflict surfaces as a runtime `TypeError` rather than an `ImportError`.
Impact
Any test that imports a module from `chat_workflow/` (e.g. `tool_handler`, `cot_events`, `models`) cannot do so via the normal package path. The `#4522` test used this workaround:
```python
import importlib.util
_spec = importlib.util.spec_from_file_location(
"chat_workflow.tool_handler",
str(_th_path)
)
_th_mod = importlib.util.module_from_spec(_spec)
_th_mod.package = "chat_workflow"
_spec.loader.exec_module(_th_mod)
```
This is fragile, obscures import errors, and makes tests harder to write and maintain. The same pattern is documented in `autobot-backend/conftest.py`.
Fix needed
Make `chat_workflow/init.py` test-friendly by deferring heavy imports:
Tests should be able to `from chat_workflow.tool_handler import ToolHandler` without side effects.
Discovered during post-implementation review of #4522.