Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions apps/web/__tests__/integration/transcribe-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,59 @@ describe("backfillEditTranscriptWorkflow", () => {
);
});

it("never substitutes edited media when the original source is inaccessible", async () => {
const originalKey = "user-456/video-123/original.mp4";
state.editRows = [
{
sourceKey: originalKey,
editSpec: {
version: 1,
sourceDuration: 12,
keepRanges: [{ start: 8, end: 12 }],
},
},
];
mocks.getInternalSignedObjectUrl.mockImplementation((key: string) =>
pipeValue(`https://storage.test/${key}`),
);
vi.stubGlobal(
"fetch",
vi.fn(
async (url: string) =>
new Response(url.endsWith(originalKey) ? null : "edited audio", {
status: url.endsWith(originalKey) ? 404 : 200,
}),
),
);

const { backfillEditTranscriptWorkflow } = await import(
"@/workflows/transcribe"
);
const result = await backfillEditTranscriptWorkflow({
videoId: "video-123",
userId: "user-456",
requestId: "request-1",
});

expect(result).toEqual({ success: false });
expect(mocks.transcribe).not.toHaveBeenCalled();
expect(mocks.putObject).not.toHaveBeenCalled();
expect(mocks.getInternalSignedObjectUrl).toHaveBeenCalledExactlyOnceWith(
originalKey,
);
expect(mocks.updates).toContainEqual(
expect.objectContaining({
metadata: expect.objectContaining({
strings: expect.arrayContaining([
expect.stringContaining(
"'$.editTranscriptBackfill.status', 'error'",
),
]),
}),
}),
);
});

it("does not run a backfill after its database claim is replaced", async () => {
const { backfillEditTranscriptWorkflow } = await import(
"@/workflows/transcribe"
Expand Down
10 changes: 5 additions & 5 deletions apps/web/workflows/transcribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ async function resolveVideoSourceUrl(
.where(eq(videoUploads.videoId, videoId as Video.VideoId))
.limit(1);

const candidateKeys = [
sourceKeyOverride,
`${userId}/${videoId}/result.mp4`,
upload[0]?.rawFileKey,
].filter(
const candidateKeys = (
sourceKeyOverride
? [sourceKeyOverride]
: [`${userId}/${videoId}/result.mp4`, upload[0]?.rawFileKey]
).filter(
(value, index, values): value is string =>
Boolean(value) && values.indexOf(value) === index,
);
Expand Down
Loading