fix(desktop): prevent browser screenshot filename collisions (#14784)

This commit is contained in:
Alex Southwell authored and GitHub committed 2026-10-06 04:22:39 -05:00
1 parent d0dc45885c
commit 411cef0008
2 files changed
+35 -1

No files matched your search

+34
View File
@@ -2367,6 +2367,40 @@ describe("PreviewManager", () => {
),
);
effectIt.effect("preserves both screenshots of the same site in the same millisecond", () =>
withManager((manager) =>
Effect.gen(function* () {
const firstPng = Buffer.from("first-preview-png");
const secondPng = Buffer.from("second-preview-png");
const pngImage = (png: Buffer) => ({
toPNG: () => png,
toJPEG: () => png,
getSize: () => ({ width: 1280, height: 720 }),
});
const capturePage = vi
.fn<() => Promise<ReturnType<typeof pngImage>>>()
.mockResolvedValueOnce(pngImage(firstPng))
.mockResolvedValueOnce(pngImage(secondPng));
fromId.mockReturnValue(makeTestPreviewWebContents(capturePage));
yield* manager.createTab("tab_1");
yield* manager.registerWebview("tab_1", 42);
// it.effect keeps TestClock fixed until explicitly advanced.
const first = yield* manager.captureScreenshot("tab_1");
const second = yield* manager.captureScreenshot("tab_1");
expect(first.createdAt).toBe(second.createdAt);
expect(first.id).not.toBe(second.id);
expect(first.path).not.toBe(second.path);
expect(first.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
expect(second.id).toMatch(/^browser-screenshot-example-com-[a-z0-9]+-[0-9a-f]{8}$/);
expect(writeFile.mock.calls).toEqual([
[first.path, firstPng],
[second.path, secondPng],
]);
}),
),
);
effectIt.effect("keeps every recorded guest unthrottled until its frame capture stops", () =>
withManager((manager) =>
Effect.gen(function* () {
+1 -1
View File
@@ -2974,7 +2974,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
wc,
),
]);
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}`;
const id = `browser-screenshot-${artifactSiteSlug(wc.getURL())}-${millis.toString(36)}-${NodeCrypto.randomUUID().slice(0, 8)}`;
const artifactPath = path.join(resolvedArtifactDirectory, `${id}.png`);
const data = image.toPNG();
yield* fileSystem.makeDirectory(resolvedArtifactDirectory, { recursive: true }).pipe(