fix(workflow): 启停结果改为回读确认,不再依赖 HTTP 状态码

生产启停此前用 ok() 判定结果,该函数只读 response.status 是否等于 200:
- 漏掉 HTTP 200 携带 code != 200 的业务失败,与 README「HTTP 200 不等于业务成功」冲突;
- 反向也会错,服务端 204 成功会被判成失败。

本次调整:
- 删除 transport/response.ts 的 ok(),消除这一判定来源;
- toggleWorkflowState 改用 readEasoWriteResponse 校验 EASO 业务码;
- management toggleWorkflow 写操作后回读详情确认状态,未变化抛 BusinessError
  (WORKFLOW_STATE_NOT_APPLIED),回读失败返回 verified: false,不谎称已生效;
- lifecycle handleToggle 此前完全不看返回值,无条件输出 [SUCCESS] 且 exitCode 0,
  现按 verified 给出 stderr 与退出码;handlePublish 同步调整;
- 新增 WorkflowToggleResult 模型并从 services 导出;
- 测试覆盖四种情形:回读确认成功、状态未生效、业务失败、回读失败。
This commit is contained in:
gitea committed 2026-11-01 21:35:22 +08:00
1 parent eb9b979943
commit 6dc96a5eb9
7 files changed
+125 -21

No files matched your search

+22 -5
View File
@@ -29,13 +29,27 @@ export async function handleToggle(parsed: CliParsedArgs, runtime: CliRuntime):
}
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const result = await toggleWorkflow(client, pipelineId, state);
const label = state === 1 ? "🟢 启用" : "⚪ 停用";
if (runtime.jsonMode) {
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
return {
stdout: printJson(result, runtime.outputOptions),
stderr: "",
exitCode: result.verified ? 0 : 1,
};
}
// 启停未回读确认时必须如实告知:不得把「请求已提交」呈现为「已生效」。
if (!result.verified) {
return {
stdout: "",
stderr: `[WARNING] 工作流 ${pipelineId} 启停请求已提交,但${result.message}\n`,
exitCode: 1,
};
}
return {
stdout: `[SUCCESS] 工作流 ${pipelineId} 状态已更新为: ${state === 1 ? "🟢 启用" : "⚪ 停用"}\n`,
stdout: `[SUCCESS] 工作流 ${pipelineId} 状态已更新为: ${label}(已回读确认)\n`,
stderr: "",
exitCode: 0,
};
@@ -55,7 +69,10 @@ export async function handlePublish(parsed: CliParsedArgs, runtime: CliRuntime):
}
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const result = await toggleWorkflow(client, pipelineId, 1);
const output = { success: result.success, pipelineId, published: result.success, state: 1 };
if (runtime.jsonMode) return { stdout: printJson(output, runtime.outputOptions), stderr: "", exitCode: result.success ? 0 : 1 };
return { stdout: result.success ? `✅ 工作流 [${pipelineId}] 已发布并启用。\n` : `❌ 工作流 [${pipelineId}] 发布失败。\n`, stderr: "", exitCode: result.success ? 0 : 1 };
const output = { success: result.verified, pipelineId, published: result.verified, state: 1, verified: result.verified, message: result.message };
if (runtime.jsonMode) return { stdout: printJson(output, runtime.outputOptions), stderr: "", exitCode: result.verified ? 0 : 1 };
if (!result.verified) {
return { stdout: "", stderr: `❌ 工作流 [${pipelineId}] 发布状态未能确认:${result.message}\n`, exitCode: 1 };
}
return { stdout: `✅ 工作流 [${pipelineId}] 已发布并启用(已回读确认)。\n`, stderr: "", exitCode: 0 };
}