- config.py/fetch.py: enforce a minimum gap between any requests to HPR's
servers (fetch._wait_for_politeness_gap()), regardless of which
function issues them. Not needed for someone who already understands
HPR's infrastructure, but a real consideration for a future user who
doesn't -- a sweep makes several requests per episode across thousands
of episodes.
- markers.json (version 3): found via the same random-sample-then-
visualize technique used for the earlier hpr4775 fix. hpr2157's era
apparently used the bare 'HPR episode' rather than 'Hacker Public Radio
episode', which fell all the way through to a much weaker sibling-
correlation fallback (3.25s) instead of a proper marker match (now
15.1s); Whisper tiny mis-hearing 'Today's' as 'To its' on hpr3356 broke
the same marker a different way (8.0s -> 26.6s). hpr3356 itself is an
unusual 282-minute special episode that remains correctly flagged for
manual review even after the fix.
- docs/DESIGN.md: corrected an overstated claim ('retry with backoff')
that was never actually implemented; documented the real smoke test
(SIGINT mid-episode, resumed, interrupted again, resumed to
completion -- no lost work, no stray subprocesses, no ledger
corruption) and a real full-corpus timing estimate (32.1s/episode
average on the hardest episode category, so on the order of 1-2 days
for the full archive, not weeks).
- New regression tests for the politeness delay and both marker fixes.
137 lines
7.5 KiB
Python
137 lines
7.5 KiB
Python
"""
|
|
Regression tests for the two real false-positive bugs found while building
|
|
the original prototype (see hpr_stripper/markers.py docstring). These use
|
|
real transcript text observed during development, not synthetic examples,
|
|
specifically so a future change can't silently reintroduce either bug.
|
|
"""
|
|
import unittest
|
|
|
|
from hpr_stripper import markers
|
|
|
|
|
|
class TestIntroDetection(unittest.TestCase):
|
|
def test_modern_episode_stops_after_tts_block(self):
|
|
# hpr3700, real Whisper segmentation.
|
|
segments = [
|
|
("This is Hacker Public Radio Episode 3,700 for Friday the 7th of October 2022.", 0.0, 13.24),
|
|
("Today's show is entitled Introduction to Batch Files.", 13.24, 17.88),
|
|
("It is part of the series DOS.", 17.88, 20.36),
|
|
("It is hosted by AOKA, and is about 15 minutes long.", 20.36, 25.0),
|
|
("It carries a clean flag.", 25.0, 27.12),
|
|
("This summary is More on DOS.", 27.12, 30.44),
|
|
("This time is Introduction to Batch Files.", 30.44, 41.24),
|
|
("Hello, this is AOKA, welcoming you to Hacker Public Radio.", 41.24, 44.92),
|
|
("And another exciting episode in our ongoing DOS series.", 44.92, 49.76),
|
|
]
|
|
self.assertEqual(markers.find_intro_end(segments), 44.92)
|
|
|
|
def test_2026_wording_variant_is_recognized(self):
|
|
# hpr4775, real official SRT -- a wording variant found by visually
|
|
# inspecting a waveform/spectrogram of the clip (see docs/DESIGN.md):
|
|
# "the host is X and the duration is Y" / "the flag is Y, and the
|
|
# license is Z" replaced the older "is hosted by" / "it carries a
|
|
# clean flag" phrasing. The old marker set stopped matching after
|
|
# segment 2 (16.4s) and silently under-trimmed; it must now reach
|
|
# the real boundary at 27.32s.
|
|
segments = [
|
|
("This is Hacker Public Radio Episode 4775, for 2026-11-20", 0.0, 13.2),
|
|
('Today\'s show is entitled, "BruCON interview 4: northstar: robots and AI"', 13.2, 16.4),
|
|
("The host is Kristoff and the duration is 00:24:05", 16.4, 20.04),
|
|
("The flag is Clean, and the license is CC-BY-SA", 20.04, 22.08),
|
|
('The summary is "Kristoff talks to Achraf of Northstar about how AI is makes robotics accessable for everybody"', 22.08, 27.32),
|
|
("I, everybody, welcome to exciting new episode of Hacker Public Radio, my name is Christof.", 40.0, 46.52),
|
|
]
|
|
self.assertEqual(markers.find_intro_end(segments), 27.32)
|
|
|
|
def test_2015_2020_template_with_bare_hpr_abbreviation(self):
|
|
# hpr2157, real Whisper tiny transcription. This era's template
|
|
# apparently says the bare "HPR episode" rather than "Hacker
|
|
# Public Radio episode"; Whisper also mis-heard "is part" as "in
|
|
# part" here specifically. Found via a waveform inspection after a
|
|
# metadata_arithmetic disagreement flag (84.2s vs 3.2s) pointed at
|
|
# this episode; the old marker set matched nothing in segment 0
|
|
# and returned None immediately, falling through to a much worse
|
|
# sibling-correlation guess (3.25s) instead of the real ~37.6s
|
|
# boundary.
|
|
segments = [
|
|
("This in HPR episode 2,157 entitled Markham Manchester Part 3, and in part of the series, Interviews.", 0.0, 8.1),
|
|
("It is posted by Tony H1,212, and in about 8 minutes long.", 8.1, 14.0),
|
|
("The summary is.", 14.0, 15.1),
|
|
("This in an Interview with Alononovo, which I did at Markham Manchester.", 15.1, 19.8),
|
|
("This episode of HPR is brought to you by An Honest Host at Come.", 19.8, 24.3),
|
|
("Get 15% discount on all shared hosting with the offer code HPR-15.", 24.3, 30.6),
|
|
("That's HPR-15.", 30.6, 33.1),
|
|
("Better web hosting that's Honest and Fair at An Honest Host.com.", 33.1, 37.6),
|
|
]
|
|
self.assertIsNotNone(markers.find_intro_end(segments))
|
|
|
|
def test_todays_misheard_as_to_its(self):
|
|
# hpr3356: Whisper tiny heard "Today's show is entitled" as "To
|
|
# its show is entitled", breaking the marker on segment 1 even
|
|
# though segment 0 matched fine.
|
|
segments = [
|
|
("This is Hacker Public Radio episode, 3,356 Formundi, 14 June 2021.", 0.0, 8.0),
|
|
("To its show is entitled, HPR 2020, 2021 New Year's Eve, Show Episode 5.", 8.0, 15.5),
|
|
]
|
|
self.assertEqual(markers.find_intro_end(segments), 15.5)
|
|
|
|
def test_organic_cold_open_is_not_mistaken_for_tts_boilerplate(self):
|
|
# hpr0500: the host's own greeting happens to say "this is Hacker
|
|
# Public Radio", but there is no actual TTS metadata announcement.
|
|
# Bug: a loose fuzzy match on the "welcome to HPR" greeting line
|
|
# alone used to trigger a false intro_end here.
|
|
segments = [
|
|
("Hi everyone, this is Klaatu and this is Hacker Public Radio, year review number two,", 0.0, 23.0),
|
|
("where we could call it around table, so I have it done around table in like three months.", 23.0, 27.0),
|
|
("On the call is Enigma.", 27.0, 29.0),
|
|
]
|
|
self.assertIsNone(markers.find_intro_end(segments))
|
|
|
|
def test_greeting_alone_never_starts_a_run(self):
|
|
# A "welcome to HPR" line with nothing stronger around it must not
|
|
# be trusted on its own, even in isolation. (Deliberately avoids
|
|
# the literal substring "hacker public radio episode", which is a
|
|
# *strong* marker on its own -- this text must only be able to
|
|
# match the "greeting" markers.)
|
|
segments = [("Hello, this is Dan, welcoming you to Hacker Public Radio.", 0.0, 4.0)]
|
|
self.assertIsNone(markers.find_intro_end(segments))
|
|
|
|
|
|
class TestOutroDetection(unittest.TestCase):
|
|
def test_finds_real_outro_marker(self):
|
|
tail_segments = [
|
|
("You can see it on my website or take a look at it if you have the media around yourself.", 0.0, 7.36),
|
|
("This is a hookah for Hacker Public Radio signing off and is always encouraging you to support free software. Bye-bye.", 7.36, 22.76),
|
|
("You have been listening to Hacker Public Radio, as Hacker Public Radio does work.", 22.76, 27.56),
|
|
]
|
|
# Bug: a too-loose fuzzy fallback once matched the host's own
|
|
# sign-off ("...Hacker Public Radio signing off...") against the
|
|
# short marker "hacker public radio does", nearly truncating the
|
|
# host's last sentence. It must match only the real marker,
|
|
# anchored at 22.76 (clip-relative), not inside the sign-off.
|
|
clip_offset = 903.14
|
|
result = markers.find_outro_start(tail_segments, clip_offset)
|
|
self.assertEqual(result, clip_offset + 22.76)
|
|
|
|
def test_host_signoff_alone_does_not_trigger_outro(self):
|
|
tail_segments = [
|
|
("This is a hookah for Hacker Public Radio signing off and is always encouraging you to support free software. Bye-bye.", 0.0, 15.4),
|
|
]
|
|
self.assertIsNone(markers.find_outro_start(tail_segments, 0.0))
|
|
|
|
|
|
class TestFuzzyContains(unittest.TestCase):
|
|
def test_strong_markers_never_use_fuzzy_fallback(self):
|
|
# "is hosted by" is a strong marker (3 words); it must not fuzzy-match
|
|
# unrelated text that merely shares a couple of words.
|
|
self.assertFalse(
|
|
markers.fuzzy_contains(["is hosted by"], "this show is mostly hosted wherever", min_words_for_fuzzy=100)
|
|
)
|
|
|
|
def test_exact_substring_always_matches(self):
|
|
self.assertTrue(markers.fuzzy_contains(["minutes long"], "and is about 15 minutes long today"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|