Files
LangBot/tests/e2e/test_runner_availability.py
Type_rBody 628525947f feat(deps): support Python 3.14
Support Python 3.14 (`requires-python` stays `>=3.11`).

Installing on 3.14 needs a newer `chromadb`, so tighten it to `>=1.5.3`: the
first release to drop the Pydantic v1 shim for 3.14. Its 1.5.x wheels are
`cp39-abi3`, and it leaves `onnxruntime` to the resolver, which picks a
`cp314` wheel on 3.14. Pinning onnxruntime would need re-pinning per chromadb
release.

Also fixed, because 3.14 exposed them:
- E2E used `with sqlite3.connect(...)`, a transaction context manager that never
  closes; the unclosed-database ResourceWarning landed in the next test's setup
  and pytest.ini makes it fatal. Switched to `contextlib.closing`.
- 3.14 parks `asyncio.shield`'s `_log_on_exception` on the cancelled inner task
  and logs the raw repr, bypassing the SDK's `_safe_error` redaction and echoing
  the workspace API key. Detach it after the cancel.
- Two tests asserted scheduling order that 3.14 changed (deadline cancellation,
  heartbeat lane order).
2026-11-20 01:56:55 +08:00

73 lines
3.0 KiB
Python

"""Runner availability through a real Host, SDK runtime and HTTP pipeline."""
# Imported pytest fixtures are injected by name.
# ruff: noqa: F811
import json
import contextlib
import sqlite3
import zipfile
import pytest
from tests.e2e.test_runner_plugin_runtime import ( # noqa: F401
_create_boundary_pipeline,
_init_and_auth,
_install_qa_plugin,
runner_client,
runner_e2e_config_path,
runner_e2e_port,
runner_e2e_tmpdir,
runner_langbot_process,
runner_runtime_ports,
runner_runtime_process,
)
pytestmark = pytest.mark.e2e
def test_message_during_plugin_initialization(runner_client, runner_e2e_tmpdir):
token = _init_and_auth(runner_client)
pipeline_id = _create_boundary_pipeline(runner_client, token)
original = runner_e2e_tmpdir / 'agent-runner-qa.zip'
delayed = runner_e2e_tmpdir / 'delayed-runner.zip'
with zipfile.ZipFile(original) as source, zipfile.ZipFile(delayed, 'w') as target:
for item in source.infolist():
content = source.read(item.filename)
if item.filename == 'main.py':
content = content.replace(b' pass', b' import asyncio\n await asyncio.sleep(5)')
target.writestr(item, content)
_install_qa_plugin(runner_client, token, delayed)
response = runner_client.post(
f'/api/v1/pipelines/{pipeline_id}/run',
headers={'Authorization': f'Bearer {token}'},
json={'message': 'initialization window'},
).json()
print(json.dumps(response, ensure_ascii=False))
assert response['code'] == 0, response
assert response['data']['status'] == 'completed', response
def test_missing_local_agent_has_recovery_hint(runner_client, runner_e2e_tmpdir):
token = _init_and_auth(runner_client)
pipeline_id = _create_boundary_pipeline(runner_client, token)
headers = {'Authorization': f'Bearer {token}'}
config = runner_client.get(f'/api/v1/pipelines/{pipeline_id}', headers=headers).json()['data']['pipeline']['config']
runner_id = 'plugin:langbot-team/LocalAgent/default'
config['ai']['runner']['id'] = runner_id
config['ai']['runner_config'] = {runner_id: {}}
saved = runner_client.put(f'/api/v1/pipelines/{pipeline_id}', headers=headers, json={'config': config}).json()
assert saved['code'] == 0, saved
response = runner_client.post(
f'/api/v1/pipelines/{pipeline_id}/run', headers=headers, json={'message': 'missing plugin'}
).json()
print(json.dumps(response, ensure_ascii=False))
assert response['code'] == 0, response
assert response['data']['status'] == 'failed', response
assert 'Plugins' in response['data']['reply'], response
with contextlib.closing(sqlite3.connect(runner_e2e_tmpdir / 'data' / 'langbot.db')) as connection:
errors = connection.execute(
'SELECT error_message FROM monitoring_errors WHERE pipeline_id = ?', (pipeline_id,)
).fetchall()
assert any('not installed in this Workspace' in row[0] for row in errors), errors