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