fix: 表达工作流部分保存结果并校验认证重放
Piper 的 chooses 刷新与删除检查业务码,保留空成功响应。主保存成功后刷新失败抛出携带已保存版本的 WorkflowSavePartialError;统一 JSON 错误保留可选 EkbError.details。 workflow save 在部分成功时返回非零与恢复信息,--in-place 仍同步已保存版本;新增带写确认的 refresh-chooses,仅重试元数据刷新,不重发完整快照。主保存失败不改本地版本。 认证重放保留最终鉴权响应检查(含 HTTP 200 的错误头),最多重放一次,其他 HTTP 错误维持 Ky 语义。补充 SDK、CLI、恢复与重放回归,并更新文档。 验证:bun test 922 通过、0 失败;bun run check、git diff --check 通过。所有业务请求均为离线假接口。
This commit is contained in:
1 parent
51fb54dfe8
commit
55d31e27e6
19 files changed
+298
-23
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { getWorkflowDetail, listAllWorkflows, updateWorkflow } from "../../../domains/platform/services.js";
|
||||
import { EkbError } from "../../../core/errors.js";
|
||||
import { getWorkflowDetail, listAllWorkflows, refreshWorkflowChooses, updateWorkflow } from "../../../domains/platform/services.js";
|
||||
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/save-error.js";
|
||||
import { WorkflowDetailSchema } from "../../../domains/platform/types.js";
|
||||
import {
|
||||
applyWorkflowPathPatch,
|
||||
@@ -137,8 +139,14 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
const payload = state.workflow.inputs?.length
|
||||
? state.workflow
|
||||
: { ...state.workflow, inputs: [{ key: "$platformId", value: platformId }] };
|
||||
const saved = await updateWorkflow(piperClient, payload);
|
||||
let partialError: WorkflowSavePartialError | undefined;
|
||||
const saved = await updateWorkflow(piperClient, payload).catch((error: unknown) => {
|
||||
if (!(error instanceof WorkflowSavePartialError)) throw error;
|
||||
partialError = error;
|
||||
return error.savedWorkflow;
|
||||
});
|
||||
state = commitWorkflowSave(state, saved);
|
||||
if (partialError) state = { ...state, status: "partial", error: partialError.message };
|
||||
let fileSynced = false;
|
||||
let fileSyncWarning = "";
|
||||
if (syncFile) {
|
||||
@@ -155,8 +163,11 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
fileSyncWarning = `本地文件同步失败: ${error instanceof Error ? error.message : String(error)}`;
|
||||
}
|
||||
}
|
||||
const quoteArg = (value: string) => `'${value.replaceAll("'", "'\\''")}'`;
|
||||
const nextAction = `hose-use workflow refresh-chooses ${quoteArg(pipelineId)} --platform-id=${quoteArg(platformId)} --corp=${quoteArg(runtime.selectedCorp!.id)} --yes`;
|
||||
const result = {
|
||||
success: true,
|
||||
success: !partialError,
|
||||
...(partialError ? { remoteSaved: true, failedStep: "chooses", nextAction, message: partialError.message } : {}),
|
||||
pipelineId,
|
||||
status: state.status,
|
||||
version: saved.version,
|
||||
@@ -165,7 +176,12 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
fileSynced,
|
||||
...(fileSyncWarning ? { fileSyncWarning } : {}),
|
||||
};
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: fileSyncWarning, exitCode: 0 };
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: fileSyncWarning, exitCode: partialError ? 1 : 0 };
|
||||
if (partialError) return {
|
||||
stdout: `⚠️ ${partialError.message}\n${fileSynced ? "已同步本地文件版本。\n" : ""}恢复命令: ${nextAction}\n`,
|
||||
stderr: fileSyncWarning,
|
||||
exitCode: 1,
|
||||
};
|
||||
return {
|
||||
stdout: `✅ 工作流 [${pipelineId}] 草稿保存成功:${formatWorkflowVersion(saved)}。${fileSynced ? "\n📝 已同步更新本地文件。" : ""}${fileSyncWarning ? `\n⚠️ ${fileSyncWarning}` : ""}\n`,
|
||||
stderr: fileSyncWarning,
|
||||
@@ -173,10 +189,23 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
};
|
||||
} catch (error) {
|
||||
state = failWorkflowSave(state, error);
|
||||
if (error instanceof EkbError) throw error;
|
||||
throw new Error(`工作流保存失败(${state.status}): ${state.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleRefreshChooses(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
if (!pipelineId) throw new Error("请提供工作流 ID: hose-use workflow refresh-chooses <pipelineId> --yes");
|
||||
requireMutationConfirmation(parsed, runtime, "刷新工作流元数据", `hose-use workflow refresh-chooses ${pipelineId} --yes`);
|
||||
if (isDryRun(parsed, runtime)) return mutationPreview(parsed, runtime, "刷新工作流元数据", pipelineId, { retryStep: "chooses", saveWorkflow: false });
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
const platformId = await resolveWorkflowPlatformId(parsed, clients, pipelineId);
|
||||
const client = await createPiperClientForCorp(runtime.selectedCorp!, platformId);
|
||||
await refreshWorkflowChooses(client, pipelineId);
|
||||
return { stdout: runtime.jsonMode ? printJson({ success: true, pipelineId, metadataRefreshed: true }, runtime.outputOptions) : `工作流 [${pipelineId}] 元数据刷新成功,未重新提交快照。\n`, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
async function resolveWorkflowPlatformId(
|
||||
parsed: CliParsedArgs,
|
||||
clients: Awaited<ReturnType<typeof createClientsForCorp>>,
|
||||
|
||||
Reference in new issue
Block a user