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
@@ -213,3 +213,8 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 `
|
|||||||
| [catalog.ts](./catalog.ts) | DSL、节点权限、枚举字典与回退 |
|
| [catalog.ts](./catalog.ts) | DSL、节点权限、枚举字典与回退 |
|
||||||
|
|
||||||
内部实现直接导入所属模块,不反向导入 services 门面。watch 的 tracker 使用 execution,工作流报告类型直接引用 branch/types,避免通过聚合出口形成循环。跨应用查询只通过 applications 的公开业务服务取得应用;各子模块禁止绕过服务直接调用兄弟模块 api。
|
内部实现直接导入所属模块,不反向导入 services 门面。watch 的 tracker 使用 execution,工作流报告类型直接引用 branch/types,避免通过聚合出口形成循环。跨应用查询只通过 applications 的公开业务服务取得应用;各子模块禁止绕过服务直接调用兄弟模块 api。
|
||||||
|
|
||||||
|
|
||||||
|
## 空历史快照兼容
|
||||||
|
|
||||||
|
Piper 对没有快照的新工作流可能返回 `items: null`。快照列表 API 将该字段归一化为 `[]`,保留分页数据;其他错误类型、无效条目、空详情及业务错误仍拒绝。该兼容仅在传输层处理,不改变工作流结构导出的模型。
|
||||||
@@ -1,7 +1,22 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "bun:test";
|
||||||
import { getWorkflowSnapshot, updateWorkflowChooses } from "./api.js";
|
import { getWorkflowSnapshot, updateWorkflowChooses, listWorkflowSnapshots } from "./api.js";
|
||||||
|
|
||||||
describe("workflow snapshot API", () => {
|
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 () => {
|
it("uses the piper pipelines/snapshot endpoint first", async () => {
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
const client = {
|
const client = {
|
||||||
|
|||||||
@@ -195,7 +195,10 @@ export async function listWorkflowSnapshots(
|
|||||||
const response = await client.get(`api/easo/pipelines/${pipelineId}/snapshots`, {
|
const response = await client.get(`api/easo/pipelines/${pipelineId}/snapshots`, {
|
||||||
searchParams: { number: String(page), pageSize: String(pageSize) },
|
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(
|
export async function getWorkflowSnapshot(
|
||||||
|
|||||||
Reference in new issue
Block a user