| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- from __future__ import annotations
- import json
- import subprocess
- import sys
- from pathlib import Path
- PROJECT_ROOT = Path(__file__).parents[1]
- def _run_isolated(code: str) -> dict:
- result = subprocess.run(
- [sys.executable, "-c", code],
- cwd=PROJECT_ROOT,
- check=True,
- capture_output=True,
- text=True,
- )
- return json.loads(result.stdout)
- def test_import_agent_does_not_configure_logging_or_mutate_sys_path() -> None:
- result = _run_isolated(
- """
- import json
- import logging
- import sys
- handlers_before = tuple(logging.getLogger().handlers)
- path_before = tuple(sys.path)
- import agent
- print(json.dumps({
- "handlers_unchanged": tuple(logging.getLogger().handlers) == handlers_before,
- "path_unchanged": tuple(sys.path) == path_before,
- }))
- """
- )
- assert result == {"handlers_unchanged": True, "path_unchanged": True}
- def test_packaged_im_client_is_the_builtin_runtime() -> None:
- result = _run_isolated(
- """
- import json
- from agent.im_client import IMClient
- from agent.tools.builtin.im.chat import IMClient as BuiltinIMClient
- print(json.dumps({"same_client": IMClient is BuiltinIMClient}))
- """
- )
- assert result == {"same_client": True}
|