From 762a9c17911018e57005e46b538947f5dd4250a2 Mon Sep 17 00:00:00 2001 From: wangdl Date: Fri, 19 Jun 2026 21:54:31 +0800 Subject: [PATCH] fix: use TestingModule as application context, fix $executeRaw - TestingModule.compile() returns an application context directly - Use $executeRaw tagged template instead of $executeRawUnsafe - Add jest.setTimeout(30000) for integration tests Co-Authored-By: Claude Opus 4.7 --- test/m-ai-01-09.e2e-spec.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/m-ai-01-09.e2e-spec.ts b/test/m-ai-01-09.e2e-spec.ts index 9d06d02..aeeb967 100644 --- a/test/m-ai-01-09.e2e-spec.ts +++ b/test/m-ai-01-09.e2e-spec.ts @@ -11,7 +11,7 @@ */ import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; +import { INestApplicationContext } from '@nestjs/common'; import { WorkerModule } from '../src/worker.module'; import { AppModule } from '../src/app.module'; import { PrismaService } from '../src/infrastructure/database/prisma.service'; @@ -46,9 +46,11 @@ import { WorkerHeartbeatService } from '../src/workers/worker-heartbeat.service' // 注意: runtime-internal.service.ts 是 Heavy Runtime (Rust) 链路, 不参与 BullMQ 链路. // Gate 报告若引用 runtime-internal.service.ts 则属于证据错误. +jest.setTimeout(30_000); + describe('M-AI-01-09 Integration', () => { - let apiApp: INestApplication; - let workerApp: INestApplication; + let apiApp: INestApplicationContext; + let workerApp: INestApplicationContext; let prisma: PrismaService; let redis: RedisService; let queueService: QueueService; @@ -65,16 +67,15 @@ describe('M-AI-01-09 Integration', () => { const apiModule: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); - apiApp = apiModule.createNestApplication(); - await apiApp.init(); + // TestingModule IS an application context — use directly + apiApp = apiModule as any; apiApp.enableShutdownHooks(); // Worker context (Consumer, all Processors) const workerModule: TestingModule = await Test.createTestingModule({ imports: [WorkerModule], }).compile(); - workerApp = workerModule.createNestApplication(); - await workerApp.init(); + workerApp = workerModule as any; workerApp.enableShutdownHooks(); prisma = workerApp.get(PrismaService); @@ -145,7 +146,7 @@ describe('M-AI-01-09 Integration', () => { 'LearningSession', 'KnowledgeItem', 'KnowledgeBase', ]; for (const table of tables) { - await prisma.$executeRawUnsafe(`DELETE FROM \`${table}\` WHERE userId = ?`, testUserId).catch(() => {}); + await prisma.$executeRaw`DELETE FROM \`${table}\` WHERE userId = ${testUserId}`.catch(() => {}); } await prisma.user.delete({ where: { id: testUserId } }).catch(() => {}); }