|
1 | 1 | import { describe, expect, it, mock } from "bun:test"; |
| 2 | +import { createHash } from "node:crypto"; |
2 | 3 | import { |
3 | 4 | hasAutoStartVideos, |
4 | 5 | hasScriptedAudioVolumeAutomation, |
@@ -583,6 +584,113 @@ describe("runProbeStage — forceScreenshot threading", () => { |
583 | 584 | expect(capturedCfgs.length).toBeGreaterThan(0); |
584 | 585 | }); |
585 | 586 |
|
| 587 | + it("probes and reconciles synchronous src mutations on existing video and audio", async () => { |
| 588 | + resetRetryMocks(); |
| 589 | + capturedCfgs.length = 0; |
| 590 | + const hash = (value: string) => createHash("sha256").update(value).digest("hex"); |
| 591 | + const videoA = `assets/video-a-${hash("sanitized-video-a")}.mp4`; |
| 592 | + const videoB = `assets/video-b-${hash("sanitized-video-b")}.mp4`; |
| 593 | + const audioA = `assets/audio-a-${hash("sanitized-audio-a")}.wav`; |
| 594 | + const audioB = `assets/audio-b-${hash("sanitized-audio-b")}.wav`; |
| 595 | + expect(hash("sanitized-video-a")).not.toBe(hash("sanitized-video-b")); |
| 596 | + expect(hash("sanitized-audio-a")).not.toBe(hash("sanitized-audio-b")); |
| 597 | + browserMediaResults = [ |
| 598 | + { |
| 599 | + id: "clip", |
| 600 | + tagName: "video", |
| 601 | + src: videoB, |
| 602 | + start: 0, |
| 603 | + end: 5, |
| 604 | + duration: 5, |
| 605 | + mediaStart: 0, |
| 606 | + loop: false, |
| 607 | + hasAudio: false, |
| 608 | + volume: 1, |
| 609 | + muted: true, |
| 610 | + }, |
| 611 | + { |
| 612 | + id: "voice", |
| 613 | + tagName: "audio", |
| 614 | + src: audioB, |
| 615 | + start: 0, |
| 616 | + end: 5, |
| 617 | + duration: 5, |
| 618 | + mediaStart: 0, |
| 619 | + loop: false, |
| 620 | + hasAudio: true, |
| 621 | + volume: 1, |
| 622 | + muted: false, |
| 623 | + }, |
| 624 | + ]; |
| 625 | + const { runProbeStage } = await import("./probeStage.js"); |
| 626 | + const input = makeProbeInput({}); |
| 627 | + input.composition.duration = 5; |
| 628 | + input.composition.videos.push({ |
| 629 | + id: "clip", |
| 630 | + src: videoA, |
| 631 | + start: 0, |
| 632 | + end: 5, |
| 633 | + mediaStart: 0, |
| 634 | + loop: false, |
| 635 | + hasAudio: false, |
| 636 | + }); |
| 637 | + input.composition.audios.push({ |
| 638 | + id: "voice", |
| 639 | + src: audioA, |
| 640 | + start: 0, |
| 641 | + end: 5, |
| 642 | + mediaStart: 0, |
| 643 | + layer: 0, |
| 644 | + volume: 1, |
| 645 | + type: "audio", |
| 646 | + }); |
| 647 | + input.compiled.html = `<video id="clip" src="${videoA}"></video> |
| 648 | + <audio id="voice" src="${audioA}"></audio> |
| 649 | + <script> |
| 650 | + const clip = document.getElementById("clip"); |
| 651 | + clip.src = ${JSON.stringify(videoB)}; |
| 652 | + document.querySelector("#voice").setAttribute("src", ${JSON.stringify(audioB)}); |
| 653 | + </script>`; |
| 654 | + |
| 655 | + await runProbeStage(input); |
| 656 | + |
| 657 | + expect(capturedCfgs.length).toBeGreaterThan(0); |
| 658 | + expect(input.composition.videos[0]?.src).toBe(videoB); |
| 659 | + expect(input.composition.audios[0]?.src).toBe(audioB); |
| 660 | + expect(mediaPreflightComposition).toBe(input.composition); |
| 661 | + }); |
| 662 | + |
| 663 | + it("does not probe for img or script src mutations", async () => { |
| 664 | + resetRetryMocks(); |
| 665 | + capturedCfgs.length = 0; |
| 666 | + const { runProbeStage } = await import("./probeStage.js"); |
| 667 | + const input = makeProbeInput({}); |
| 668 | + input.composition.duration = 5; |
| 669 | + input.compiled.html = `<img id="poster" src="a.png"><script id="loader"></script> |
| 670 | + <script> |
| 671 | + document.getElementById("poster").src = "b.png"; |
| 672 | + document.getElementById("loader").setAttribute("src", "loader-b.js"); |
| 673 | + </script>`; |
| 674 | + |
| 675 | + await runProbeStage(input); |
| 676 | + |
| 677 | + expect(capturedCfgs).toHaveLength(0); |
| 678 | + }); |
| 679 | + |
| 680 | + it("probes when a source child of existing media is mutated", async () => { |
| 681 | + resetRetryMocks(); |
| 682 | + capturedCfgs.length = 0; |
| 683 | + const { runProbeStage } = await import("./probeStage.js"); |
| 684 | + const input = makeProbeInput({}); |
| 685 | + input.composition.duration = 5; |
| 686 | + input.compiled.html = `<video id="clip"><source id="clip-source" src="video-a.mp4"></video> |
| 687 | + <script>document.getElementById("clip-source").src = "video-b.mp4";</script>`; |
| 688 | + |
| 689 | + await runProbeStage(input); |
| 690 | + |
| 691 | + expect(capturedCfgs.length).toBeGreaterThan(0); |
| 692 | + }); |
| 693 | + |
586 | 694 | it("launches a probe when a static-duration composition uses the Audio constructor", async () => { |
587 | 695 | capturedCfgs.length = 0; |
588 | 696 | const { runProbeStage } = await import("./probeStage.js"); |
|
0 commit comments