fix: 兼容新工作流空历史快照响应
Piper 无快照时可能返回 items 为 null,在传输层归一化为空数组。 保留分页及其他校验,覆盖正常条目、无效集合和业务错误,补充说明。 验证:945 项测试、类型和版本检查通过,README 审计通过。
This commit is contained in:
1 parent
a2cdefb322
commit
306eaa9fa9
3 files changed
+25
-2
No files matched your search
@@ -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 = {
|
||||
|
||||
Reference in new issue
Block a user