mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-26 07:24:20 +00:00
refactor(agent-runner): use sandbox file model
This commit is contained in:
@@ -1510,36 +1510,6 @@ class TestStorageResourcePermissionHelper:
|
||||
assert registry.is_resource_allowed(session, 'storage', 'workspace') is False
|
||||
|
||||
|
||||
class TestFilesResourcePermission:
|
||||
"""Tests for session_registry.is_resource_allowed for files resource type.
|
||||
|
||||
Phase 6: 'files' resource type is now implemented in is_resource_allowed.
|
||||
"""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_files_resource_type_now_implemented(self):
|
||||
"""'files' resource type is now implemented in is_resource_allowed."""
|
||||
from langbot.pkg.agent.runner.session_registry import get_session_registry
|
||||
|
||||
registry = get_session_registry()
|
||||
resources = make_resources(files=[{'file_id': 'file_001'}])
|
||||
|
||||
await registry.register(
|
||||
run_id='run_files_implemented',
|
||||
runner_id='plugin:test/runner/default',
|
||||
query_id=1,
|
||||
plugin_identity='test/runner',
|
||||
resources=resources,
|
||||
)
|
||||
|
||||
session = await registry.get('run_files_implemented')
|
||||
|
||||
# 'files' resource type is now implemented
|
||||
assert registry.is_resource_allowed(session, 'file', 'file_001') is True
|
||||
assert registry.is_resource_allowed(session, 'file', 'file_999') is False
|
||||
|
||||
await registry.unregister('run_files_implemented')
|
||||
|
||||
|
||||
class TestRealActionHandlerSimulation:
|
||||
"""Tests that simulate real RuntimeConnectionHandler action registration and execution.
|
||||
@@ -1797,84 +1767,6 @@ class TestStoragePermissionValidation:
|
||||
await registry.unregister('run_workspace_storage_denied')
|
||||
|
||||
|
||||
class TestFilePermissionValidation:
|
||||
"""Tests for Host-side file permission validation via _validate_run_authorization.
|
||||
|
||||
Phase 6: GET_CONFIG_FILE action now validates file permissions
|
||||
via _validate_run_authorization when run_id is present.
|
||||
"""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_file_allowed_when_in_resources(self):
|
||||
"""_validate_run_authorization allows file when in resources."""
|
||||
from langbot.pkg.agent.runner.session_registry import get_session_registry
|
||||
|
||||
registry = get_session_registry()
|
||||
resources = make_resources(files=[{'file_id': 'file_001'}])
|
||||
|
||||
await registry.register(
|
||||
run_id='run_file_auth',
|
||||
runner_id='plugin:test/runner/default',
|
||||
query_id=1,
|
||||
plugin_identity='test/runner',
|
||||
resources=resources,
|
||||
)
|
||||
|
||||
from langbot.pkg.plugin.handler import _validate_run_authorization
|
||||
|
||||
mock_ap = MagicMock()
|
||||
mock_ap.logger = MagicMock()
|
||||
|
||||
session, error = await _validate_run_authorization(
|
||||
'run_file_auth',
|
||||
'file',
|
||||
'file_001',
|
||||
mock_ap,
|
||||
caller_plugin_identity='test/runner',
|
||||
)
|
||||
|
||||
assert session is not None
|
||||
assert error is None
|
||||
|
||||
await registry.unregister('run_file_auth')
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_file_denied_when_not_in_resources(self):
|
||||
"""_validate_run_authorization denies file when not in resources."""
|
||||
from langbot.pkg.agent.runner.session_registry import get_session_registry
|
||||
|
||||
registry = get_session_registry()
|
||||
resources = make_resources(files=[{'file_id': 'file_001'}])
|
||||
|
||||
await registry.register(
|
||||
run_id='run_file_denied',
|
||||
runner_id='plugin:test/runner/default',
|
||||
query_id=1,
|
||||
plugin_identity='test/runner',
|
||||
resources=resources,
|
||||
)
|
||||
|
||||
from langbot.pkg.plugin.handler import _validate_run_authorization
|
||||
|
||||
mock_ap = MagicMock()
|
||||
mock_ap.logger = MagicMock()
|
||||
mock_ap.logger.warning = MagicMock()
|
||||
|
||||
session, error = await _validate_run_authorization(
|
||||
'run_file_denied',
|
||||
'file',
|
||||
'file_999', # Not in resources
|
||||
mock_ap,
|
||||
caller_plugin_identity='test/runner',
|
||||
)
|
||||
|
||||
assert session is None
|
||||
assert error is not None
|
||||
assert 'not authorized' in error.message.lower()
|
||||
|
||||
await registry.unregister('run_file_denied')
|
||||
|
||||
|
||||
class TestOperationPermissionValidation:
|
||||
"""Tests operation-level Host-side run authorization."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user