read and write tools, moved schemas to tool/__init__

This commit is contained in:
2026-02-21 14:51:39 -07:00
parent 3085f82179
commit 0cd089894b
5 changed files with 165 additions and 19 deletions
+46
View File
@@ -0,0 +1,46 @@
import asyncio
from unittest.mock import MagicMock
import pytest
from tools.files import read_file, write_file
@pytest.mark.unit
async def test_read_file_with_no_sandbox():
"""Test read_file handles missing sandbox."""
result = await read_file("test.txt", sandbox=None)
assert "error" in result.lower()
@pytest.mark.integration
async def test_real_write_then_read():
"""Integration: Write file, then read it back."""
from sandbox.session import PodmanSandbox
async with PodmanSandbox() as sb:
# Write
result = await write_file("test.txt", "Hello, world!", sb)
assert "" in result
# Read back
content = await read_file("test.txt", sb)
assert "Hello, world!" in content
# Cleanup
await asyncio.to_thread(sb.run, "rm test.txt")
@pytest.mark.integration
async def test_real_write_creates_directories():
"""Integration: write_file creates parent directories."""
from sandbox.session import PodmanSandbox
async with PodmanSandbox() as sb:
result = await write_file("dir1/dir2/test.txt", "nested", sb)
assert "" in result
# Verify file exists
ls_result = await asyncio.to_thread(sb.run, "ls -R")
assert "dir1" in ls_result
assert "dir2" in ls_result