Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): read desktop source tree pages larger than the ones we write

Richie McIlroy310ee62f2323
diff --git a/apps/web/__tests__/unit/desktop-recording-source.test.ts b/apps/web/__tests__/unit/desktop-recording-source.test.ts
index 5db42c507..0da9e32b8 100644
--- a/apps/web/__tests__/unit/desktop-recording-source.test.ts
+++ b/apps/web/__tests__/unit/desktop-recording-source.test.ts
@@ -10,6 +10,7 @@ import type { RecordingVerification } from "@/lib/desktop-recording-verification
const mocks = vi.hoisted(() => ({
storage: vi.fn(),
pageSize: undefined as number | undefined,
+ treePageSize: undefined as number | undefined,
}));
vi.mock("@cap/web-backend/src/Storage/index", () => ({
@@ -28,6 +29,9 @@ vi.mock("@/lib/desktop-recording-source-checkpoint", async (importOriginal) => {
get SOURCE_COMMIT_AWS_PAGE_SIZE() {
return mocks.pageSize ?? actual.SOURCE_COMMIT_AWS_PAGE_SIZE;
},
+ get SOURCE_COMMIT_PART_PAGE_SIZE() {
+ return mocks.treePageSize ?? actual.SOURCE_COMMIT_PART_PAGE_SIZE;
+ },
};
});
vi.mock("@/lib/workflow-runtime", async () => {
@@ -446,6 +450,7 @@ function seedSegments(
beforeEach(() => {
vi.clearAllMocks();
mocks.pageSize = undefined;
+ mocks.treePageSize = undefined;
});
describe("recording source preparation during upload", () => {
@@ -1777,6 +1782,26 @@ describe("source commit page size", () => {
);
});
+ it("reads tree pages larger than it writes, so a newer deployment's commit can be resumed after a rollback", async () => {
+ const reference = await referenceOutput(64);
+ mocks.treePageSize = 128;
+ const larger = await referenceOutput(128);
+ mocks.treePageSize = undefined;
+ expect(Math.max(...larger.leaves)).toBeGreaterThan(64);
+ expect(larger.output).toEqual(reference.output);
+ expect(larger.checkpoints).toBeLessThan(reference.checkpoints);
+ });
+
+ it("still rejects tree pages above the read limit", async () => {
+ const actual = await vi.importActual<
+ typeof import("@/lib/desktop-recording-source-checkpoint")
+ >("@/lib/desktop-recording-source-checkpoint");
+ expect(actual.SOURCE_COMMIT_MAX_TREE_PAGE_ENTRIES).toBe(256);
+ expect(actual.SOURCE_COMMIT_PART_PAGE_SIZE).toBeLessThanOrEqual(
+ actual.SOURCE_COMMIT_MAX_TREE_PAGE_ENTRIES,
+ );
+ });
+
it.each([
["a custom S3-compatible bucket", "s3", true],
["Google Drive", "googleDrive", false],
diff --git a/apps/web/lib/desktop-recording-source-checkpoint.ts b/apps/web/lib/desktop-recording-source-checkpoint.ts
index 08add3f07..bf6275007 100644
--- a/apps/web/lib/desktop-recording-source-checkpoint.ts
+++ b/apps/web/lib/desktop-recording-source-checkpoint.ts
@@ -5,6 +5,8 @@ export const SOURCE_COMMIT_PAGE_SIZE = 16;
export const SOURCE_COMMIT_AWS_PAGE_SIZE = 64;
export const SOURCE_COMMIT_PART_BATCH_SIZE = 4;
export const SOURCE_COMMIT_PART_PAGE_SIZE = 64;
+// Readers accept larger tree pages than writers produce, so a deployment can be rolled back while commits written by a newer one are in flight.
+export const SOURCE_COMMIT_MAX_TREE_PAGE_ENTRIES = 256;
export const SOURCE_COMMIT_MAX_OBJECTS = 100_002;
const sha256 = z.string().regex(/^[a-f0-9]{64}$/);
diff --git a/apps/web/lib/desktop-recording-source.ts b/apps/web/lib/desktop-recording-source.ts
index 4d4825589..37353de85 100644
--- a/apps/web/lib/desktop-recording-source.ts
+++ b/apps/web/lib/desktop-recording-source.ts
@@ -11,6 +11,7 @@ import {
desktopRecordingSourceCheckpointSchema,
SOURCE_COMMIT_AWS_PAGE_SIZE,
SOURCE_COMMIT_MAX_OBJECTS,
+ SOURCE_COMMIT_MAX_TREE_PAGE_ENTRIES,
SOURCE_COMMIT_PAGE_SIZE,
SOURCE_COMMIT_PART_BATCH_SIZE,
SOURCE_COMMIT_PART_PAGE_SIZE,
@@ -233,7 +234,10 @@ const treePageSchema = z.discriminatedUnion("type", [
kind: z.enum(["plan", "objects", "parts"]),
scope: z.string(),
start: z.number().int().nonnegative(),
- entries: z.array(z.unknown()).min(1).max(SOURCE_COMMIT_PART_PAGE_SIZE),
+ entries: z
+ .array(z.unknown())
+ .min(1)
+ .max(SOURCE_COMMIT_MAX_TREE_PAGE_ENTRIES),
}),
z.object({
version: z.literal(1),