diff --git a/server/src/index.ts b/server/src/index.ts index 361b67f..888c110 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -202,6 +202,9 @@ app.get('/api/health', (_req: Request, res: Response) => { database: 'connected', uptime: process.uptime(), build: '2026-10-19', + // 运行模式自检:非 production 时用户身份校验会放宽、且允许沙箱支付(严禁用于公网) + mode: IS_PRODUCTION ? 'production' : 'development', + sandboxPayAllowed: ALLOW_SANDBOX_PAY, features: { userToken: true, adminPasswordGate: true, diff --git a/server/tests/runtime-mode-selfcheck.spec.ts b/server/tests/runtime-mode-selfcheck.spec.ts new file mode 100644 index 0000000..c13b368 --- /dev/null +++ b/server/tests/runtime-mode-selfcheck.spec.ts @@ -0,0 +1,18 @@ +// 已读取AGENTS.md +import * as fs from 'fs'; +import * as path from 'path'; + +/** + * 第八十六批:/api/health 暴露运行模式,避免"生产跑成 development"却无人察觉。 + * 背景:线上 NODE_ENV 未设为 production 时,resolveSecureUserId 会退回客户端声明身份, + * 且 ALLOW_SANDBOX_PAY 为 true(可无支付推进订单),属资损级配置风险。 + */ +describe('第八十六批运行模式自检闸门', () => { + const root = path.resolve(__dirname, '../../'); + const indexCode = fs.readFileSync(path.join(root, 'server/src/index.ts'), 'utf-8'); + + it('/api/health 返回 mode 与 sandboxPayAllowed', () => { + expect(indexCode).toContain("mode: IS_PRODUCTION ? 'production' : 'development'"); + expect(indexCode).toContain('sandboxPayAllowed: ALLOW_SANDBOX_PAY'); + }); +});