refactor: improve file splitting performance and code quality

- Use BytesIO for size checking instead of temporary disk writes (major performance improvement)
- Add constant and comment for PDF overhead multiplier in tests
- Address code review feedback

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-10 10:59:39 +00:00
parent ee43687eaa
commit 03222c5ef1
2 changed files with 15 additions and 16 deletions
+5 -3
View File
@@ -79,11 +79,13 @@ class TestSplitPdfBySize:
# If we got more than 1 file, verify each file is under the limit (with some margin for PDF overhead)
if len(split_files) > 1:
# PDF_OVERHEAD_MULTIPLIER: PDFs have structural overhead (headers, metadata, compression)
# that can cause files to exceed the target size by ~20-50%. We allow 1.5x (50%) margin.
PDF_OVERHEAD_MULTIPLIER = 1.5
for split_file in split_files:
# Allow some overhead for PDF structure (up to 50% over limit)
assert (
os.path.getsize(split_file) <= max_size * 1.5
), f"Split file {split_file} should respect size limit"
os.path.getsize(split_file) <= max_size * PDF_OVERHEAD_MULTIPLIER
), f"Split file {split_file} should respect size limit (with PDF overhead allowance)"
# Cleanup split files
for split_file in split_files: