fix(GOV-009): 完成脚手架审查整改
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/** 应用环境仅允许显式的开发或生产态,禁止隐式 test/staging 绕过生产约束。 */
|
||||
export type AppEnvironment = 'development' | 'production';
|
||||
/** 四级日志口径由进程入口统一校验,避免基础设施各自解释字符串。 */
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
|
||||
/** 每个进程只接收自己的 Redis DB 与连接参数,凭据不得进入安全摘要。 */
|
||||
export interface RedisRuntimeConfig {
|
||||
host: string;
|
||||
port: number;
|
||||
@@ -10,6 +13,7 @@ export interface RedisRuntimeConfig {
|
||||
tls: boolean;
|
||||
}
|
||||
|
||||
/** MySQL 配置固定 5.7.42 兼容口径,启用状态决定凭据是否必填。 */
|
||||
export interface MysqlRuntimeConfig {
|
||||
enabled: boolean;
|
||||
host: string;
|
||||
@@ -22,6 +26,7 @@ export interface MysqlRuntimeConfig {
|
||||
timezone: '+08:00';
|
||||
}
|
||||
|
||||
/** OpenAI 兼容接口配置;关闭 AI 时允许凭据为空,且不影响规则分析。 */
|
||||
export interface AiRuntimeConfig {
|
||||
enabled: boolean;
|
||||
baseUrl: string;
|
||||
@@ -30,6 +35,7 @@ export interface AiRuntimeConfig {
|
||||
timeoutMs: number;
|
||||
}
|
||||
|
||||
/** RocketMQ 公共寻址配置;实际生产/消费参数由相应进程扩展。 */
|
||||
export interface RocketMqRuntimeConfig {
|
||||
enabled: boolean;
|
||||
nameServerAddress: string;
|
||||
@@ -44,6 +50,7 @@ interface CommonRuntimeConfig {
|
||||
redis: RedisRuntimeConfig;
|
||||
}
|
||||
|
||||
/** API 仅获得 HTTP、Redis、MySQL 与可选 AI 配置,不读取调度和消费配置。 */
|
||||
export interface ApiRuntimeConfig extends CommonRuntimeConfig {
|
||||
processName: 'api';
|
||||
api: Readonly<{ host: string; port: number }>;
|
||||
@@ -51,12 +58,14 @@ export interface ApiRuntimeConfig extends CommonRuntimeConfig {
|
||||
ai: AiRuntimeConfig;
|
||||
}
|
||||
|
||||
/** Scheduler 只决定何时投递,因此不获得 MySQL、行情源或 AI 凭据。 */
|
||||
export interface SchedulerRuntimeConfig extends CommonRuntimeConfig {
|
||||
processName: 'scheduler';
|
||||
scheduler: Readonly<{ enabled: boolean; timezone: 'Asia/Shanghai' }>;
|
||||
rocketMq: RocketMqRuntimeConfig & Readonly<{ sendTimeoutMs: number }>;
|
||||
}
|
||||
|
||||
/** Worker 获得执行任务所需配置,但不读取 API 监听或 Scheduler 开关。 */
|
||||
export interface WorkerRuntimeConfig extends CommonRuntimeConfig {
|
||||
processName: 'worker';
|
||||
marketData: Readonly<{
|
||||
@@ -71,6 +80,7 @@ export interface WorkerRuntimeConfig extends CommonRuntimeConfig {
|
||||
ai: AiRuntimeConfig;
|
||||
}
|
||||
|
||||
/** 三类配置的联合类型仅用于安全摘要等跨进程基础能力。 */
|
||||
export type RuntimeConfig = ApiRuntimeConfig | SchedulerRuntimeConfig | WorkerRuntimeConfig;
|
||||
type EnvironmentSource = Readonly<Record<string, string | undefined>>;
|
||||
|
||||
@@ -205,6 +215,7 @@ function loadRocketMqConfig(env: EnvironmentSource): RocketMqRuntimeConfig {
|
||||
};
|
||||
}
|
||||
|
||||
/** 从 API 专属环境变量生成深冻结配置,启动后禁止被运行时代码改写。 */
|
||||
export function loadApiConfig(env: EnvironmentSource): ApiRuntimeConfig {
|
||||
return deepFreeze({
|
||||
processName: 'api',
|
||||
@@ -220,6 +231,7 @@ export function loadApiConfig(env: EnvironmentSource): ApiRuntimeConfig {
|
||||
}) as ApiRuntimeConfig;
|
||||
}
|
||||
|
||||
/** 从 Scheduler 专属变量生成深冻结配置,并保持 RocketMQ 默认禁用边界。 */
|
||||
export function loadSchedulerConfig(env: EnvironmentSource): SchedulerRuntimeConfig {
|
||||
const rocketMq = loadRocketMqConfig(env);
|
||||
return deepFreeze({
|
||||
@@ -241,6 +253,7 @@ export function loadSchedulerConfig(env: EnvironmentSource): SchedulerRuntimeCon
|
||||
}) as SchedulerRuntimeConfig;
|
||||
}
|
||||
|
||||
/** 从 Worker 专属变量生成深冻结配置,并阻止生产环境使用模拟行情。 */
|
||||
export function loadWorkerConfig(env: EnvironmentSource): WorkerRuntimeConfig {
|
||||
const appEnv = loadAppEnv(env);
|
||||
const mode = parseEnum(env, 'MARKET_DATA_MODE', ['mock', 'live']);
|
||||
@@ -275,6 +288,7 @@ export function loadWorkerConfig(env: EnvironmentSource): WorkerRuntimeConfig {
|
||||
}) as WorkerRuntimeConfig;
|
||||
}
|
||||
|
||||
/** 日志只保留诊断所需的非敏感字段,绝不序列化密码、Token 或 API Key。 */
|
||||
export function toSafeRuntimeSummary(config: RuntimeConfig): Readonly<Record<string, unknown>> {
|
||||
const summary: Record<string, unknown> = {
|
||||
processName: config.processName,
|
||||
|
||||
Reference in New Issue
Block a user