fix(workflow): 修正工作流快照 diff 的接口路径
- getWorkflowSnapshot 优先使用前端实际接口 api/easo/pipelines/snapshot/{id}
- 保留既有路径作为兼容回退,修复 workflow diff 的 404
- 增加快照接口路径单测,并重新生成 dist/mcp/server.js
This commit is contained in:
1 parent
1a2e485caa
commit
efb5b0e1bd
3 files changed
+168
-136
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { getWorkflowSnapshot } from "./api.js";
|
||||
|
||||
describe("workflow snapshot API", () => {
|
||||
it("uses the piper pipelines/snapshot endpoint first", async () => {
|
||||
const calls: string[] = [];
|
||||
const client = {
|
||||
get: async (path: string) => {
|
||||
calls.push(path);
|
||||
if (path === "api/easo/pipelines/snapshot/snap-1") {
|
||||
return new Response(JSON.stringify({
|
||||
code: 200,
|
||||
data: { id: "snap-1", pipelineId: "pipe-1", version: "26.10.7" },
|
||||
}), { status: 200, headers: { "content-type": "application/json" } });
|
||||
}
|
||||
throw new Error("unexpected path");
|
||||
},
|
||||
} as any;
|
||||
|
||||
const snapshot = await getWorkflowSnapshot(client, "snap-1", "pipe-1");
|
||||
|
||||
expect(calls).toEqual(["api/easo/pipelines/snapshot/snap-1"]);
|
||||
expect(snapshot.id).toBe("snap-1");
|
||||
expect(snapshot.version).toBe("26.10.7");
|
||||
});
|
||||
});
|
||||
@@ -191,16 +191,22 @@ export async function getWorkflowSnapshot(
|
||||
snapshotId: string,
|
||||
pipelineId?: string
|
||||
): Promise<import("./types.js").WorkflowSnapshot> {
|
||||
try {
|
||||
const response = await client.get(`api/easo/snapshots/${snapshotId}`);
|
||||
return unwrap(response, WorkflowSnapshotSchema);
|
||||
} catch (err) {
|
||||
if (pipelineId) {
|
||||
const response = await client.get(`api/easo/pipelines/${pipelineId}/snapshots/${snapshotId}`);
|
||||
const paths = [
|
||||
// 前端实际使用的快照接口:pipelines/snapshot/{id}
|
||||
`api/easo/pipelines/snapshot/${snapshotId}`,
|
||||
`api/easo/snapshots/${snapshotId}`,
|
||||
...(pipelineId ? [`api/easo/pipelines/${pipelineId}/snapshots/${snapshotId}`] : []),
|
||||
];
|
||||
let lastError: unknown;
|
||||
for (const path of paths) {
|
||||
try {
|
||||
const response = await client.get(path);
|
||||
return unwrap(response, WorkflowSnapshotSchema);
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
||||
}
|
||||
|
||||
export async function listWorkflowLogs(
|
||||
|
||||
Reference in new issue
Block a user