fix(workflow): 复刻前端保存的 $platformId 与 chooses 刷新

- 全量保存时自动补充 inputs: [{$platformId}],避免平台把内置节点 desc 重置为「」
- 保存后调用 pipelines/{id}/chooses,与前端“保存更新”保持一致
- createWorkflowDetailClient 返回当前 platformId,node add/edit/map/rm 保存路径传入
- 更新保存/节点编排测试 mock,重新生成 dist/mcp/server.js
This commit is contained in:
gitea committed 2026-10-28 10:56:02 +08:00
1 parent efb5b0e1bd
commit 1d24c022ab
8 files changed
+401 -361

No files matched your search

+346 -346
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -1522,6 +1522,9 @@ describe("CLI - workflow job 执行详情与异常精准透视", () => {
return { json: async () => ({ code: 200, data: null }) };
},
put: (url: string, opts: any) => {
if (url.endsWith("/chooses")) {
return { json: async () => ({ code: 200, data: [] }) };
}
if (url.includes("api/easo/pipelines/pipe_node_test")) {
savedWorkflowPayload = opts.json;
return {
+10 -10
View File
@@ -133,7 +133,7 @@ async function handleListNodes(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const tasks = detail.tasks || [];
const flattened = flattenWorkflowTaskTree(tasks);
@@ -190,7 +190,7 @@ async function handleGetNode(
};
}
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const located = findWorkflowTask(detail.tasks || [], nodeTarget);
@@ -290,7 +290,7 @@ async function handleAddNode(
`hose-use workflow node add ${pipelineId} --type=${type}${label ? ` --label="${label}"` : ""}${displayName ? ` --display-name="${displayName}"` : ""}${parent ? ` --parent="${parent}"` : ""}${after ? ` --after="${after}"` : ""} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const { workflow: updatedWorkflow, newTask } = addWorkflowTask(detail, {
@@ -315,7 +315,7 @@ async function handleAddNode(
});
}
const saveResult = await updateWorkflow(client, updatedWorkflow);
const saveResult = await updateWorkflow(client, updatedWorkflow, platformId);
if (runtime.jsonMode) {
return {
@@ -410,7 +410,7 @@ async function handleEditNode(
`hose-use workflow node edit ${pipelineId} ${nodeTarget}${label ? ` --label="${label}"` : ""}${displayName ? ` --display-name="${displayName}"` : ""} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const { workflow: updatedWorkflow, editedTask } = editWorkflowTask(detail, nodeTarget, {
@@ -436,7 +436,7 @@ async function handleEditNode(
});
}
const saveResult = await updateWorkflow(client, updatedWorkflow);
const saveResult = await updateWorkflow(client, updatedWorkflow, platformId);
if (runtime.jsonMode) {
return {
@@ -516,7 +516,7 @@ async function handleMapNode(
`hose-use workflow node map ${pipelineId} ${nodeTarget} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const { workflow: updatedWorkflow, editedTask, changedKeys } = applyNodeMapping(detail, nodeTarget, mappingData);
@@ -534,7 +534,7 @@ async function handleMapNode(
});
}
const saveResult = await updateWorkflow(client, updatedWorkflow);
const saveResult = await updateWorkflow(client, updatedWorkflow, platformId);
if (runtime.jsonMode) {
return {
@@ -572,7 +572,7 @@ async function handleRemoveNode(
`hose-use workflow node rm ${pipelineId} ${nodeTarget} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const { client, platformId } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
const detail = await getWorkflowDetail(client, pipelineId);
const { workflow: updatedWorkflow, removedTask } = removeWorkflowTask(detail, nodeTarget);
@@ -587,7 +587,7 @@ async function handleRemoveNode(
});
}
const saveResult = await updateWorkflow(client, updatedWorkflow);
const saveResult = await updateWorkflow(client, updatedWorkflow, platformId);
if (runtime.jsonMode) {
return {
+2
View File
@@ -12,6 +12,7 @@ export async function createWorkflowDetailClient(
): Promise<{
client: Awaited<ReturnType<typeof createPiperClientForCorp>>;
clients: Awaited<ReturnType<typeof createClientsForCorp>>;
platformId?: string;
}> {
const clients = await createClientsForCorp(runtime.selectedCorp!);
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
@@ -30,6 +31,7 @@ export async function createWorkflowDetailClient(
return {
client: platformId ? await createPiperClientForCorp(runtime.selectedCorp!, platformId) : clients.easoClient,
clients,
platformId,
};
}
+15 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { getWorkflowSnapshot } from "./api.js";
import { getWorkflowSnapshot, updateWorkflowChooses } from "./api.js";
describe("workflow snapshot API", () => {
it("uses the piper pipelines/snapshot endpoint first", async () => {
@@ -23,4 +23,18 @@ describe("workflow snapshot API", () => {
expect(snapshot.id).toBe("snap-1");
expect(snapshot.version).toBe("26.10.7");
});
it("refreshes chooses after the pipeline save", async () => {
const calls: string[] = [];
const client = {
put: async (path: string) => {
calls.push(path);
return new Response(JSON.stringify({ code: 200, data: [] }), { status: 200, headers: { "content-type": "application/json" } });
},
} as any;
await updateWorkflowChooses(client, "pipe-1");
expect(calls).toEqual(["api/easo/pipelines/pipe-1/chooses"]);
});
});
+11
View File
@@ -144,6 +144,17 @@ export async function updateWorkflow(
return unwrap(response, WorkflowDetailSchema);
}
/**
* 前端“保存更新”在主线 PUT 之后还会调用该接口(无 body),
* 由平台重新生成 choose/描述元数据;CLI 保存必须保持一致,否则内置节点 desc 会变成「」。
*/
export async function updateWorkflowChooses(
client: KyInstance,
pipelineId: string
): Promise<void> {
await client.put(`api/easo/pipelines/${pipelineId}/chooses`);
}
export async function copyWorkflow(
client: KyInstance,
pipelineId: string,
+12 -4
View File
@@ -64,12 +64,20 @@ export function sanitizeWorkflowSnapshot(
return cloned;
}
export function updateWorkflow(
export async function updateWorkflow(
client: KyInstance,
workflow: import("./types.js").WorkflowDetail
workflow: import("./types.js").WorkflowDetail,
platformId?: string
) {
const sanitized = sanitizeWorkflowSnapshot(workflow);
return api.updateWorkflow(client, sanitized);
// 前端保存时会带上触发输入 $platformId;缺少它会导致平台把内置节点 desc 重置为「」。
const payload: import("./types.js").WorkflowDetail = platformId && !workflow.inputs?.length
? { ...workflow, inputs: [{ key: "$platformId", value: platformId }] }
: workflow;
const sanitized = sanitizeWorkflowSnapshot(payload);
const updated = await api.updateWorkflow(client, sanitized);
// 复刻前端“保存更新”:主线 PUT 之后刷新 chooses。
await api.updateWorkflowChooses(client, updated.id || workflow.id);
return updated;
}
export async function copyWorkflow(
@@ -67,6 +67,7 @@ describe("workflow draft state machine", () => {
let request: { url: string; json: WorkflowDetail } | undefined;
const client = {
put: async (url: string, options: { json: WorkflowDetail }) => {
if (url.endsWith("/chooses")) return { json: async () => ({ data: [] }) };
request = { url, json: options.json };
return { json: async () => ({ data: options.json }) };
},
@@ -82,6 +83,7 @@ describe("workflow draft state machine", () => {
let sentWorkflow: WorkflowDetail | undefined;
const client = {
put: async (url: string, options: { json: WorkflowDetail }) => {
if (url.endsWith("/chooses")) return { json: async () => ({ data: [] }) };
sentWorkflow = options.json;
return { json: async () => ({ data: options.json }) };
},