Files
c020627andHarry e053af00af fix(subtitle): never publish a caption file without cues
`write_subtitle_file` replaced its destination with whatever body it was
handed. `subtitle.correct()` builds that body from the cues it managed to merge
against the script, and a script that normalizes to nothing leaves the list
empty, so the helper atomically replaced a complete transcript with a 0-byte
file:

    subtitle.correct(destination, "---")  # also "***", "___", "   ", "[pause: 3s]"

`task.generate_subtitle` then re-reads the staged path, `file_to_subtitles()`
returns [], and the "subtitle file is invalid" branch publishes the finished
video without the captions whisper had already produced -- while
`app/services/subtitle.py:360` still logs `INFO Subtitle corrected`.

Every other caption publication site added in 44e6d5e validates the artifact it
is about to replace: `voice._write_subtitle_items` re-parses the staged file and
requires cues, `task.generate_subtitle` requires parseable cues before its
`os.replace`, and `subtitle.create()` returns early when `not lines`. Only the
shared helper skipped that check, which is what left the correction path as the
one publication that could still destroy published captions. Its regression file
already parametrizes the `correction` writer into the "preserve complete
existing SRT" family, but only covered a failed write.

Enforce the same rule once in the helper: a body without a single `-->` timing
line is a failed write, not a valid empty result. Callers are untouched, and the
empty-correction case now leaves the verbatim transcription on disk so
`task.generate_subtitle` can publish it.

Checked with the source reverted and the new tests kept: 9 failing tests
(4 bodies x 5 correction scripts) and nothing else failing, so the change is a
pure increment. Related suites (`test_media_srt_publication`, `test_subtitle`,
`test_subtitle_background_settings`, `test_subtitle_manual_wrap`,
`test_subtitle_stage_result`, `test_pause_concat_completeness`, `test_task`):
130 passed, 2 skipped, 0 failed. `ruff check` passes and `git diff --check` is
clean.
2026-10-02 16:48:07 +08:00
..