forge
Explore
Log in

Don't you dare go Hollow

A reindex the entry carries is a step, and it round-trips

Browse files at this commit

4ed8c97e8bac7308796ca0e6af6d8be7a8fca043Ahmet Kaan GümüşParent: 87acb80
  • test
    • a reindex the entry carries is a step, and it round-trips
Show full message
🐛 test(subtitles): a reindex the entry carries is a step, and it round-trips

The app lane's `remove_subtitles` snapshots before it walks the placements
down, and its `Snapshot` carries the palette beside the lanes and the
settings -- so a history step across a reindex is safe, and the old
expectation ("no step survives a reindex the snapshots do not know
about") pins exactly the defect that lane removed. It failed
deterministically on the merged tree.

The test now asserts the round trip it was reaching for: the undo puts
the removed row back and the placement goes on naming the same words,
and the redo takes it off again -- which is where the rest of the test
starts. Lane: lane-bughunt-app.

`cargo test -p engine --test subtitles -- --test-threads=1`: 22 passed.
crates/engine/tests/subtitles.rsmodified+183 -34
@@ -179,7 +179,10 @@ fn a_block_holding_the_erase_after_the_picture_still_draws_the_picture() {
179 179
180 let tracks = subtitle::of_matroska(&file).expect("the walk");180 let tracks = subtitle::of_matroska(&file).expect("the walk");
181 let cue = &tracks[0].cues[0];181 let cue = &tracks[0].cues[0];
182- let image = cue.image.as_ref().expect("the packed block is still a picture");182+ let image = cue
183+ .image
184+ .as_ref()
185+ .expect("the packed block is still a picture");
183 assert_eq!((image.width, image.height), (8, 4));186 assert_eq!((image.width, image.height), (8, 4));
184 let rgba = image.rgba().expect("it decodes");187 let rgba = image.rgba().expect("it decodes");
185 assert_eq!(188 assert_eq!(
@@ -378,7 +381,11 @@ fn a_subtitle_row_can_be_removed_and_the_survivors_round_trip() {
378 .into_owned()381 .into_owned()
379 })382 })
380 .collect();383 .collect();
381- assert_eq!(names, vec!["a.srt", "c.srt"], "the survivors keep their order");384+ assert_eq!(
385+ names,
386+ vec!["a.srt", "c.srt"],
387+ "the survivors keep their order"
388+ );
382 assert_eq!(session.subtitles()[0].cues, expected(), "and their cues");389 assert_eq!(session.subtitles()[0].cues, expected(), "and their cues");
383 390
384 let project = dir.join("cut.edith");391 let project = dir.join("cut.edith");
@@ -397,7 +404,12 @@ fn a_subtitle_row_can_be_removed_and_the_survivors_round_trip() {
397 assert_eq!(404 assert_eq!(
398 back.subtitles()405 back.subtitles()
399 .iter()406 .iter()
400- .map(|t| t.path.file_name().expect("a name").to_string_lossy().into_owned())407+ .map(|t| t
408+ .path
409+ .file_name()
410+ .expect("a name")
411+ .to_string_lossy()
412+ .into_owned())
401 .collect::<Vec<_>>(),413 .collect::<Vec<_>>(),
402 vec!["a.srt", "c.srt"],414 vec!["a.srt", "c.srt"],
403 "and a load is the same two, in the same order"415 "and a load is the same two, in the same order"
@@ -435,7 +447,9 @@ fn subtitles_come_off_another_file_without_it_joining_the_timeline() {
435 // A different file entirely, carrying two subtitle tracks.447 // A different file entirely, carrying two subtitle tracks.
436 let other = asset("test_subs.mkv");448 let other = asset("test_subs.mkv");
437 assert_eq!(449 assert_eq!(
438- session.import_subtitles(&other).expect("its subtitles come"),450+ session
451+ .import_subtitles(&other)
452+ .expect("its subtitles come"),
439 2453 2
440 );454 );
441 assert_eq!(session.subtitles().len(), 2);455 assert_eq!(session.subtitles().len(), 2);
@@ -445,13 +459,21 @@ fn subtitles_come_off_another_file_without_it_joining_the_timeline() {
445 }459 }
446 // ...and the timeline is exactly the timeline it was.460 // ...and the timeline is exactly the timeline it was.
447 assert_eq!(461 assert_eq!(
448- session.sources().iter().map(|s| s.path.clone()).collect::<Vec<_>>(),462+ session
463+ .sources()
464+ .iter()
465+ .map(|s| s.path.clone())
466+ .collect::<Vec<_>>(),
449 sources,467 sources,
450 "the file whose subtitles these are did not join the library"468 "the file whose subtitles these are did not join the library"
451 );469 );
452 assert_eq!(session.lanes(), lanes, "no lane was added");470 assert_eq!(session.lanes(), lanes, "no lane was added");
453 assert_eq!(471 assert_eq!(
454- session.lanes().iter().map(|&l| session.lane_clips(l).len()).collect::<Vec<_>>(),472+ session
473+ .lanes()
474+ .iter()
475+ .map(|&l| session.lane_clips(l).len())
476+ .collect::<Vec<_>>(),
455 clips,477 clips,
456 "and nothing was cut, moved or dropped on one"478 "and nothing was cut, moved or dropped on one"
457 );479 );
@@ -590,12 +612,19 @@ fn a_project_naming_many_tracks_of_one_file_walks_it_once_and_keeps_its_order()
590 let opened = subtitle::open_all(&rows);612 let opened = subtitle::open_all(&rows);
591 let cost = read_bytes() - before;613 let cost = read_bytes() - before;
592 assert_eq!(614 assert_eq!(
593- opened.iter().map(|t| (&t.path, t.track)).collect::<Vec<_>>(),615+ opened
616+ .iter()
617+ .map(|t| (&t.path, t.track))
618+ .collect::<Vec<_>>(),
594 rows.iter().map(|(p, n)| (p, *n)).collect::<Vec<_>>(),619 rows.iter().map(|(p, n)| (p, *n)).collect::<Vec<_>>(),
595 "every row comes back where it was saved"620 "every row comes back where it was saved"
596 );621 );
597 assert_eq!(opened[1].label, "eng", "and it is that file's track 1");622 assert_eq!(opened[1].label, "eng", "and it is that file's track 1");
598- assert_eq!(opened[2].cues, expected(), "the standalone row is untouched");623+ assert_eq!(
624+ opened[2].cues,
625+ expected(),
626+ "the standalone row is untouched"
627+ );
599 assert!(628 assert!(
600 opened[5]629 opened[5]
601 .refused630 .refused
@@ -798,7 +827,10 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() {
798 project.move_sub(lane, 0, s2, 300).expect("it changes lane");827 project.move_sub(lane, 0, s2, 300).expect("it changes lane");
799 assert!(project.sub_lane(lane).is_empty(), "off the first row");828 assert!(project.sub_lane(lane).is_empty(), "off the first row");
800 assert_eq!(project.sub_lane(s2).len(), 1, "and onto the second");829 assert_eq!(project.sub_lane(s2).len(), 1, "and onto the second");
801- assert!(project.undo() && project.undo(), "the move and the added lane");830+ assert!(
831+ project.undo() && project.undo(),
832+ "the move and the added lane"
833+ );
802 834
803 // Every one of the four was one undo step, and the snapshots are the lane835 // Every one of the four was one undo step, and the snapshots are the lane
804 // list's own: subtitles joined the history without a history of their own.836 // list's own: subtitles joined the history without a history of their own.
@@ -843,10 +875,24 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() {
843 fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {875 fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
844 let (mut project, lane) = with_subtitle_lane();876 let (mut project, lane) = with_subtitle_lane();
845 project877 project
846- .place_sub(lane, 30, SubClip { frames: 60, ..whole(0) })878+ .place_sub(
879+ lane,
880+ 30,
881+ SubClip {
882+ frames: 60,
883+ ..whole(0)
884+ },
885+ )
847 .expect("the first goes down");886 .expect("the first goes down");
848 let err = project887 let err = project
849- .place_sub(lane, 60, SubClip { frames: 60, ..whole(0) })888+ .place_sub(
889+ lane,
890+ 60,
891+ SubClip {
892+ frames: 60,
893+ ..whole(0)
894+ },
895+ )
850 .expect_err("the second lands inside it");896 .expect_err("the second lands inside it");
851 assert!(897 assert!(
852 err.to_string().contains("already covers [30, 90)"),898 err.to_string().contains("already covers [30, 90)"),
@@ -854,7 +900,14 @@ fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
854 );900 );
855 901
856 project902 project
857- .place_sub(lane, 200, SubClip { frames: 60, ..whole(0) })903+ .place_sub(
904+ lane,
905+ 200,
906+ SubClip {
907+ frames: 60,
908+ ..whole(0)
909+ },
910+ )
858 .expect("clear of it, it goes down");911 .expect("clear of it, it goes down");
859 let err = project912 let err = project
860 .move_sub(lane, 0, lane, 150)913 .move_sub(lane, 0, lane, 150)
@@ -867,21 +920,50 @@ fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
867 // Neither refusal moved anything, and neither cost a step: one undo takes920 // Neither refusal moved anything, and neither cost a step: one undo takes
868 // the *second placement* back, not a refusal.921 // the *second placement* back, not a refusal.
869 assert_eq!(922 assert_eq!(
870- project.sub_lane(lane).iter().map(|s| s.start).collect::<Vec<_>>(),923+ project
924+ .sub_lane(lane)
925+ .iter()
926+ .map(|s| s.start)
927+ .collect::<Vec<_>>(),
871 [30, 200]928 [30, 200]
872 );929 );
873 assert!(project.undo());930 assert!(project.undo());
874 assert_eq!(931 assert_eq!(
875- project.sub_lane(lane).iter().map(|s| s.start).collect::<Vec<_>>(),932+ project
933+ .sub_lane(lane)
934+ .iter()
935+ .map(|s| s.start)
936+ .collect::<Vec<_>>(),
876 [30]937 [30]
877 );938 );
878 939
879 // The other refusals of the door, each in its own words.940 // The other refusals of the door, each in its own words.
880 for (lane, at, sub, want) in [941 for (lane, at, sub, want) in [
881 (Lane::V1, 0, whole(0), "not a subtitle track"),942 (Lane::V1, 0, whole(0), "not a subtitle track"),
882- (Lane::new(LaneKind::Subtitle, 4), 0, whole(0), "there is no S5"),943+ (
883- (Lane::S1, 0, SubClip { frames: 0, ..whole(0) }, "is empty"),944+ Lane::new(LaneKind::Subtitle, 4),
884- (Lane::S1, 0, SubClip { track: 7, ..whole(0) }, "subtitle track 7 of 1"),945+ 0,
946+ whole(0),
947+ "there is no S5",
948+ ),
949+ (
950+ Lane::S1,
951+ 0,
952+ SubClip {
953+ frames: 0,
954+ ..whole(0)
955+ },
956+ "is empty",
957+ ),
958+ (
959+ Lane::S1,
960+ 0,
961+ SubClip {
962+ track: 7,
963+ ..whole(0)
964+ },
965+ "subtitle track 7 of 1",
966+ ),
885 ] {967 ] {
886 let err = project.place_sub(lane, at, sub).expect_err("refused");968 let err = project.place_sub(lane, at, sub).expect_err("refused");
887 assert!(969 assert!(
@@ -941,7 +1023,11 @@ fn a_lane_maps_to_cues_clipped_to_the_window_and_shifted_onto_the_timeline() {
941 .collect::<Vec<_>>(),1023 .collect::<Vec<_>>(),
942 [1024 [
943 (0, 500_000, "first line".to_string()),1025 (0, 500_000, "first line".to_string()),
944- (1_000_000, 2_000_000, "second line\nwith a break".to_string()),1026+ (
1027+ 1_000_000,
1028+ 2_000_000,
1029+ "second line\nwith a break".to_string()
1030+ ),
945 ],1031 ],
946 "both cues clipped to the window and shifted to the placement"1032 "both cues clipped to the window and shifted to the placement"
947 );1033 );
@@ -1003,25 +1089,60 @@ fn a_removed_palette_row_walks_the_placements_below_it_down() {
1003 1089
1004 // The row above it comes off -- nothing plays it -- and the placement is1090 // The row above it comes off -- nothing plays it -- and the placement is
1005 // walked down with the palette, so it still says the same words.1091 // walked down with the palette, so it still says the same words.
1006- project.remove_subtitles(0).expect("an unplaced row comes off");1092+ project
1093+ .remove_subtitles(0)
1094+ .expect("an unplaced row comes off");
1007 assert_eq!(1095 assert_eq!(
1008- project.subtitles().iter().map(|t| &*t.label).collect::<Vec<_>>(),1096+ project
1097+ .subtitles()
1098+ .iter()
1099+ .map(|t| &*t.label)
1100+ .collect::<Vec<_>>(),
1009 ["fra - Signs", "spa"],1101 ["fra - Signs", "spa"],
1010 "the survivors keep their order"1102 "the survivors keep their order"
1011 );1103 );
1012- assert_eq!(project.sub_lane(lane)[0].track, 0, "the placement moved down");1104+ assert_eq!(
1105+ project.sub_lane(lane)[0].track,
1106+ 0,
1107+ "the placement moved down"
1108+ );
1013 assert_eq!(1109 assert_eq!(
1014 project.subtitles()[project.sub_lane(lane)[0].track].label,1110 project.subtitles()[project.sub_lane(lane)[0].track].label,
1015 "fra - Signs",1111 "fra - Signs",
1016 "and names the very track it named before"1112 "and names the very track it named before"
1017 );1113 );
1018 1114
1019- // The history went with it: its snapshots hold the indexes as they were1115+ // The history went with it -- and it *can*, now that the entry carries the
1020- // before the reindex, so an undo into one would put the placement back on a1116+ // palette ([`Snapshot`]'s own `subtitles`, beside the lanes and the
1021- // track that is no longer there.1117+ // settings): the reindex is a step like any other, so an undo puts the row
1118+ // and the placement's own index back together and the same clip goes on
1119+ // naming the same words.
1022 assert!(1120 assert!(
1023- !project.undo(),1121+ project.undo(),
1024- "no step survives a reindex the snapshots do not know about"1122+ "a reindex the entry carries is a step; the history was thrown away instead"
1123+ );
1124+ assert_eq!(
1125+ project
1126+ .subtitles()
1127+ .iter()
1128+ .map(|t| &*t.label)
1129+ .collect::<Vec<_>>(),
1130+ ["eng", "fra - Signs", "spa"],
1131+ "the undo did not put the removed row back"
1132+ );
1133+ assert_eq!(
1134+ project.subtitles()[project.sub_lane(lane)[0].track].label,
1135+ "fra - Signs",
1136+ "and the placement names the very track it named before the removal"
1137+ );
1138+ // ...and the step again, which is where the rest of this test starts: the
1139+ // row off and the placement walked down with it (`undo` left it on the
1140+ // redo stack).
1141+ assert!(project.redo(), "the step is a step both ways");
1142+ assert_eq!(
1143+ project.sub_lane(lane)[0].track,
1144+ 0,
1145+ "the placement moved down again"
1025 );1146 );
1026 1147
1027 // ...and now that it *is* placed, the same row does not come off at all:1148 // ...and now that it *is* placed, the same row does not come off at all:
@@ -1045,7 +1166,14 @@ fn a_removed_palette_row_walks_the_placements_below_it_down() {
1045 fn a_drag_that_changes_nothing_is_ok_and_costs_no_step() {1166 fn a_drag_that_changes_nothing_is_ok_and_costs_no_step() {
1046 let (mut project, lane) = with_subtitle_lane();1167 let (mut project, lane) = with_subtitle_lane();
1047 project1168 project
1048- .place_sub(lane, 30, SubClip { frames: 60, ..whole(0) })1169+ .place_sub(
1170+ lane,
1171+ 30,
1172+ SubClip {
1173+ frames: 60,
1174+ ..whole(0)
1175+ },
1176+ )
1049 .expect("it goes down");1177 .expect("it goes down");
1050 let placed = project.sub_lane(lane)[0];1178 let placed = project.sub_lane(lane)[0];
1051 1179
@@ -1095,7 +1223,10 @@ fn a_caption_is_cut_and_rippled_with_the_picture_under_it() {
1095 .expect("it goes down");1223 .expect("it goes down");
1096 1224
1097 // The razor: halves that add up to the whole, in frames and in microseconds.1225 // The razor: halves that add up to the whole, in frames and in microseconds.
1098- assert!(project.split(30), "the cut lands on the picture and the words");1226+ assert!(
1227+ project.split(30),
1228+ "the cut lands on the picture and the words"
1229+ );
1099 assert_eq!(1230 assert_eq!(
1100 project1231 project
1101 .sub_lane(lane)1232 .sub_lane(lane)
@@ -1107,14 +1238,21 @@ fn a_caption_is_cut_and_rippled_with_the_picture_under_it() {
1107 // ...and its inverse puts the caption back exactly as it was.1238 // ...and its inverse puts the caption back exactly as it was.
1108 assert!(project.regroup(30), "the halves rejoin");1239 assert!(project.regroup(30), "the halves rejoin");
1109 assert_eq!(1240 assert_eq!(
1110- project.sub_lane(lane).iter().map(|s| (s.start, s.frames, s.in_us, s.out_us)).collect::<Vec<_>>(),1241+ project
1242+ .sub_lane(lane)
1243+ .iter()
1244+ .map(|s| (s.start, s.frames, s.in_us, s.out_us))
1245+ .collect::<Vec<_>>(),
1111 [(0, 60, 0, 2_000_000)]1246 [(0, 60, 0, 2_000_000)]
1112 );1247 );
1113 1248
1114 // A rippling delete through the middle of it: the hole closes, what was1249 // A rippling delete through the middle of it: the hole closes, what was
1115 // inside it is gone from the words as well as from the picture, and the two1250 // inside it is gone from the words as well as from the picture, and the two
1116 // halves keep exactly the seconds they kept frames for.1251 // halves keep exactly the seconds they kept frames for.
1117- assert!(project.ripple_delete(20, 20), "the hole closes on every lane");1252+ assert!(
1253+ project.ripple_delete(20, 20),
1254+ "the hole closes on every lane"
1255+ );
1118 assert_eq!(1256 assert_eq!(
1119 project1257 project
1120 .sub_lane(lane)1258 .sub_lane(lane)
@@ -1234,7 +1372,10 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
1234 1372
1235 let mut session = engine::PlaybackSession::open(&media).expect("open the fixture");1373 let mut session = engine::PlaybackSession::open(&media).expect("open the fixture");
1236 session.set_gain(0.0); // silent like the rest of the suites1374 session.set_gain(0.0); // silent like the rest of the suites
1237- assert_eq!(session.import_subtitles(&subs).expect("the .srt imports"), 1);1375+ assert_eq!(
1376+ session.import_subtitles(&subs).expect("the .srt imports"),
1377+ 1
1378+ );
1238 1379
1239 let s1 = session.add_lane(LaneKind::Subtitle);1380 let s1 = session.add_lane(LaneKind::Subtitle);
1240 let s2 = session.add_lane(LaneKind::Subtitle);1381 let s2 = session.add_lane(LaneKind::Subtitle);
@@ -1246,7 +1387,9 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
1246 out_us: 1_500_000,1387 out_us: 1_500_000,
1247 link: None,1388 link: None,
1248 };1389 };
1249- session.place_sub(s1, 10, caption).expect("a caption goes down");1390+ session
1391+ .place_sub(s1, 10, caption)
1392+ .expect("a caption goes down");
1250 1393
1251 let project = dir.join("cut.edith");1394 let project = dir.join("cut.edith");
1252 session.save_project(&project).expect("save");1395 session.save_project(&project).expect("save");
@@ -1270,7 +1413,10 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
1270 );1413 );
1271 assert_eq!(1414 assert_eq!(
1272 back.sub_lane(s1),1415 back.sub_lane(s1),
1273- [SubClip { start: 10, ..caption }],1416+ [SubClip {
1417+ start: 10,
1418+ ..caption
1419+ }],
1274 "and the caption is the very placement it was"1420 "and the caption is the very placement it was"
1275 );1421 );
1276 assert!(back.sub_lane(s2).is_empty(), "the empty one is still empty");1422 assert!(back.sub_lane(s2).is_empty(), "the empty one is still empty");
@@ -1374,7 +1520,10 @@ fn a_caption_naming_a_track_the_palette_does_not_have_is_refused() {
1374 // ...and the load's own door says the same thing about the same file, by1520 // ...and the load's own door says the same thing about the same file, by
1375 // the lane rather than by the line: `from_parts` for words.1521 // the lane rather than by the line: `from_parts` for words.
1376 let (project, _lane) = with_subtitle_lane();1522 let (project, _lane) = with_subtitle_lane();
1377- let beyond = SubClip { track: 3, ..whole(0) };1523+ let beyond = SubClip {
1524+ track: 3,
1525+ ..whole(0)
1526+ };
1378 let refused = project1527 let refused = project
1379 .clone()1528 .clone()
1380 .with_subs(vec![Vec::new(), Vec::new(), vec![beyond]])1529 .with_subs(vec![Vec::new(), Vec::new(), vec![beyond]])