Files
hpr-intro-stripper/tests/test_cli_trim_errors.py
Lee Hanken 3a1c996732 Fix sibling-correlation aggregation, trim's silent no-op, and tidy format/precision docs
- detect.py: _best_sibling_estimate() replaces a median/consensus across
  neighbouring episodes with the best match found. Found directly on a
  user-reported case (hpr0400): its three closest neighbours correlated
  at ~0 since they don't share this episode's specific jingle variant,
  but a fourth matched cleanly at 29.25s -- the median discarded that
  real evidence because it was outvoted by neighbours that simply aren't
  relevant, not because the intro genuinely doesn't match anything. Only
  the case where nothing nearby correlates at all is still flagged
  inconclusive.
- cli.py: trim --episode N with no prior detect for that episode used to
  silently do nothing -- no output, no error, exit 0. Now errors clearly
  and tells the user to run detect first; a batch trim over a range still
  treats this as normal and reports a count instead. Also made trim's
  metadata connection lazy, so the error path doesn't need network access
  at all (a test that exercises it dropped from ~4s to instant).
- docs/DESIGN.md: documented both fixes, and the format-default/
  --format/precision fixes from immediately before this round.

New tests: test_sibling_aggregation.py, test_cli_trim_errors.py.
2026-11-22 14:09:20 +00:00

33 lines
1.2 KiB
Python

"""
Regression test: `trim --episode N` without having run `detect` first used
to silently do nothing at all -- no output, no error, exit code 0. An
explicit --episode with no ledger entry is a real mistake, not a normal
part of batch trimming, and should say so plainly.
"""
import os
import subprocess
import sys
import tempfile
import unittest
class TestTrimWithoutDetect(unittest.TestCase):
def test_explicit_episode_with_no_ledger_entry_errors_clearly(self):
with tempfile.TemporaryDirectory() as cache_dir:
# No detect has ever been run, so there is no ledger.db at
# all yet -- this must still produce a clear, actionable
# error rather than crashing on a missing file or silently
# exiting 0.
result = subprocess.run(
[sys.executable, "-m", "hpr_stripper.cli",
"--cache-dir", cache_dir, "trim", "--episode", "999999"],
cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
capture_output=True, text=True,
)
self.assertNotEqual(result.returncode, 0)
self.assertIn("detect --episode 999999", result.stdout + result.stderr)
if __name__ == "__main__":
unittest.main()