refactor(workflow): 收敛 Job 状态语义与监听事件过滤
同一份逻辑在两个地方各写一遍,必然在某次修改后漂移: - Job 状态判定:watch/helpers.ts 与 execution/debug.ts 各有一份终态集合, 且对数字 state 的解释相反——watch 把 state:0 视为 COMPLETED, debug 把它当成未知继续轮询到超时,同一个 Job 在两条路径上结论相反。 统一到 execution/job-status.ts(watch 已依赖 execution,方向单向), helpers 保留转发导出,debug 删除本地实现;新增两条用例固定该语义。 - --failed-only 事件过滤:pipeline-watcher.ts 与 single-job.ts 逐字重复, 抽为 watch/helpers.ts 的 shouldEmitWatchEvent(),两处调用点同步瘦身。 同步更新 execution 模块 README,说明状态语义的两个入口必须一起考虑。
This commit is contained in:
1 parent
a0058c1c66
commit
71aa9b54a7
7 files changed
+102
-48
No files matched your search
@@ -63,6 +63,35 @@ describe("workflow debug completion evidence", () => {
|
||||
await expect(runWorkflowDebugTest(client, "pipe", { flowCodeOrId: "ID01-record", timeoutMs: -1 })).rejects.toThrow("timeoutMs");
|
||||
expect(posts).toEqual([]);
|
||||
});
|
||||
|
||||
describe("numeric job state must agree with the watch pipeline", () => {
|
||||
const withState = (state: number) => {
|
||||
const { client } = setup();
|
||||
const get = client.get;
|
||||
client.get = async (path: string) => {
|
||||
if (path.endsWith("/job")) {
|
||||
return new Response(JSON.stringify({ code: 200, data: { id: "job", state } }), {
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
return get(path);
|
||||
};
|
||||
return client;
|
||||
};
|
||||
|
||||
it("reads state 0 as completed instead of polling until timeout", async () => {
|
||||
const result = await runWorkflowDebugTest(withState(0), "pipe", { flowCodeOrId: "ID01-record", timeoutMs: 100, pollIntervalMs: 1 });
|
||||
expect(result.status).toBe("COMPLETED");
|
||||
expect(result.outcome).toBe("completed");
|
||||
expect(result.timedOut).toBe(false);
|
||||
});
|
||||
|
||||
it("reads state 1 as still running", async () => {
|
||||
const result = await runWorkflowDebugTest(withState(1), "pipe", { flowCodeOrId: "ID01-record", timeoutMs: 0 });
|
||||
expect(result.status).toBe("RUNNING");
|
||||
expect(result.outcome).toBe("timed_out");
|
||||
});
|
||||
});
|
||||
it("retries a newly created job's HTTP 404 instead of reporting an authorization failure", async () => {
|
||||
const { client } = setup();
|
||||
const get = client.get;
|
||||
|
||||
Reference in new issue
Block a user