Skip to content

Commit 2c14f1d

Browse files
committed
test: keep media oracles optional in clean clones
1 parent 8f2c171 commit 2c14f1d

2 files changed

Lines changed: 42 additions & 25 deletions

File tree

test/test-gif-decode.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,10 @@ test("decodeGifFirstFrame agrees byte-for-byte with frames[0] (synthetic)", () =
958958
);
959959
});
960960

961-
test("decodeGifFirstFrame agrees with the full decode on both fixture GIFs", () => {
962-
for (const path of [TESTSRC_GIF, SINTEL_GIF]) {
961+
test("decodeGifFirstFrame agrees with the full decode on every available fixture GIF", () => {
962+
const fixtures = [TESTSRC_GIF, SINTEL_GIF].filter(existsSync);
963+
assert(fixtures.length > 0, "at least the checked-in fixture is present");
964+
for (const path of fixtures) {
963965
const bytes = new Uint8Array(readFileSync(path));
964966
const full = mustDecode(bytes, path);
965967
const first = decodeGifFirstFrame(bytes);
@@ -1090,7 +1092,11 @@ if (FFMPEG_DIR === null) {
10901092
const fixtures: Array<[string, string, number]> = [
10911093
[TESTSRC_GIF, "testsrc-48x32-8f", 8],
10921094
[SINTEL_GIF, "sintel-3s", 36],
1093-
];
1095+
].filter(([path]) => existsSync(path));
1096+
1097+
if (!existsSync(SINTEL_GIF)) {
1098+
console.log(" \x1b[33m- skipped: optional devnotes/media/sintel-3s.gif fixture missing\x1b[0m");
1099+
}
10941100

10951101
for (const [path, label, expectedFrames] of fixtures) {
10961102
test(`${label}: frames match ffmpeg's composited output (MAE ~0)`, () => {
@@ -1151,22 +1157,24 @@ if (FFMPEG_DIR === null) {
11511157
}
11521158
});
11531159

1154-
test("sintel-3s: first-frame fast path is cheaper than the full decode", () => {
1155-
const bytes = new Uint8Array(readFileSync(SINTEL_GIF));
1156-
const t0 = performance.now();
1157-
const full = decodeGif(bytes);
1158-
const fullMs = performance.now() - t0;
1159-
const t1 = performance.now();
1160-
const first = decodeGifFirstFrame(bytes);
1161-
const firstMs = performance.now() - t1;
1162-
assert(full.ok && first !== null, "both paths decode");
1163-
measurements.push(`sintel-3s: full decode ${fullMs.toFixed(1)} ms, first frame only ${firstMs.toFixed(1)} ms`);
1164-
console.log(` ${measurements[measurements.length - 1]}`);
1165-
// Frame 0 is ~1/36th of the LZW work; anything close to the full decode
1166-
// would mean the early-out is not early. Generous 0.75 bound so timer
1167-
// noise on a loaded machine cannot flake the suite.
1168-
assert(firstMs < fullMs * 0.75 + 2, `first-frame ${firstMs} ms vs full ${fullMs} ms`);
1169-
});
1160+
if (existsSync(SINTEL_GIF)) {
1161+
test("sintel-3s: first-frame fast path is cheaper than the full decode", () => {
1162+
const bytes = new Uint8Array(readFileSync(SINTEL_GIF));
1163+
const t0 = performance.now();
1164+
const full = decodeGif(bytes);
1165+
const fullMs = performance.now() - t0;
1166+
const t1 = performance.now();
1167+
const first = decodeGifFirstFrame(bytes);
1168+
const firstMs = performance.now() - t1;
1169+
assert(full.ok && first !== null, "both paths decode");
1170+
measurements.push(`sintel-3s: full decode ${fullMs.toFixed(1)} ms, first frame only ${firstMs.toFixed(1)} ms`);
1171+
console.log(` ${measurements[measurements.length - 1]}`);
1172+
// Frame 0 is ~1/36th of the LZW work; anything close to the full decode
1173+
// would mean the early-out is not early. Generous 0.75 bound so timer
1174+
// noise on a loaded machine cannot flake the suite.
1175+
assert(firstMs < fullMs * 0.75 + 2, `first-frame ${firstMs} ms vs full ${fullMs} ms`);
1176+
});
1177+
}
11701178
}
11711179

11721180
// ═════════════════════════════════════════════════════════

test/test-video-pack-format.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ function errText(err: unknown): string {
8181

8282
const HERE = dirname(fileURLToPath(import.meta.url));
8383
const REAL_JPEG = join(HERE, "fixtures", "quarters-64x48.jpg");
84-
const TRAILER = join(HERE, "..", "devnotes", "media", "sintel-trailer.mp4");
8584

8685
// ─── Synthetic frames ─────────────────────────────────────
8786

@@ -744,9 +743,16 @@ test("sha1File matches shasum(1) on a small file", () => {
744743
});
745744

746745
test("sha1File hashes a file larger than its 1 MiB read chunk correctly", () => {
747-
// 4.4 MB, so the chunk loop runs five times — the case a single-read
748-
// implementation would silently get wrong.
749-
assertEqual(sha1File(TRAILER), "9b678890fb8ca401c28e7ca09171ec008a154b97", "sintel-trailer.mp4");
746+
// One chunk plus 17 bytes forces a second read. The digest was pinned with
747+
// `head -c 1048593 /dev/zero | tr '\\0' a | shasum -a 1`.
748+
const dir = mkdtempSync(join(tmpdir(), "tvf-sha1-large-"));
749+
try {
750+
const path = join(dir, "large.bin");
751+
writeFileSync(path, Buffer.alloc(1024 * 1024 + 17, 0x61));
752+
assertEqual(sha1File(path), "4d936f3b48d0ec41dc5a43693850fe1fe7b5f9f1", "large synthetic file");
753+
} finally {
754+
rmSync(dir, { recursive: true, force: true });
755+
}
750756
});
751757

752758
test("sha1File returns \"\" for an unreadable source instead of throwing", () => {
@@ -811,7 +817,10 @@ test("A pack carries the source digest for staleness detection", () => {
811817
"digest",
812818
);
813819
assertEqual(pack.header.sourceSha1, digest, "digest survives the roundtrip");
814-
assert(pack.header.sourceSha1 !== sha1File(TRAILER), "and a different source would not match");
820+
assert(
821+
pack.header.sourceSha1 !== sha1File(join(HERE, "fixtures", "video", "testsrc-48x32-8f.gif")),
822+
"and a different source would not match",
823+
);
815824
});
816825

817826
// ═════════════════════════════════════════════════════════════
@@ -837,7 +846,7 @@ for (let i = 0; i < BIG_COUNT; i++) {
837846

838847
const t0 = performance.now();
839848
const bigBytes = encodePack(
840-
{ width: 854, height: 480, fps: 24, frameCount: BIG_COUNT, durationMs: (BIG_COUNT * 1000) / 24, sourceSha1: sha1File(TRAILER) },
849+
{ width: 854, height: 480, fps: 24, frameCount: BIG_COUNT, durationMs: (BIG_COUNT * 1000) / 24, sourceSha1: sha1File(REAL_JPEG) },
841850
bigFrames,
842851
);
843852
const encodeMs = performance.now() - t0;

0 commit comments

Comments
 (0)