From c4d3b8342daff835e251fe12b00ee50a7c90360d Mon Sep 17 00:00:00 2001 From: wangdl Date: Sun, 21 Jun 2026 11:46:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Gate=20E2E=20=E2=80=94=20Test.createTest?= =?UTF-8?q?ingModule=20+=20DiscoveryModule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DiscoveryModule 来自 @nestjs/core,提供 ModulesContainer 和 Reflector。 解决了 AdminAuthGuard 和 DiscoveryService 的依赖解析问题。 Co-Authored-By: Claude --- test/m-ai-03-gate.e2e-spec.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/m-ai-03-gate.e2e-spec.ts b/test/m-ai-03-gate.e2e-spec.ts index aeb5d80..1cfde4f 100644 --- a/test/m-ai-03-gate.e2e-spec.ts +++ b/test/m-ai-03-gate.e2e-spec.ts @@ -1,5 +1,6 @@ -import { NestFactory } from '@nestjs/core'; +import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; +import { DiscoveryModule } from '@nestjs/core'; import { JwtService } from '@nestjs/jwt'; import request from 'supertest'; import { AppModule } from '../src/app.module'; @@ -40,15 +41,18 @@ describe('M-AI-03 GATE E2E (fail-closed)', () => { process.env.AI_JOB_SYNTHETIC_ENABLED = 'true'; process.env.JWT_SECRET = 'gate-e2e-secret'; - // NestFactory.create 提供所有 core providers (Reflector etc.) - // 连接 Prisma + Redis — 失败则测试 fail-closed - app = await NestFactory.create(AppModule); + // DiscoveryModule 提供 ModulesContainer + Reflector(TestingModule 不自动导入) + const module: TestingModule = await Test.createTestingModule({ + imports: [AppModule, DiscoveryModule], + }).compile(); + + app = module.createNestApplication(); await app.init(); - creationService = app.get(AiJobCreationService); - registry = app.get(JobDefinitionRegistry); - lifecycleRepo = app.get(AiJobLifecycleRepository); - jwtService = app.get(JwtService); + creationService = module.get(AiJobCreationService); + registry = module.get(JobDefinitionRegistry); + lifecycleRepo = module.get(AiJobLifecycleRepository); + jwtService = module.get(JwtService); userToken = jwtService.sign({ sub: TEST_USER, email: 'gate@test.com', role: 'USER', type: 'user' }); }, 30000);