Skip to content

Commit 86fa65a

Browse files
committed
x
1 parent eaa8f7d commit 86fa65a

File tree

1 file changed

+88
-0
lines changed
  • libs/standard-tests/langchain_tests/integration_tests

1 file changed

+88
-0
lines changed

libs/standard-tests/langchain_tests/integration_tests/sandboxes.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,47 @@ def test_read_binary_file(
152152
assert result.file_data["encoding"] == "base64"
153153
assert base64.b64decode(result.file_data["content"]) == raw_bytes
154154

155+
def test_read_binary_file_100_kib(
156+
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
157+
) -> None:
158+
"""Read should return base64 content for a 100 KiB binary file."""
159+
if not self.has_sync:
160+
pytest.skip("Sync tests not supported.")
161+
162+
test_path = self.sandbox_path("binary_100kib.png", root_dir=sandbox_test_root)
163+
chunk = bytes(range(256))
164+
raw_bytes = chunk * 400
165+
166+
sandbox_backend.upload_files([(test_path, raw_bytes)])
167+
result = sandbox_backend.read(test_path)
168+
169+
assert isinstance(result, ReadResult)
170+
assert result.error is None
171+
assert result.file_data is not None
172+
assert result.file_data["encoding"] == "base64"
173+
assert base64.b64decode(result.file_data["content"]) == raw_bytes
174+
175+
def test_read_binary_file_1_mib_returns_error(
176+
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
177+
) -> None:
178+
"""Read should error when a binary file exceeds the preview size limit."""
179+
if not self.has_sync:
180+
pytest.skip("Sync tests not supported.")
181+
182+
test_path = self.sandbox_path("binary_1mib.png", root_dir=sandbox_test_root)
183+
chunk = bytes(range(256))
184+
raw_bytes = chunk * 4096
185+
186+
sandbox_backend.upload_files([(test_path, raw_bytes)])
187+
result = sandbox_backend.read(test_path)
188+
189+
assert isinstance(result, ReadResult)
190+
assert result.file_data is None
191+
assert (
192+
result.error
193+
== f"File '{test_path}': Binary file exceeds maximum preview size of 512000 bytes"
194+
)
195+
155196
def test_edit_single_occurrence(
156197
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
157198
) -> None:
@@ -1724,6 +1765,53 @@ async def test_aread_binary_image_file(
17241765
assert result.file_data["encoding"] == "base64"
17251766
assert base64.b64decode(result.file_data["content"]) == raw_bytes
17261767

1768+
async def test_aread_binary_file_100_kib(
1769+
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
1770+
) -> None:
1771+
"""Async read should return base64 content for a 100 KiB binary file."""
1772+
if not self.has_async:
1773+
pytest.skip("Async tests not supported.")
1774+
1775+
test_path = self.sandbox_path(
1776+
"async_binary_100kib.png", root_dir=sandbox_test_root
1777+
)
1778+
chunk = bytes(range(256))
1779+
raw_bytes = chunk * 400
1780+
1781+
upload_responses = await sandbox_backend.aupload_files([(test_path, raw_bytes)])
1782+
assert upload_responses == [FileUploadResponse(path=test_path, error=None)]
1783+
1784+
result = await sandbox_backend.aread(test_path)
1785+
assert isinstance(result, ReadResult)
1786+
assert result.error is None
1787+
assert result.file_data is not None
1788+
assert result.file_data["encoding"] == "base64"
1789+
assert base64.b64decode(result.file_data["content"]) == raw_bytes
1790+
1791+
async def test_aread_binary_file_1_mib_returns_error(
1792+
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
1793+
) -> None:
1794+
"""Async read should error when a binary file exceeds the preview size limit."""
1795+
if not self.has_async:
1796+
pytest.skip("Async tests not supported.")
1797+
1798+
test_path = self.sandbox_path(
1799+
"async_binary_1mib.png", root_dir=sandbox_test_root
1800+
)
1801+
chunk = bytes(range(256))
1802+
raw_bytes = chunk * 4096
1803+
1804+
upload_responses = await sandbox_backend.aupload_files([(test_path, raw_bytes)])
1805+
assert upload_responses == [FileUploadResponse(path=test_path, error=None)]
1806+
1807+
result = await sandbox_backend.aread(test_path)
1808+
assert isinstance(result, ReadResult)
1809+
assert result.file_data is None
1810+
assert (
1811+
result.error
1812+
== f"File '{test_path}': Binary file exceeds maximum preview size of 512000 bytes"
1813+
)
1814+
17271815
async def test_aupload_adownload_large_file_roundtrip(
17281816
self, sandbox_backend: SandboxBackendProtocol, sandbox_test_root: str
17291817
) -> None:

0 commit comments

Comments
 (0)