fix(files): treat nonpositive max_batch_file_size_mb as no cap

This commit is contained in:
mateo-berri 2026-08-19 15:05:17 -07:00
parent 2a4598219d
commit 680e4a5736
2 changed files with 7 additions and 1 deletions

View file

@ -108,7 +108,7 @@ def check_batch_file_upload(
) -> BatchFileValidationFailure | None:
if filename is None or not filename.lower().endswith(".jsonl"):
return BatchFileWrongExtension(filename=filename or "")
if max_batch_file_size_mb is not None:
if max_batch_file_size_mb is not None and max_batch_file_size_mb > 0:
size_bytes: Final = _file_size_bytes(file_source)
if size_bytes > max_batch_file_size_mb * _MB:
return BatchFileTooLarge(size_bytes=size_bytes, limit_mb=max_batch_file_size_mb)

View file

@ -69,6 +69,12 @@ def test_no_cap_skips_size_check():
assert check_batch_file_upload("batch.jsonl", content, None) is None
@pytest.mark.parametrize("cap", [0, -3])
def test_nonpositive_cap_disables_size_check(cap):
content = (VALID_LINE + b"\n") * 5000
assert check_batch_file_upload("batch.jsonl", content, cap) is None
@pytest.mark.parametrize("content", [b"", b"\n\n", b" \n\t\n"])
def test_empty_file_rejected(content):
assert check_batch_file_upload("batch.jsonl", content, None) == BatchFileEmpty()