fix(admin): 生产环境隐藏并禁用自动化测试

侧栏与路由按服务端 NODE_ENV 控制;可通过 ALLOW_SMOKE_TESTS=true 临时开启。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-11 17:52:07 +08:00
parent e469611138
commit 283252c841
7 changed files with 94 additions and 15 deletions

View File

@@ -2299,9 +2299,16 @@ export class AdminController {
return jsonResponse(messages);
}
@Get('system/smoke-tests')
@RequirePermissions(P.settings)
getSmokeTestsStatus() {
return jsonResponse({ allowed: this.smokeTests.isAllowed() });
}
@Get('smoke-tests/suites')
@RequirePermissions(P.settings)
async smokeTestSuites() {
this.smokeTests.assertAllowed();
return jsonResponse({
suites: this.smokeTests.listSuites(),
cases: this.smokeTests.listCases(),
@@ -2312,6 +2319,7 @@ export class AdminController {
@Get('smoke-tests/last-run')
@RequirePermissions(P.settings)
async smokeTestLastRun() {
this.smokeTests.assertAllowed();
return jsonResponse(this.smokeTests.getLastRun());
}
@@ -2321,6 +2329,7 @@ export class AdminController {
@CurrentUser('id') operatorId: bigint,
@Body() body: { suites?: string[] },
) {
this.smokeTests.assertAllowed();
const summary = await this.smokeTests.run(body?.suites, operatorId);
await this.audit.log({
operatorId,

View File

@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { appForbidden } from '../../../shared/common/app-error';
import { PrismaService } from '../../../shared/prisma/prisma.service';
import { AgentsService } from '../../agent/agents.service';
import { BetsService } from '../../betting/bets.service';
@@ -30,6 +31,17 @@ export class SmokeTestService {
private agents: AgentsService,
) {}
isAllowed(): boolean {
if (process.env.ALLOW_SMOKE_TESTS === 'true') return true;
return process.env.NODE_ENV !== 'production';
}
assertAllowed() {
if (!this.isAllowed()) {
throw appForbidden('SMOKE_TESTS_FORBIDDEN');
}
}
listSuites(): SmokeTestSuiteInfo[] {
const counts = new Map<string, number>();
for (const c of SMOKE_TEST_CASES) {