From afb90d690b2ae68b3b748ac8594af072757c0724 Mon Sep 17 00:00:00 2001 From: wangdl Date: Sun, 21 Jun 2026 11:48:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Gate=20E2E=20=E2=80=94=20@Global()=20Ref?= =?UTF-8?q?lectorModule=20=E6=8F=90=E4=BE=9B=E8=B7=A8=E6=A8=A1=E5=9D=97=20?= =?UTF-8?q?Reflector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AppConfigModule 注册 AdminAuthGuard 需要 Reflector。 @Global() 装饰让 Reflector 对子模块可见——这是 NestJS 正确做法。 Co-Authored-By: Claude --- test/m-ai-03-gate.e2e-spec.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/m-ai-03-gate.e2e-spec.ts b/test/m-ai-03-gate.e2e-spec.ts index 1cfde4f..58a4580 100644 --- a/test/m-ai-03-gate.e2e-spec.ts +++ b/test/m-ai-03-gate.e2e-spec.ts @@ -1,9 +1,15 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import { DiscoveryModule } from '@nestjs/core'; +import { INestApplication, Global, Module } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; +import { Reflector } from '@nestjs/core'; import request from 'supertest'; import { AppModule } from '../src/app.module'; + +// Reflector 是 NestJS 全局 provider,但 Test.createTestingModule 不自动导入。 +// 需要 @Global() 模块使其对 AppConfigModule(子模块)可见。 +@Global() +@Module({ providers: [Reflector], exports: [Reflector] }) +class ReflectorModule {} import { AiJobCreationService } from '../src/modules/ai-job/ai-job-creation.service'; import { JobDefinitionRegistry } from '../src/modules/ai-job/job-definition-registry'; import { AiJobLifecycleRepository } from '../src/modules/ai-job/ai-job-lifecycle.repository'; @@ -41,9 +47,9 @@ describe('M-AI-03 GATE E2E (fail-closed)', () => { process.env.AI_JOB_SYNTHETIC_ENABLED = 'true'; process.env.JWT_SECRET = 'gate-e2e-secret'; - // DiscoveryModule 提供 ModulesContainer + Reflector(TestingModule 不自动导入) + // ReflectorModule(@Global) 让子模块 AppConfigModule 能解析 Reflector 依赖 const module: TestingModule = await Test.createTestingModule({ - imports: [AppModule, DiscoveryModule], + imports: [ReflectorModule, AppModule], }).compile(); app = module.createNestApplication();