Files
jetson e963ba0cb4 feat: append source clip name to annotated output filename
Output was a fixed name (merged_annotated.mp4) so every download looked
the same. The source clip name is now appended at the back:
merged_annotated_rekap_2026-10-27.mp4

- src/naming.py: annotated_output_name() + source_stem(); client upload
  name wins, stored file name is the fallback (reuse endpoint), unsafe
  chars replaced, stem capped at 80 chars
- src/job.py: Job.source_stem + add_job(source_stem=...); both output
  paths go through the helper
- app.py: capture the sanitized client filename before the collision
  suffix is added
- cli.py: same helper for the CLI output name

Verified live on .93: POST /api/analyze with 'rekap 2026-10-27.mp4' ->
output/job-e0409b05/merged_annotated_rekap_2026-10-27.mp4, download 200.
2026-10-27 11:26:07 +07:00

39 lines
1.2 KiB
Python

"""Output filename helpers (src/naming.py)."""
from src.naming import MAX_STEM, annotated_output_name, source_stem
def test_client_name_wins_over_stored_file_name():
"""The upload name the operator sees wins over the on-disk name."""
assert annotated_output_name("merged_annotated", "/uploads/clip_1.mp4", "clip") == (
"merged_annotated_clip.mp4"
)
def test_falls_back_to_stored_file_name():
"""No client name (reuse endpoint) -> stored file name is used."""
assert annotated_output_name("merged_annotated", "/uploads/clip_1.mp4") == (
"merged_annotated_clip_1.mp4"
)
def test_extension_is_dropped():
assert source_stem("/uploads/clip.mp4") == "clip"
def test_unsafe_characters_are_replaced():
assert source_stem("/uploads/my clip!.mp4") == "my_clip"
def test_long_stem_is_truncated():
stem = source_stem("/uploads/" + "a" * 200 + ".mp4")
assert len(stem) == MAX_STEM
def test_empty_stem_falls_back_to_base_name():
assert annotated_output_name("merged_annotated", "") == "merged_annotated.mp4"
def test_extension_is_configurable():
assert annotated_output_name("out", "/uploads/clip.mp4", ext=".mkv") == "out_clip.mkv"