feat(corps): 企业配置增加环境属性与生产安全保护机制
- Schema 扩展: CorpConfigSchema 增加 env ('prod' | 'test' | 'demo') 与 isTest 字段,未知企业保守兜底为 prod
- 智能初判与归一化: inferCorpEnvFromName 依据名称初判环境,normalizeCorpConfig 确保配置持久化时环境对齐
- CLI 视图升级: corps list 与 search 增加「环境」列 (🏭 正式 / 🧪 测试 / 🎪 演示),支持 --test/--prod/--env 筛选
- 环境打标与迁移: 新增 hose-use corps tag 命令,支持单个企业标记与 --migrate-all 批量显式升级持久化
- 生产安全阻断: workflow test 等敏感调试在正式生产环境 (prod) 阻断执行,需显式附加 --force 确认生产风险
- 上下文与探针增强: context、probe、corps current 全面输出企业环境属性
- 测试与文档补全: 覆盖 489 项全量测试并通过 tsc 类型检查
This commit is contained in:
1 parent
908286c1df
commit
af1e11c018
15 files changed
+775
-28
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { isCorpProd } from "../../../core/config/types.js";
|
||||
import {
|
||||
classifyWorkflowTrigger,
|
||||
getWorkflowDebugSource,
|
||||
@@ -33,6 +34,7 @@ export async function handleWorkflowTest(
|
||||
"通用选项:",
|
||||
" --timeout=<ms> 设置轮询超时时间 (默认 15000ms)",
|
||||
" --auto-publish 是否自动发布测试快照 (默认 false)",
|
||||
" --force, -f 允许在正式生产环境 (env: prod) 下执行调试",
|
||||
" --dry-run 只预览,不发起调试",
|
||||
" --yes/--confirm 确认执行真实工作流节点",
|
||||
"",
|
||||
@@ -49,8 +51,13 @@ export async function handleWorkflowTest(
|
||||
const filePath = stringOption(parsed.options, ["file", "path"]);
|
||||
const isEmpty = booleanOption(parsed.options, ["empty", "none"]);
|
||||
const sampleOption = stringOption(parsed.options, ["sample", "sample-id", "sampleId"]);
|
||||
const forceProd = booleanOption(parsed.options, ["force", "f", "allow-prod", "allow-production"]);
|
||||
const isProductionCorp = Boolean(runtime.selectedCorp && isCorpProd(runtime.selectedCorp));
|
||||
|
||||
const warnings = ["调试会在真实环境执行工作流节点,可能改变业务数据、发送通知并生成快照;auto-publish 还可能发布流程。"];
|
||||
if (isProductionCorp) {
|
||||
warnings.push(`⚠️ 当前企业 [${runtime.selectedCorp?.name || runtime.selectedCorp?.id}] 为正式生产环境 (env: prod)!正式执行时需显式追加 --force 参数。`);
|
||||
}
|
||||
const confirmExecution = () => requireMutationConfirmation(parsed, runtime, "执行工作流调试", `hose-use workflow test ${pipelineId} --yes`);
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "执行工作流调试", pipelineId, { flowCodeOrId, rawBody, filePath, empty: isEmpty, autoPublish, timeoutMs, warnings });
|
||||
@@ -314,6 +321,25 @@ export async function handleWorkflowTest(
|
||||
|
||||
// 3. 执行端到端调试测试
|
||||
confirmExecution();
|
||||
|
||||
if (isProductionCorp && !forceProd) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: [
|
||||
`🛑 生产环境安全阻断 (Production Safeguard):`,
|
||||
`当前工作企业 [${runtime.selectedCorp?.name || runtime.selectedCorp?.id}] 被标记为【🏭 正式生产环境】(env: prod)!`,
|
||||
`在正式生产企业执行工作流调试可能产生不可逆的单据流转、第三方系统调用与真实业务变更。`,
|
||||
``,
|
||||
`如确需在生产环境进行带副作用的真实调试,必须显式附加 --force 参数确认生产风险:`,
|
||||
` hose-use workflow test ${pipelineId} ${parsed.raw.filter((a) => !["--yes", "-y", "--dry-run"].includes(a)).slice(2).join(" ")} --yes --force`,
|
||||
``,
|
||||
`建议切换至测试企业进行调试:`,
|
||||
` hose-use corps switch <测试企业ID>`,
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const execution = await runWorkflowDebugTest(client, pipelineId, {
|
||||
flowCodeOrId: targetId,
|
||||
data: customPayload,
|
||||
|
||||
Reference in new issue
Block a user