refactor(db): isolate test hooks and clean up workflow worker options

This commit is contained in:
yiling
2026-06-02 18:48:54 +08:00
parent c110d67d80
commit e409f551cc
30 changed files with 34 additions and 39 deletions
@@ -1,5 +1,5 @@
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { s3Service } from '@shumai/core/src/s3/s3'
import { type SessionTreeEntry } from '@earendil-works/pi-agent-core'
import { describe, expect, it, vi } from 'vitest'
+1 -1
View File
@@ -5,7 +5,7 @@ vi.mock('fs')
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { createReadSkillTool } from './read-skill'
import { s3Service } from '@shumai/core/src/s3/s3'
import AdmZip from 'adm-zip'
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentAutofillMedia } from './agent-autofill'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@shumai/workflow-core', async () => {
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentChat } from './agent-chat'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@shumai/workflow-core', async () => {
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentEmbeddingMedia } from './agent-embedding'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@shumai/workflow-core', async () => {
+1 -1
View File
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest'
import { AgentService } from './agent'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
describe('AgentService', () => {
setupTestDbHooks()
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { AssetType, AssetStatus, Prisma } from '@shumai/db'
import { AssetService } from './asset'
+1 -1
View File
@@ -1,4 +1,4 @@
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { describe, expect, it } from 'vitest'
import { prisma } from '@shumai/db'
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { collectionService } from './collection'
import { projectService } from '../project/project'
+1 -1
View File
@@ -1,5 +1,5 @@
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { inviteService } from '@shumai/core/src/invite/invite'
import { beforeEach, describe, expect, it } from 'vitest'
+1 -1
View File
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { MetadataService } from './metadata'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
describe('MetadataService', () => {
setupTestDbHooks()
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { NotificationType } from '@shumai/db'
import { notificationService } from './notification'
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { ProjectService } from './project'
import { s3Service } from '@shumai/core/src/s3/s3'
import { assetService } from '@shumai/core/src/asset/asset'
+1 -1
View File
@@ -1,4 +1,4 @@
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { teamService } from '@shumai/core/src/team/team'
import { providerService } from './provider'
import { describe, expect, it } from 'vitest'
@@ -1,6 +1,6 @@
import { describe, expect, it, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { SearchService } from './search'
import { AssetType } from '@shumai/db'
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, beforeEach, vi } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { SearchService } from './search'
import { SearchConditionOperator } from '@shumai/dtos'
import { metadataService } from '@shumai/core/src/metadata/metadata'
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { shareService } from './share'
import { assetService } from '@shumai/core/src/asset/asset'
import { projectService } from '@shumai/core/src/project/project'
+1 -1
View File
@@ -1,5 +1,5 @@
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { s3Service } from '@shumai/core/src/s3/s3'
import { skillService } from '@shumai/core/src/skill/skill'
import AdmZip from 'adm-zip'
+1 -1
View File
@@ -1,5 +1,5 @@
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { teamService } from '@shumai/core/src/team/team'
import { describe, expect, it } from 'vitest'
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, vi, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { uploadService } from './upload'
import { s3Service } from '@shumai/core/src/s3/s3'
import { AssetStatus, AssetType, WorkflowTaskType } from '@shumai/db'
@@ -1,5 +1,5 @@
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { userMetadataService } from './user-metadata'
import { describe, expect, it } from 'vitest'
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { VersionStackService } from './versionStack'
import { AssetType } from '@shumai/db'
-2
View File
@@ -96,6 +96,4 @@ export function getPrismaTestingHelper() {
}
export * from './utils/ngram'
export * from './db-test-hooks'
export * from './prisma-testing-helper'
export * from './generated/prisma/client'
+2
View File
@@ -0,0 +1,2 @@
export * from './db-test-hooks'
export * from './prisma-testing-helper'
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { getMediaInfoActivity, transcodeVideoActivity, updateAssetMediaActivity } from './transcode'
import { s3Service } from '@shumai/core/src/s3/s3'
import { transcodeService } from '../transcode'
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import {
updateTaskStatusActivity,
updateAssetStatusActivity,
@@ -5,6 +5,10 @@ export async function getTranscodeWorkerQueueActivity(): Promise<string> {
return 'transcode_queue'
}
export async function getAgentWorkerQueueActivity(): Promise<string> {
return 'agent_queue'
}
export async function getAssetStatusActivity(params: { assetId: string }): Promise<AssetStatus | null> {
const asset = await prisma.asset.findUnique({
where: { id: params.assetId },
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { workflowService } from './workflow'
import { LocalExecutor, ConcurrencyLimiter, registerWorkflow } from './local-executor'
import { WorkflowTaskStatus, WorkflowTaskType } from '@shumai/db'
+2 -12
View File
@@ -56,15 +56,7 @@ export class WorkflowService {
}
// Starts Temporal workers for specific task queues
async startWorkers(
queue: string,
options?: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
workflowBundle?: any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
activities?: any
},
): Promise<void> {
async startWorkers(queue: string): Promise<void> {
const type = process.env.WORKFLOW_EXECUTOR || 'local'
if (type === 'temporal') {
const { Worker, NativeConnection } = await import('@temporalio/worker')
@@ -74,8 +66,7 @@ export class WorkflowService {
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const activities = options?.activities || (globalThis as any).__localActivities
const workflowBundle = options?.workflowBundle
const activities = (globalThis as any).__localActivities
// For agent_queue and transcode_queue, use worker-specific unique queues
const crypto = await import('crypto')
@@ -96,7 +87,6 @@ export class WorkflowService {
const sharedWorker = await Worker.create({
connection,
workflowBundle,
activities: sharedActivities,
taskQueue: queue,
})
+1
View File
@@ -18,6 +18,7 @@
"@shumai/core": ["packages/core/src/index.ts"],
"@shumai/core/src/*": ["packages/core/src/*"],
"@shumai/db": ["packages/db/src/index.ts"],
"@shumai/db/test": ["packages/db/src/test.ts"],
"@shumai/dtos": ["packages/dtos/src/index.ts"],
"@shumai/workflow-core": ["packages/workflow-core/src/index.ts"],
"@shumai/agent": ["packages/agent/src/index.ts"],