From 9e86844a024c7e37da9be6769b90c639293c4860 Mon Sep 17 00:00:00 2001 From: Etienne Lescot Date: Tue, 4 Aug 2026 23:45:39 +0200 Subject: [PATCH] test(recording): make the re-index suite run off Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reindexRecordingOnDisk is Linux-gated by intent — Windows and macOS record through native helpers that write indexed files at the source, so the wrapper returns `unsupported-platform` before touching anything else. The suite never accounted for that: six of its cases inject a fake remux service and assert the remuxed result, so on a macOS or Windows checkout they stop at the guard and fail. They were red on a clean tree, for environmental reasons, with nothing to distinguish them from a real regression. Pin process.platform to linux in beforeEach and restore the real value in afterEach, so the cases exercise the wrapper's own logic on every platform. The technique is the one the suite's last case already used inline; hoisting it removes the per-test save/restore boilerplate and makes the restore hold even when a case throws part-way. The guard itself stays covered, now over both platforms it exists for rather than win32 alone, so pinning to Linux can't quietly become the only thing the suite exercises. No production code changes. Verified the cases still have teeth: removing the empty-output size check from reindexRecordingOnDisk fails the truncated-file case, which had been passing vacuously on macOS. `npx vitest --run` is now green on macOS: 137 files, 1626 passing. --- electron/recording/webm-seek-index.test.ts | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/electron/recording/webm-seek-index.test.ts b/electron/recording/webm-seek-index.test.ts index fd654a3a6..58fa423ac 100644 --- a/electron/recording/webm-seek-index.test.ts +++ b/electron/recording/webm-seek-index.test.ts @@ -4,6 +4,9 @@ import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { reindexRecordingOnDisk } from "./webm-seek-index"; +/** The platforms whose native helpers already write an indexed file. */ +const NON_LINUX = ["darwin", "win32"] as const; + /** * The property under test is not "does libavformat work" — the Rust side owns * that, and `crates/compositor/tests/remux_seek_index.rs` proves it. It is the @@ -14,13 +17,26 @@ import { reindexRecordingOnDisk } from "./webm-seek-index"; describe("recording re-index", () => { let dir: string; const ORIGINAL = "original recording bytes"; - + const REAL_PLATFORM = process.platform; + + const setPlatform = (value: NodeJS.Platform) => + Object.defineProperty(process, "platform", { value, configurable: true }); + + /** + * Pin the platform, because the wrapper is Linux-gated and returns + * `unsupported-platform` before it touches anything else. Left to the real + * platform, every case below stops at that guard and asserts nothing on a + * macOS or Windows checkout — where this suite read as six red tests that + * were neither the contributor's fault nor a real regression. + */ beforeEach(async () => { + setPlatform("linux"); dir = await mkdtemp(path.join(tmpdir(), "openscreen-reindex-")); vi.spyOn(console, "warn").mockImplementation(() => undefined); }); afterEach(async () => { + setPlatform(REAL_PLATFORM); await rm(dir, { recursive: true, force: true }); vi.restoreAllMocks(); }); @@ -116,18 +132,17 @@ describe("recording re-index", () => { expect(await readFile(filePath, "utf8")).toBe("remuxed bytes"); }); - it("does nothing on platforms whose capture already writes indexed files", async () => { + // Both platforms the guard is there for, so the Linux pin above can never + // quietly become the only thing this suite ever exercises. + it.each(NON_LINUX)("does nothing on %s, which captures an index already", async (platform) => { const filePath = await makeRecording(); const service = fakeRemux("remuxed bytes"); - const platform = process.platform; - Object.defineProperty(process, "platform", { value: "win32", configurable: true }); - try { - const result = await reindexRecordingOnDisk(filePath, service); - expect(result).toEqual({ reindexed: false, reason: "unsupported-platform" }); - expect(service.remuxSeekable).not.toHaveBeenCalled(); - expect(await readFile(filePath, "utf8")).toBe(ORIGINAL); - } finally { - Object.defineProperty(process, "platform", { value: platform, configurable: true }); - } + setPlatform(platform); + + const result = await reindexRecordingOnDisk(filePath, service); + + expect(result).toEqual({ reindexed: false, reason: "unsupported-platform" }); + expect(service.remuxSeekable).not.toHaveBeenCalled(); + expect(await readFile(filePath, "utf8")).toBe(ORIGINAL); }); });