Piper 的 chooses 刷新与删除检查业务码,保留空成功响应。主保存成功后刷新失败抛出携带已保存版本的 WorkflowSavePartialError;统一 JSON 错误保留可选 EkbError.details。 workflow save 在部分成功时返回非零与恢复信息,--in-place 仍同步已保存版本;新增带写确认的 refresh-chooses,仅重试元数据刷新,不重发完整快照。主保存失败不改本地版本。 认证重放保留最终鉴权响应检查(含 HTTP 200 的错误头),最多重放一次,其他 HTTP 错误维持 Ky 语义。补充 SDK、CLI、恢复与重放回归,并更新文档。 验证:bun test 922 通过、0 失败;bun run check、git diff --check 通过。所有业务请求均为离线假接口。
55 lines
3.0 KiB
TypeScript
55 lines
3.0 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import ky from "ky";
|
|
import { deleteWorkflow, updateWorkflowChooses } from "./api.js";
|
|
import { refreshWorkflowChooses, updateWorkflow } from "./services.js";
|
|
import { WorkflowDetailSchema } from "./types.js";
|
|
import { WorkflowSavePartialError } from "./workflow/save-error.js";
|
|
import { AuthenticationError } from "../../core/errors.js";
|
|
|
|
test("Piper 无返回值写操作兼容空成功,拒绝业务失败与无效 JSON", async () => {
|
|
for (const action of [deleteWorkflow, updateWorkflowChooses]) {
|
|
for (const body of ["", JSON.stringify({ code: 200, data: [] })]) {
|
|
const client = ky.create({ prefix: "https://piper.invalid", retry: 0, fetch: async () => new Response(body) });
|
|
await action(client, "p");
|
|
}
|
|
for (const body of [JSON.stringify({ code: 500, msg: "拒绝写入" }), "{broken"]) {
|
|
const client = ky.create({ prefix: "https://piper.invalid", retry: 0, fetch: async () => new Response(body) });
|
|
await expect(action(client, "p")).rejects.toThrow();
|
|
}
|
|
const client = ky.create({ prefix: "https://piper.invalid", retry: 0, fetch: async () => Response.json({ code: 401, msg: "凭证失效" }) });
|
|
await expect(action(client, "p")).rejects.toBeInstanceOf(AuthenticationError);
|
|
}
|
|
});
|
|
|
|
test("两阶段保存保留已提交版本,恢复只刷新 chooses", async () => {
|
|
const workflow = WorkflowDetailSchema.parse({ id: "p", version: "v1", tasksVersion: 1 });
|
|
const calls: string[] = [];
|
|
let failRefresh = true;
|
|
const client = ky.create({ prefix: "https://piper.invalid", retry: 0, fetch: async input => {
|
|
const path = new URL(input instanceof Request ? input.url : input.toString()).pathname;
|
|
calls.push(path);
|
|
return path.endsWith("/chooses")
|
|
? Response.json(failRefresh ? { code: 500, msg: "刷新拒绝" } : { code: 200, data: [] })
|
|
: Response.json({ code: 200, data: { ...workflow, tasksVersion: 2 } });
|
|
} });
|
|
let partial: WorkflowSavePartialError | undefined;
|
|
try { await updateWorkflow(client, workflow); }
|
|
catch (error) { expect(error).toBeInstanceOf(WorkflowSavePartialError); partial = error as WorkflowSavePartialError; }
|
|
expect(partial?.savedWorkflow.tasksVersion).toBe(2);
|
|
expect(partial?.details).toMatchObject({ remoteSaved: true, failedStep: "chooses", saved: { tasksVersion: 2 } });
|
|
failRefresh = false;
|
|
await refreshWorkflowChooses(client, "p");
|
|
expect(calls).toEqual(["/api/easo/pipelines/p", "/api/easo/pipelines/p/chooses", "/api/easo/pipelines/p/chooses"]);
|
|
});
|
|
|
|
test("主保存失败不会刷新 chooses,也不报告部分成功", async () => {
|
|
const calls: string[] = [];
|
|
const client = ky.create({ prefix: "https://piper.invalid", retry: 0, fetch: async input => {
|
|
calls.push(input instanceof Request ? input.url : input.toString());
|
|
return Response.json({ code: 500, msg: "主保存拒绝" });
|
|
} });
|
|
const error = await updateWorkflow(client, WorkflowDetailSchema.parse({ id: "p" })).catch(error => error);
|
|
expect(error).not.toBeInstanceOf(WorkflowSavePartialError);
|
|
expect(calls).toHaveLength(1);
|
|
});
|