Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(mobile): make inferred completion recovery consistent

Akshar Patel592c71711ab2
diff --git a/apps/mobile/src/uploads/recording-upload-provider.test.tsx b/apps/mobile/src/uploads/recording-upload-provider.test.tsx
index d6b070696..9cea7c8aa 100644
--- a/apps/mobile/src/uploads/recording-upload-provider.test.tsx
+++ b/apps/mobile/src/uploads/recording-upload-provider.test.tsx
@@ -292,10 +292,22 @@ describe("RecordingUploadProvider", () => {
},
);
- it.each([null, "uploading"] as const)(
- "recovers an already-stranded camera completion with persisted server phase %s once",
- async (serverPhase) => {
+ it.each([
+ { serverPhase: null, durationSeconds: 2 },
+ { serverPhase: "uploading", durationSeconds: 2 },
+ { serverPhase: null, durationSeconds: null },
+ { serverPhase: "uploading", durationSeconds: null },
+ ] as const)(
+ "recovers uploaded recording media with saved state %j once per launch",
+ async ({ serverPhase, durationSeconds }) => {
vi.useFakeTimers();
+ let persisted = "";
+ fileSystemMock.writeAsStringAsync.mockImplementation(
+ (_uri: string, value: string) => {
+ persisted = value;
+ return Promise.resolve();
+ },
+ );
fileSystemMock.readAsStringAsync.mockResolvedValueOnce(
JSON.stringify({
jobs: [
@@ -303,6 +315,7 @@ describe("RecordingUploadProvider", () => {
...uploadedRecording,
status: serverPhase === null ? "processing" : "uploading",
serverPhase,
+ durationSeconds,
},
],
}),
@@ -324,9 +337,21 @@ describe("RecordingUploadProvider", () => {
});
await mountRecoveryProvider();
expect(authState.completeRecording).toHaveBeenCalledTimes(1);
+ expect(authState.completeRecording).toHaveBeenCalledWith(
+ "cap_123",
+ expect.objectContaining({ durationSeconds: 2 }),
+ );
expect(uploadToTarget).not.toHaveBeenCalled();
await act(async () => vi.advanceTimersByTimeAsync(30_000));
expect(authState.completeRecording).toHaveBeenCalledTimes(1);
+ await act(async () => recoveryRenderer?.unmount());
+ fileSystemMock.readAsStringAsync.mockResolvedValueOnce(persisted);
+ await mountRecoveryProvider();
+ expect(authState.completeRecording).toHaveBeenCalledTimes(2);
+ expect(authState.completeRecording.mock.calls[1]).toEqual(
+ authState.completeRecording.mock.calls[0],
+ );
+ expect(uploadToTarget).not.toHaveBeenCalled();
},
);
@@ -335,7 +360,6 @@ describe("RecordingUploadProvider", () => {
{ serverPhase: "processing" },
{ serverPhase: "generating_thumbnail" },
{ status: "complete" },
- { durationSeconds: null },
{ segments: [] },
{
segments: uploadedRecording.segments.map((segment) => ({
diff --git a/apps/mobile/src/uploads/recording-upload-queue.ts b/apps/mobile/src/uploads/recording-upload-queue.ts
index 6c12a183f..51e61ad00 100644
--- a/apps/mobile/src/uploads/recording-upload-queue.ts
+++ b/apps/mobile/src/uploads/recording-upload-queue.ts
@@ -387,7 +387,7 @@ const parseJob = (value: unknown): RecordingUploadJob | null => {
: segmentUploadedBytes;
const resumeCompletion =
uploadOwner === "app" &&
- storedDuration !== null &&
+ durationSeconds !== null &&
status !== "complete" &&
(status === "processing" || serverPhase === "uploading") &&
(serverPhase === null || serverPhase === "uploading") &&