mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 18:38:24 +00:00
* feat(workflow): migrate workflow engine from temporal to dbos Replace Temporal and LocalExecutor with DBOS Transact (@dbos-inc/dbos-sdk) as the unified workflow engine. Background tasks, media transcoding, and AI agent workflows now execute with durable steps and task queues directly against PostgreSQL, eliminating the need for an external Temporal cluster and separate polling executors. * fix(workflow): submit tasks via DBOSClient to allow enqueueing from steps Enqueuing workflows using DBOS.enqueueWorkflowWithOptions threw a DBOSInvalidWorkflowTransitionError when triggered from within a running step or activity (e.g. creating embedding or autofill tasks during video transcoding). Use DBOSClient to submit and cancel workflow tasks directly against the system database, detaching execution from the ambient workflow/step context. * feat(web): support SHUMAI_WORKERS environment variable * fix(workflow): ensure CLI tasks are enqueued to DBOS and run DBOS migrations in global setup - Initialize workflows and wait for pending DBOS submissions in shumai regenerate-embeddings CLI - Remove no-op submit bypass and enqueue tasks via DBOSClient in producer and CLI contexts - Add DBOS migration runner in test global setup to avoid concurrent migration deadlocks across test forks - Update changelog and add regression tests * fix(workflow): ensure unique per-instance executor identity for worker replicas - Derive unique per-instance DBOS executor IDs across worker replicas - Support SHUMAI_WORKER_ID, DBOS__VMID, and POD_NAME (Kubernetes Downward API) - Disambiguate multi-replica bare metal/container deployments with host, PID, and instance suffix - Prevent startup recovery from re-enqueueing workflows actively executed by other live workers - Add multi-instance startup recovery tests and update deployment documentation * fix(workflow): only register listened queues and update concurrency on change - Only register queues that the executor instance actively listens to - Use always_update conflict resolution so environment variable changes take effect on restart - Prevent dedicated workers from overwriting unmanaged queue concurrency configurations - Add tests verifying concurrency updates and queue isolation across worker roles * refactor(workflow): simplify activities to use defineStep and direct calls (#482) * refactor(workflow): simplify activities to use defineStep and direct calls - Wrap activities using defineStep from @shumai/workflow-core - Remove obsolete getActivities, registerActivities, dynamic activity proxies, and workerQueue arguments - Remove executor.ts and registry.ts, consolidating workflow registration into workflow.ts - Call activities directly across transcode and agent workflows - Update all corresponding workflow tests and developer guide documentation * fix(workflow): properly detect DBOSWorkflowCancelledError in runOnCancel fallback - DBOSWorkflowCancelledError in DBOS SDK does not set name, inheriting 'Error' - Implement isDbosWorkflowCancelledError checking instanceof, constructor.name, and dbosErrorCode - Update unit tests to verify real DBOS SDK cancellation error instances * docs(workflow): update documentation and readme for dbos migration - Rename docs/configuration/temporal.mdx to docs/configuration/distributed.mdx - Document DBOS-based distributed worker architecture and task queues - Remove obsolete docker-compose/temporal/ - Update environment variables documentation in docs/configuration/env-variables.mdx - Update references in README.md, README_CN.md, docs/docs.json, and related guides * feat(deploy): implement KEDA ScaledJob and scale-to-zero On-Demand transcoding (#483) * feat(deploy): add shumai-transcode docker image and k8s autoscaling example with garage s3 * docs(k8s): document port-forwarding and in-cluster s3 domain mapping * feat(storage): support public s3 endpoint for browser uploads and update k8s example * fix(k8s): configure s3 bucket cors rules in garage initialization * fix(k8s): increase transcode worker memory limit to 4Gi for 4K video encoding * feat(deploy): add AWS EKS deployment with Graviton3 Spot nodegroups and autoscaling * docs(deploy): redesign EKS documentation, rename k8s to eks, and add scalable deployment feature * docs: rephrase DBOS feature bullet to Durable Workflows via DBOS * docs(eks): upgrade default instances to Graviton5 c9g.large and c9g.xlarge * feat(eks): use On-Demand for general nodegroup and add spot capacity diversification * docs(eks): fix Architecture diagram to locate all transcode worker pods in Transcode Compute Pool * feat(deploy): implement KEDA ScaledJob and scale-to-zero On-Demand transcoding * feat(transcode): support idle-timeout auto-drain for KEDA scaled jobs * fix(deploy): fix EKS deployment manifests and documentation based on cluster verification
560 lines
18 KiB
TypeScript
560 lines
18 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
|
import { prisma, WatermarkFileStatus } from '@shumai/db'
|
|
import { setupTestDbHooks } from '@shumai/db/test'
|
|
import { workflowService, TaskQueueTranscode } from '@shumai/workflow-core'
|
|
import { initTranscodeWorkflows } from '@shumai/transcode'
|
|
import { watermarkService } from '@shumai/core/src/watermark/watermark'
|
|
import { shareService } from '@shumai/core/src/share/share'
|
|
import { s3Service } from '@shumai/core/src/s3/s3'
|
|
import { fileURLToPath } from 'url'
|
|
import * as path from 'path'
|
|
import * as fs from 'fs'
|
|
import type { WatermarkConfigSpec } from '@shumai/dtos'
|
|
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
const fixturesDir = path.resolve(currentDir, '../fixtures')
|
|
|
|
describe('Workflow E2E - transcodeWatermarkWorkflow', () => {
|
|
setupTestDbHooks()
|
|
|
|
beforeAll(async () => {
|
|
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-watermark'
|
|
|
|
initTranscodeWorkflows()
|
|
await workflowService.startWorkers(TaskQueueTranscode)
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await workflowService.shutdownWorkers()
|
|
workflowService.close()
|
|
vi.restoreAllMocks()
|
|
try {
|
|
await s3Service.deletePrefix('shumai-e2e-test-bucket-watermark', '')
|
|
} catch (err) {
|
|
console.error('Failed to clean up E2E storage folder:', err)
|
|
}
|
|
})
|
|
|
|
it('should generate watermark proxy for an image asset and update sharelink status to ready', async () => {
|
|
// 1. Seed Database
|
|
const team = await prisma.team.create({
|
|
data: { name: 'E2E Watermark Team' },
|
|
})
|
|
const projectFolder = await prisma.asset.create({
|
|
data: { name: 'root', type: 'root', status: 'processed' },
|
|
})
|
|
const project = await prisma.project.create({
|
|
data: { name: 'E2E Watermark Project', teamId: team.id, rootFolderId: projectFolder.id },
|
|
})
|
|
|
|
const storageKey = await prisma.storageKey.create({
|
|
data: { key: 'files/e2e-watermark-asset/original.png' },
|
|
})
|
|
|
|
const sampleImagePath = path.join(fixturesDir, 'sample.png')
|
|
let sampleBuffer: Buffer
|
|
if (fs.existsSync(sampleImagePath)) {
|
|
sampleBuffer = fs.readFileSync(sampleImagePath)
|
|
} else {
|
|
// Minimal 1x1 PNG fallback if fixture is missing
|
|
sampleBuffer = Buffer.from(
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
|
|
'base64',
|
|
)
|
|
}
|
|
|
|
await s3Service.putObject(
|
|
'shumai-e2e-test-bucket-watermark',
|
|
storageKey.key,
|
|
sampleBuffer,
|
|
sampleBuffer.length,
|
|
'image/png',
|
|
)
|
|
|
|
const asset = await prisma.asset.create({
|
|
data: {
|
|
name: 'sample.png',
|
|
type: 'file',
|
|
mediaType: 'image/png',
|
|
status: 'processed',
|
|
projectId: project.id,
|
|
storageKeyId: storageKey.id,
|
|
media: {
|
|
duration: 0,
|
|
filesize: sampleBuffer.length,
|
|
frames: 0,
|
|
proxyType: 'image',
|
|
imageTranscodes: [
|
|
{ key: storageKey.key, width: 100, height: 100, quality: 90, format: 'webp' },
|
|
],
|
|
videoTranscodes: [],
|
|
videoPreview: { width: 100, height: 100 },
|
|
finishedAt: new Date().toISOString(),
|
|
metadata: {
|
|
originalWidth: 100,
|
|
originalHeight: 100,
|
|
duration: 0,
|
|
bitRate: 0,
|
|
frameRate: 0,
|
|
totalFrames: 0,
|
|
startTimecode: '00:00:00:00',
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
original: {
|
|
key: storageKey.key,
|
|
filesizeInBytes: sampleBuffer.length,
|
|
codec: '',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const shareLink = await shareService.createShareLink(project.id, {
|
|
name: 'Public Watermarked Share',
|
|
})
|
|
await shareService.addAssetToShare(shareLink.id, { assetIds: [asset.id] })
|
|
|
|
const watermarkConfig: WatermarkConfigSpec = {
|
|
blocks: [
|
|
{
|
|
id: 'b1',
|
|
type: 'text',
|
|
x: 0.5,
|
|
y: 0.5,
|
|
opacity: 0.5,
|
|
rotation: 0,
|
|
text: 'CONFIDENTIAL E2E',
|
|
size: 0.2,
|
|
color: '#FF0000',
|
|
},
|
|
],
|
|
}
|
|
|
|
// 2. Enable Watermark on Sharelink
|
|
const updatedShare = await watermarkService.updateShareLinkWatermark(
|
|
shareLink.id,
|
|
true,
|
|
watermarkConfig,
|
|
)
|
|
expect(updatedShare.watermarkStatus).toBe('processing')
|
|
|
|
// 3. Poll for WorkflowTask completion & ShareLink status 'ready'
|
|
let finalShare = await shareService.getShareLink(shareLink.id)
|
|
const startTime = Date.now()
|
|
while (finalShare.watermarkStatus === 'processing' && Date.now() - startTime < 15000) {
|
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
finalShare = await shareService.getShareLink(shareLink.id)
|
|
}
|
|
|
|
expect(finalShare.watermarkStatus).toBe('ready')
|
|
|
|
// Verify WatermarkFile record was created and completed
|
|
const watermarkFile = await prisma.watermarkFile.findUnique({
|
|
where: {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
assetId_watermarkConfigId: {
|
|
assetId: asset.id,
|
|
watermarkConfigId: updatedShare.watermarkConfigId!,
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(watermarkFile).toBeDefined()
|
|
expect(watermarkFile?.status).toBe(WatermarkFileStatus.completed)
|
|
expect(watermarkFile?.media).toBeDefined()
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
expect((watermarkFile?.media as any)?.imageTranscodes?.length).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('should generate watermark proxy for a video asset and update sharelink status to ready', async () => {
|
|
// 1. Seed Database
|
|
const team = await prisma.team.create({
|
|
data: { name: 'E2E Watermark Video Team' },
|
|
})
|
|
const projectFolder = await prisma.asset.create({
|
|
data: { name: 'root', type: 'root', status: 'processed' },
|
|
})
|
|
const project = await prisma.project.create({
|
|
data: {
|
|
name: 'E2E Watermark Video Project',
|
|
teamId: team.id,
|
|
rootFolderId: projectFolder.id,
|
|
},
|
|
})
|
|
|
|
const storageKey = await prisma.storageKey.create({
|
|
data: { key: 'files/e2e-watermark-video/original.mp4' },
|
|
})
|
|
|
|
const videoPath = path.join(fixturesDir, 'small.mp4')
|
|
const videoBuffer = fs.readFileSync(videoPath)
|
|
await s3Service.putObject(
|
|
'shumai-e2e-test-bucket-watermark',
|
|
storageKey.key,
|
|
videoBuffer,
|
|
videoBuffer.length,
|
|
'video/mp4',
|
|
)
|
|
|
|
const asset = await prisma.asset.create({
|
|
data: {
|
|
name: 'small.mp4',
|
|
type: 'file',
|
|
mediaType: 'video/mp4',
|
|
status: 'processed',
|
|
projectId: project.id,
|
|
storageKeyId: storageKey.id,
|
|
media: {
|
|
duration: 1,
|
|
filesize: videoBuffer.length,
|
|
frames: 30,
|
|
proxyType: 'video',
|
|
imageTranscodes: [],
|
|
videoTranscodes: [{ key: storageKey.key, width: 640, height: 360, resolution: '360p' }],
|
|
videoPreview: { width: 640, height: 360 },
|
|
finishedAt: new Date().toISOString(),
|
|
metadata: {
|
|
originalWidth: 640,
|
|
originalHeight: 360,
|
|
duration: 1,
|
|
bitRate: 0,
|
|
frameRate: 30,
|
|
totalFrames: 30,
|
|
startTimecode: '00:00:00:00',
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
original: {
|
|
key: storageKey.key,
|
|
filesizeInBytes: videoBuffer.length,
|
|
codec: '',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const shareLink = await shareService.createShareLink(project.id, {
|
|
name: 'Public Watermarked Video Share',
|
|
})
|
|
await shareService.addAssetToShare(shareLink.id, { assetIds: [asset.id] })
|
|
|
|
const watermarkConfig: WatermarkConfigSpec = {
|
|
blocks: [
|
|
{
|
|
id: 'b1',
|
|
type: 'text',
|
|
x: 0.5,
|
|
y: 0.5,
|
|
opacity: 0.5,
|
|
rotation: 0,
|
|
text: 'CONFIDENTIAL VIDEO',
|
|
size: 0.2,
|
|
color: '#FF0000',
|
|
},
|
|
],
|
|
}
|
|
|
|
// 2. Enable Watermark on Sharelink
|
|
const updatedShare = await watermarkService.updateShareLinkWatermark(
|
|
shareLink.id,
|
|
true,
|
|
watermarkConfig,
|
|
)
|
|
expect(updatedShare.watermarkStatus).toBe('processing')
|
|
|
|
// 3. Poll for WorkflowTask completion & ShareLink status 'ready'
|
|
let finalShare = await shareService.getShareLink(shareLink.id)
|
|
const startTime = Date.now()
|
|
while (finalShare.watermarkStatus === 'processing' && Date.now() - startTime < 30000) {
|
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
finalShare = await shareService.getShareLink(shareLink.id)
|
|
}
|
|
|
|
expect(finalShare.watermarkStatus).toBe('ready')
|
|
|
|
const watermarkFile = await prisma.watermarkFile.findUnique({
|
|
where: {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
assetId_watermarkConfigId: {
|
|
assetId: asset.id,
|
|
watermarkConfigId: updatedShare.watermarkConfigId!,
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(watermarkFile).toBeDefined()
|
|
expect(watermarkFile?.status).toBe(WatermarkFileStatus.completed)
|
|
expect(watermarkFile?.media).toBeDefined()
|
|
// The transcoded proxy should be watermarked, producing exactly one proxy.
|
|
const mediaInfo = watermarkFile?.media as PrismaJson.MediaInfo | null
|
|
expect(mediaInfo?.videoTranscodes?.length).toBe(1)
|
|
expect(mediaInfo?.videoTranscodes?.[0].resolution).toBe('360p')
|
|
})
|
|
|
|
it('should generate watermark proxy for a 3d asset from turntable video and update sharelink status to ready', async () => {
|
|
// 1. Seed Database
|
|
const team = await prisma.team.create({
|
|
data: { name: 'E2E Watermark 3D Team' },
|
|
})
|
|
const projectFolder = await prisma.asset.create({
|
|
data: { name: 'root', type: 'root', status: 'processed' },
|
|
})
|
|
const project = await prisma.project.create({
|
|
data: {
|
|
name: 'E2E Watermark 3D Project',
|
|
teamId: team.id,
|
|
rootFolderId: projectFolder.id,
|
|
},
|
|
})
|
|
|
|
const storageKey = await prisma.storageKey.create({
|
|
data: { key: 'files/e2e-watermark-3d/model.glb' },
|
|
})
|
|
|
|
const turntableKey = 'files/e2e-watermark-3d/turntable.mp4'
|
|
const videoPath = path.join(fixturesDir, 'small.mp4')
|
|
const videoBuffer = fs.readFileSync(videoPath)
|
|
await s3Service.putObject(
|
|
'shumai-e2e-test-bucket-watermark',
|
|
turntableKey,
|
|
videoBuffer,
|
|
videoBuffer.length,
|
|
'video/mp4',
|
|
)
|
|
|
|
const asset = await prisma.asset.create({
|
|
data: {
|
|
name: 'model.glb',
|
|
type: 'file',
|
|
mediaType: 'model/gltf-binary',
|
|
status: 'processed',
|
|
projectId: project.id,
|
|
storageKeyId: storageKey.id,
|
|
media: {
|
|
duration: 1,
|
|
filesize: videoBuffer.length,
|
|
frames: 30,
|
|
proxyType: '3d',
|
|
imageTranscodes: [],
|
|
videoTranscodes: [{ key: turntableKey, width: 640, height: 360, resolution: '360p' }],
|
|
videoPreview: { key: turntableKey, width: 640, height: 360, resolution: '360p' },
|
|
poster: { key: 'files/e2e-watermark-3d/poster.webp' },
|
|
finishedAt: new Date().toISOString(),
|
|
metadata: {
|
|
originalWidth: 640,
|
|
originalHeight: 360,
|
|
duration: 1,
|
|
bitRate: 0,
|
|
frameRate: 30,
|
|
totalFrames: 30,
|
|
startTimecode: '00:00:00:00',
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
original: {
|
|
key: storageKey.key,
|
|
filesizeInBytes: 100,
|
|
codec: '',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const shareLink = await shareService.createShareLink(project.id, {
|
|
name: 'Public Watermarked 3D Share',
|
|
})
|
|
await shareService.addAssetToShare(shareLink.id, { assetIds: [asset.id] })
|
|
|
|
const watermarkConfig: WatermarkConfigSpec = {
|
|
blocks: [
|
|
{
|
|
id: 'b1',
|
|
type: 'text',
|
|
x: 0.5,
|
|
y: 0.5,
|
|
opacity: 0.5,
|
|
rotation: 0,
|
|
text: 'CONFIDENTIAL 3D',
|
|
size: 0.2,
|
|
color: '#FF0000',
|
|
},
|
|
],
|
|
}
|
|
|
|
const updatedShare = await watermarkService.updateShareLinkWatermark(
|
|
shareLink.id,
|
|
true,
|
|
watermarkConfig,
|
|
)
|
|
expect(updatedShare.watermarkStatus).toBe('processing')
|
|
|
|
let share = await shareService.getShareLink(shareLink.id)
|
|
const startTime = Date.now()
|
|
while (share.watermarkStatus === 'processing' && Date.now() - startTime < 60000) {
|
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
share = await shareService.getShareLink(shareLink.id)
|
|
}
|
|
expect(share.watermarkStatus).toBe('ready')
|
|
|
|
const wf = await prisma.watermarkFile.findUnique({
|
|
where: {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
assetId_watermarkConfigId: {
|
|
assetId: asset.id,
|
|
watermarkConfigId: updatedShare.watermarkConfigId!,
|
|
},
|
|
},
|
|
})
|
|
expect(wf).toBeDefined()
|
|
expect(wf?.status).toBe(WatermarkFileStatus.completed)
|
|
const media = wf?.media as PrismaJson.MediaInfo
|
|
expect(media.proxyType).toBe('3d')
|
|
expect(media.videoTranscodes?.length).toBeGreaterThan(0)
|
|
expect(media.videoPreview?.key).toBe(media.videoTranscodes?.[0]?.key)
|
|
})
|
|
|
|
it('should watermark a newly added asset after the sharelink is already ready', async () => {
|
|
// 1. Seed Database
|
|
const team = await prisma.team.create({
|
|
data: { name: 'E2E Watermark Team' },
|
|
})
|
|
const projectFolder = await prisma.asset.create({
|
|
data: { name: 'root', type: 'root', status: 'processed' },
|
|
})
|
|
const project = await prisma.project.create({
|
|
data: { name: 'E2E Watermark Project', teamId: team.id, rootFolderId: projectFolder.id },
|
|
})
|
|
|
|
const readSampleImage = (): Buffer => {
|
|
const sampleImagePath = path.join(fixturesDir, 'sample.png')
|
|
if (fs.existsSync(sampleImagePath)) {
|
|
return fs.readFileSync(sampleImagePath)
|
|
}
|
|
// Minimal 1x1 PNG fallback if fixture is missing
|
|
return Buffer.from(
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
|
|
'base64',
|
|
)
|
|
}
|
|
|
|
const createImageAsset = async (key: string, name: string) => {
|
|
const buffer = readSampleImage()
|
|
const storageKey = await prisma.storageKey.create({ data: { key } })
|
|
await s3Service.putObject(
|
|
'shumai-e2e-test-bucket-watermark',
|
|
key,
|
|
buffer,
|
|
buffer.length,
|
|
'image/png',
|
|
)
|
|
return await prisma.asset.create({
|
|
data: {
|
|
name,
|
|
type: 'file',
|
|
mediaType: 'image/png',
|
|
status: 'processed',
|
|
projectId: project.id,
|
|
storageKeyId: storageKey.id,
|
|
media: {
|
|
duration: 0,
|
|
filesize: buffer.length,
|
|
frames: 0,
|
|
proxyType: 'image',
|
|
imageTranscodes: [{ key, width: 100, height: 100, quality: 90, format: 'webp' }],
|
|
videoTranscodes: [],
|
|
videoPreview: { width: 100, height: 100 },
|
|
finishedAt: new Date().toISOString(),
|
|
metadata: {
|
|
originalWidth: 100,
|
|
originalHeight: 100,
|
|
duration: 0,
|
|
bitRate: 0,
|
|
frameRate: 0,
|
|
totalFrames: 0,
|
|
startTimecode: '00:00:00:00',
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
original: {
|
|
key,
|
|
filesizeInBytes: buffer.length,
|
|
codec: '',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
const assetA = await createImageAsset('files/e2e-add-after-ready/a.png', 'a.png')
|
|
const shareLink = await shareService.createShareLink(project.id, {
|
|
name: 'Public Watermarked Share',
|
|
})
|
|
await shareService.addAssetToShare(shareLink.id, { assetIds: [assetA.id] })
|
|
|
|
const watermarkConfig: WatermarkConfigSpec = {
|
|
blocks: [
|
|
{
|
|
id: 'b1',
|
|
type: 'text',
|
|
x: 0.5,
|
|
y: 0.5,
|
|
opacity: 0.5,
|
|
rotation: 0,
|
|
text: 'CONFIDENTIAL E2E',
|
|
size: 0.2,
|
|
color: '#FF0000',
|
|
},
|
|
],
|
|
}
|
|
|
|
// 2. Enable Watermark on Sharelink and wait for initial 'ready'
|
|
const updatedShare = await watermarkService.updateShareLinkWatermark(
|
|
shareLink.id,
|
|
true,
|
|
watermarkConfig,
|
|
)
|
|
expect(updatedShare.watermarkStatus).toBe('processing')
|
|
|
|
let share = await shareService.getShareLink(shareLink.id)
|
|
let startTime = Date.now()
|
|
while (share.watermarkStatus === 'processing' && Date.now() - startTime < 30000) {
|
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
share = await shareService.getShareLink(shareLink.id)
|
|
}
|
|
expect(share.watermarkStatus).toBe('ready')
|
|
expect(share.watermarkConfigId).toBe(updatedShare.watermarkConfigId)
|
|
|
|
// 3. Add a NEW asset to the ready sharelink
|
|
const assetB = await createImageAsset('files/e2e-add-after-ready/b.png', 'b.png')
|
|
await shareService.addAssetToShare(shareLink.id, { assetIds: [assetB.id] })
|
|
|
|
// 4. Status flips back to 'processing' while the new asset is transcoded
|
|
share = await shareService.getShareLink(shareLink.id)
|
|
expect(share.watermarkStatus).toBe('processing')
|
|
|
|
// 5. Poll until the sharelink is 'ready' again
|
|
startTime = Date.now()
|
|
while (share.watermarkStatus === 'processing' && Date.now() - startTime < 30000) {
|
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
share = await shareService.getShareLink(shareLink.id)
|
|
}
|
|
expect(share.watermarkStatus).toBe('ready')
|
|
|
|
// 6. Both assets now have completed watermark files
|
|
for (const asset of [assetA, assetB]) {
|
|
const wf = await prisma.watermarkFile.findUnique({
|
|
where: {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
assetId_watermarkConfigId: {
|
|
assetId: asset.id,
|
|
watermarkConfigId: updatedShare.watermarkConfigId!,
|
|
},
|
|
},
|
|
})
|
|
expect(wf).toBeDefined()
|
|
expect(wf?.status).toBe(WatermarkFileStatus.completed)
|
|
}
|
|
})
|
|
})
|