diff --git a/src/domains/platform/workflow/README.workflow.md b/src/domains/platform/workflow/README.workflow.md index 41d1f8e..e6bef85 100644 --- a/src/domains/platform/workflow/README.workflow.md +++ b/src/domains/platform/workflow/README.workflow.md @@ -213,3 +213,8 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 ` | [catalog.ts](./catalog.ts) | DSL、节点权限、枚举字典与回退 | 内部实现直接导入所属模块,不反向导入 services 门面。watch 的 tracker 使用 execution,工作流报告类型直接引用 branch/types,避免通过聚合出口形成循环。跨应用查询只通过 applications 的公开业务服务取得应用;各子模块禁止绕过服务直接调用兄弟模块 api。 + + +## 空历史快照兼容 + +Piper 对没有快照的新工作流可能返回 `items: null`。快照列表 API 将该字段归一化为 `[]`,保留分页数据;其他错误类型、无效条目、空详情及业务错误仍拒绝。该兼容仅在传输层处理,不改变工作流结构导出的模型。 diff --git a/src/domains/platform/workflow/api.test.ts b/src/domains/platform/workflow/api.test.ts index fd68ba1..31f99d0 100644 --- a/src/domains/platform/workflow/api.test.ts +++ b/src/domains/platform/workflow/api.test.ts @@ -1,7 +1,22 @@ import { describe, expect, it } from "bun:test"; -import { getWorkflowSnapshot, updateWorkflowChooses } from "./api.js"; +import { getWorkflowSnapshot, updateWorkflowChooses, listWorkflowSnapshots } from "./api.js"; describe("workflow snapshot API", () => { + it("normalizes null or missing snapshot items without losing pagination", async () => { + for (const items of [null, undefined, []]) { + const client = { get: async () => Response.json({ code: 200, data: { number: 2, size: 10, totalItems: 0, items } }) } as any; + expect(await listWorkflowSnapshots(client, "fixture")).toEqual({ number: 2, size: 10, totalPages: 0, totalItems: 0, items: [] }); + } + }); + + it("keeps snapshot entries and rejects malformed items or business failures", async () => { + const query = (body: unknown) => listWorkflowSnapshots({ get: async () => Response.json(body) } as any, "fixture"); + expect((await query({ code: 200, data: { items: [{ id: "snapshot", pipelineId: "fixture" }] } })).items[0]?.id).toBe("snapshot"); + for (const items of ["bad", {}, [{}]]) await expect(query({ code: 200, data: { items } })).rejects.toThrow(); + await expect(query({ code: 403, msg: "denied", data: { items: null } })).rejects.toThrow("denied"); + await expect(query({ code: 200, data: null })).rejects.toThrow(); + }); + it("uses the piper pipelines/snapshot endpoint first", async () => { const calls: string[] = []; const client = { diff --git a/src/domains/platform/workflow/api.ts b/src/domains/platform/workflow/api.ts index a437f60..b058751 100644 --- a/src/domains/platform/workflow/api.ts +++ b/src/domains/platform/workflow/api.ts @@ -195,7 +195,10 @@ export async function listWorkflowSnapshots( const response = await client.get(`api/easo/pipelines/${pipelineId}/snapshots`, { searchParams: { number: String(page), pageSize: String(pageSize) }, }); - return unwrap(response, WorkflowSnapshotPageSchema); + // 新工作流没有历史快照时,Piper 将 items 返回为 null;仅归一化空集合,保留其他校验。 + return unwrap(response, WorkflowSnapshotPageSchema.extend({ + items: WorkflowSnapshotPageSchema.shape.items.nullable().transform(items => items ?? []), + })); } export async function getWorkflowSnapshot(