fix(recording): prefer staged windows capture helper

This commit is contained in:
wiiiii123
2026-05-06 23:46:13 +07:00
parent 322cf8b1ca
commit 65e7bd4fff
2 changed files with 81 additions and 4 deletions
+75
View File
@@ -0,0 +1,75 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("Windows native helper path resolution", () => {
let tempRoot: string;
let appPath: string;
beforeEach(async () => {
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "recordly-helper-paths-"));
appPath = path.join(tempRoot, "App");
await fs.mkdir(appPath, { recursive: true });
vi.resetModules();
vi.doMock("electron", () => ({
app: {
isPackaged: false,
getAppPath: () => appPath,
},
}));
});
afterEach(async () => {
vi.resetModules();
vi.doUnmock("electron");
await fs.rm(tempRoot, { recursive: true, force: true });
});
it("prefers the branch-staged helper over a stale local CMake build in dev", async () => {
const buildOutputPath = path.join(
appPath,
"electron",
"native",
"wgc-capture",
"build",
"Release",
"wgc-capture.exe",
);
const prebundledPath = path.join(
appPath,
"electron",
"native",
"bin",
process.arch === "arm64" ? "win32-arm64" : "win32-x64",
"wgc-capture.exe",
);
await fs.mkdir(path.dirname(buildOutputPath), { recursive: true });
await fs.mkdir(path.dirname(prebundledPath), { recursive: true });
await fs.writeFile(buildOutputPath, "old-local-build");
await fs.writeFile(prebundledPath, "branch-staged-helper");
const { getWindowsCaptureExePath } = await import("./binaries");
expect(getWindowsCaptureExePath()).toBe(prebundledPath);
});
it("falls back to the local CMake build when no staged helper exists", async () => {
const buildOutputPath = path.join(
appPath,
"electron",
"native",
"wgc-capture",
"build",
"Release",
"wgc-capture.exe",
);
await fs.mkdir(path.dirname(buildOutputPath), { recursive: true });
await fs.writeFile(buildOutputPath, "local-build");
const { getWindowsCaptureExePath } = await import("./binaries");
expect(getWindowsCaptureExePath()).toBe(buildOutputPath);
});
});
+6 -4
View File
@@ -67,14 +67,16 @@ export function resolvePreferredWindowsNativeHelperPath(
return prebundledPath;
}
if (existsSync(buildOutputPath)) {
return buildOutputPath;
}
// Source checkouts should run the helper staged in the branch instead of a
// stale local CMake build left over from an earlier test run.
if (existsSync(prebundledPath)) {
return prebundledPath;
}
if (existsSync(buildOutputPath)) {
return buildOutputPath;
}
return buildOutputPath;
}