test: cover the 1.6.1 provenance work where it was assumed, not asserted

Four parsers (dvdsub, flac, lpcm, mpegaudio) stamp a source offset on
every frame but had no test that read one back, so a regression to
`source: None` would have been caught only by the brace-balanced audit
in codec/mod.rs — a lint, not a behavioural check. Each now asserts the
emitted frame carries the offset of the packet that supplied its first
byte.

The Blu-ray feed spans had no direct test at all. Add one that walks a
multi-item playlist and requires the spans to tile the feed with no gap
or overlap; it catches a one-sector-per-clip drift, which is exactly the
error class that would misattribute frames near a seam.

`no_provenance_still_places_by_marks` asserted only that placement
returned something, which passes for a frame placed in the wrong clip.
Its probe timestamp lands in an overlap between two clips in the real
mark table, so pinning one clip would assert a coin-flip; instead
require the offset to be one that a clip actually containing that
timestamp would produce.
This commit is contained in:
Matthew Jackson
2026-08-07 22:16:02 -07:00
parent 42c62d46b6
commit 418abfe79e
6 changed files with 215 additions and 2 deletions
+18
View File
@@ -717,4 +717,22 @@ mod tests {
let result = format_palette(&[[0x00, 16, 128, 128]], 0, 0);
assert_eq!(String::from_utf8(result).unwrap(), "palette: 101010\n");
}
/// The text guard in `codec/mod.rs` scans for a literal `source: None` and
/// cannot see a parser that writes `source: facts.source` where the facts
/// carry no offset. Only a runtime check proves an emitted frame really
/// carries the byte it was read from, and without it a multi-clip title
/// places this track by timestamp inference instead of by byte.
#[test]
fn an_emitted_frame_carries_the_packets_source_offset() {
let mut parser = DvdSubParser::new(None);
let mut pes = make_pes(
vec![0x00, 0x0A, 0x00, 0x08, 0x01, 0xFF, 0x02, 0x03, 0x04, 0x05],
Some(90_000),
);
pes.source = Some(crate::pes::SourcePos::at_byte(7_777));
let frames = parser.parse(&pes);
assert!(!frames.is_empty(), "the segment is emitted");
assert_eq!(frames[0].source.map(|s| s.byte), Some(7_777));
}
}
+15
View File
@@ -271,4 +271,19 @@ mod tests {
);
assert_eq!(emitted.len() + tail.len(), 2);
}
/// The text guard in `codec/mod.rs` scans for a literal `source: None` and
/// cannot see a parser that writes `source: facts.source` where the facts
/// carry no offset. Only a runtime check proves an emitted frame really
/// carries the byte it was read from, and without it a multi-clip title
/// places this track by timestamp inference instead of by byte.
#[test]
fn an_emitted_frame_carries_the_packets_source_offset() {
let mut p = FlacParser::new();
let mut pes = make_pes(make_flac_frame(100), Some(90_000));
pes.source = Some(crate::pes::SourcePos::at_byte(7_777));
let f = p.parse(&pes);
assert!(!f.is_empty(), "the frame is emitted");
assert_eq!(f[0].source.map(|s| s.byte), Some(7_777));
}
}
+17
View File
@@ -279,4 +279,21 @@ mod tests {
let f = parser.parse(&make_pes(vec![0xAA, 0xBB], None));
assert_eq!(f[0].pts_ns, 0);
}
/// The text guard in `codec/mod.rs` scans for a literal `source: None` and
/// cannot see a parser that writes `source: facts.source` where the facts
/// carry no offset. Only a runtime check proves an emitted frame really
/// carries the byte it was read from, and without it a multi-clip title
/// places this track by timestamp inference instead of by byte.
#[test]
fn an_emitted_frame_carries_the_packets_source_offset() {
let mut parser = LpcmParser::new();
let mut data = vec![0x00, 0x01, 0x00, 0b1001_0001];
data.extend_from_slice(&[0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE]);
let mut pes = make_pes(data, Some(90_000));
pes.source = Some(crate::pes::SourcePos::at_byte(7_777));
let frames = parser.parse(&pes);
assert!(!frames.is_empty(), "the frame is emitted");
assert_eq!(frames[0].source.map(|s| s.byte), Some(7_777));
}
}
+15
View File
@@ -319,4 +319,19 @@ mod tests {
// a manufactured tail frame would break this even if it were non-empty.
assert_eq!(emitted.len() + tail.len(), 2);
}
/// The text guard in `codec/mod.rs` scans for a literal `source: None` and
/// cannot see a parser that writes `source: facts.source` where the facts
/// carry no offset. Only a runtime check proves an emitted frame really
/// carries the byte it was read from, and without it a multi-clip title
/// places this track by timestamp inference instead of by byte.
#[test]
fn an_emitted_frame_carries_the_packets_source_offset() {
let mut p = MpegAudioParser::new();
let mut pes = make_pes(mp3_frame(400), Some(90_000));
pes.source = Some(crate::pes::SourcePos::at_byte(7_777));
let f = p.parse(&pes);
assert!(!f.is_empty(), "the frame is emitted");
assert_eq!(f[0].source.map(|s| s.byte), Some(7_777));
}
}
+42 -2
View File
@@ -1044,6 +1044,21 @@ mod tests {
/// Clips with byte spans, built from the real mark table so provenance and
/// marks can be tested against each other.
/// The output offset `from_clips` computes for a clip: the sum of every
/// earlier clip's playable duration, minus its own IN.
fn plan_offset_for(clips: &[crate::disc::Clip], want: &crate::disc::Clip) -> i64 {
let mut cum = 0i64;
for c in clips {
let in_ns = mpls_ticks_to_ns(c.in_time);
let out_ns = mpls_ticks_to_ns(c.out_time);
if c.clip_id == want.clip_id && c.in_time == want.in_time {
return cum;
}
cum += out_ns - in_ns;
}
cum
}
fn clips_with_spans() -> Vec<crate::disc::Clip> {
let mut clips = seamless_branching_clips();
// Each clip's stream occupies a contiguous run of the feed. Sizes are
@@ -1171,9 +1186,34 @@ mod tests {
fn no_provenance_still_places_by_marks() {
let clips = clips_with_spans();
let mut plan = SeamPlan::from_clips(&clips).expect("plan");
// `is_some()` alone was the whole assertion here, which passes for a
// frame placed in the WRONG clip — on the one path taken whenever a
// source stamps no offset.
//
// This timestamp sits in the OVERLAP of two clips in the real mark
// table, which is precisely the ambiguity provenance exists to settle,
// so pinning one specific clip would be asserting the coin-flip. The
// invariant that holds either way: the frame is placed with the offset
// of a clip whose marks actually contain it — never a clip it does not
// belong to, and never at the head of the timeline.
let raw = 7_900_000_000_000i64;
let placed = plan
.place(raw, 0, true, None)
.expect("a frame with no source offset must still be placed");
let candidates: Vec<i64> = clips
.iter()
.filter(|c| raw >= mpls_ticks_to_ns(c.in_time) && raw <= mpls_ticks_to_ns(c.out_time))
.map(|c| raw - mpls_ticks_to_ns(c.in_time) + plan_offset_for(&clips, c))
.collect();
assert!(
plan.place(7_900_000_000_000, 0, true, None).is_some(),
"a frame with no source offset must still be placed"
!candidates.is_empty(),
"fixture check: the probe timestamp must sit inside at least one clip"
);
assert!(
candidates.contains(&placed),
"placed at {placed}, but no clip containing this timestamp maps it there \
(candidates {candidates:?}) — a frame was given a clip it does not belong to"
);
}