fix: Gate E2E — @Global() ReflectorModule 提供跨模块 Reflector
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 34s
Deploy API Server / current-integration (push) Successful in 30s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / m-ai-03-synthetic-e2e (push) Failing after 12s
Deploy API Server / deploy (push) Has been skipped

AppConfigModule 注册 AdminAuthGuard 需要 Reflector。
@Global() 装饰让 Reflector 对子模块可见——这是 NestJS 正确做法。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-21 11:48:27 +08:00
parent c4d3b8342d
commit afb90d690b

View File

@ -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 + ReflectorTestingModule 不自动导入)
// ReflectorModule(@Global) 让子模块 AppConfigModule 能解析 Reflector 依赖
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule, DiscoveryModule],
imports: [ReflectorModule, AppModule],
}).compile();
app = module.createNestApplication();