mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 20:14:36 +00:00
After the architecture settled on always using an independent Box Runtime service, several pieces of compatibility code and design shortcuts were left behind. This commit cleans them up: - Remove `LocalBoxRuntimeClient` and `create_box_runtime_client` from production code (moved to test-only helper). - Remove unused `_clip_bytes` method from backend. - Remove `__langbot_session_placeholder__` hack by making `BoxSpec.cmd` default to empty and validating non-empty only in `runtime.execute()`. - Extract `get_box_config()` helper to eliminate 5× duplicated config access boilerplate. - Remove `session_id`/`host_path`/`host_path_mode` from the LLM-facing tool schema to enforce request-scoped session isolation. - Fix dual shutdown path: `NativeToolLoader.shutdown()` no longer calls `box_service.shutdown()` (handled by `Application.dispose()`). - Simplify `_assert_session_compatible` with a loop. - Inline client creation in `BoxRuntimeConnector`. - Remove redundant `BOX__RUNTIME_URL` env var from docker-compose (auto-detected by code). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from langbot.pkg.box.backend import CLISandboxBackend, _MAX_RAW_OUTPUT_BYTES
|
|
|
|
|
|
class TestClipCapturedBytes:
|
|
def test_within_limit_unchanged(self):
|
|
data = b'hello world'
|
|
result = CLISandboxBackend._clip_captured_bytes(data, total_size=len(data), limit=1024)
|
|
assert result == 'hello world'
|
|
|
|
def test_exceeding_limit_clips_and_appends_notice(self):
|
|
captured = b'A' * 100
|
|
total_size = 200
|
|
result = CLISandboxBackend._clip_captured_bytes(captured, total_size=total_size, limit=100)
|
|
assert result.startswith('A' * 100)
|
|
assert 'raw output clipped at 100 bytes' in result
|
|
assert '100 bytes discarded' in result
|
|
|
|
def test_exact_limit_not_clipped(self):
|
|
data = b'B' * 100
|
|
result = CLISandboxBackend._clip_captured_bytes(data, total_size=100, limit=100)
|
|
assert result == 'B' * 100
|
|
assert 'clipped' not in result
|
|
|
|
def test_default_limit_is_module_constant(self):
|
|
data = b'x' * 10
|
|
result = CLISandboxBackend._clip_captured_bytes(data, total_size=10)
|
|
assert result == 'x' * 10
|
|
assert _MAX_RAW_OUTPUT_BYTES == 1_048_576
|
|
|
|
def test_invalid_utf8_replaced(self):
|
|
data = b'ok\xff\xfetail'
|
|
result = CLISandboxBackend._clip_captured_bytes(data, total_size=len(data), limit=1024)
|
|
assert 'ok' in result
|
|
assert 'tail' in result
|