fix(phase1): restore API contract while preserving N+1 optimization

The N+1 optimization in save_image() pre-lowercases the existing_files list
before passing to get_unique_filename(). However, this broke the API contract:
the function should handle any-case input to remain robust.

Changed: get_unique_filename() now defensively lowercases the input list,
ensuring collision detection works regardless of input case.

Benefits:
- Fixes implicit API contract change (function expected any-case input)
- Maintains N+1 optimization (pre-lowercasing still works)
- Supports both optimization and edge cases (direct function calls)
- All 22 tests pass
This commit is contained in:
2026-04-20 22:09:58 +03:00
parent 2951ed81eb
commit 01321bf607

View File

@@ -84,8 +84,10 @@ def get_unique_filename(
# Build the base filename without UUID
base_filename = f"{sanitized_name}_{variant}.jpg"
# Check for collision (existing_files should already be lowercased)
if base_filename.lower() not in existing_files:
# Defensive collision check: handle both pre-lowercased and any-case input
# This maintains backward compatibility while supporting the optimization
existing_lower = [f.lower() for f in existing_files]
if base_filename.lower() not in existing_lower:
# No collision
return base_filename