fix(files): reject oversized reads before loading
This commit is contained in:
committed by
chengyongru
parent
d5658dbc91
commit
cdb2df4982
@@ -99,6 +99,22 @@ class TestReadFileTool:
|
||||
assert len(result) <= ReadFileTool._MAX_CHARS + 500 # small margin for footer
|
||||
assert "Use offset=" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oversized_file_is_rejected_before_read(self, tool, tmp_path, monkeypatch):
|
||||
f = tmp_path / "huge.txt"
|
||||
with f.open("wb") as stream:
|
||||
stream.truncate(ReadFileTool._MAX_FILE_SIZE_BYTES + 1)
|
||||
|
||||
def fail_read_bytes(self):
|
||||
raise AssertionError("oversized file content should not be loaded")
|
||||
|
||||
monkeypatch.setattr(type(f), "read_bytes", fail_read_bytes)
|
||||
|
||||
result = await tool.execute(path=str(f))
|
||||
|
||||
assert "File too large to read" in result
|
||||
assert "Maximum is 100 MiB" in result
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _find_match (unit tests for the helper)
|
||||
|
||||
Reference in New Issue
Block a user