
























@@ -1,7 +1,11 @@
11import { afterEach, describe, expect, it } from "vitest";
22import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js";
33import { createRunningTaskRun } from "./task-executor.js";
4-import { listTaskFlowAuditFindings } from "./task-flow-registry.audit.js";
4+import {
5+listTaskFlowAuditFindings,
6+type TaskFlowAuditCode,
7+type TaskFlowAuditFinding,
8+} from "./task-flow-registry.audit.js";
59import {
610createManagedTaskFlow,
711resetTaskFlowRegistryForTests,
@@ -15,6 +19,21 @@ import {
15191620const ORIGINAL_STATE_DIR = process.env.OPENCLAW_STATE_DIR;
172122+function requireFinding(
23+findings: TaskFlowAuditFinding[],
24+code: TaskFlowAuditCode,
25+flowId?: string,
26+): TaskFlowAuditFinding {
27+const finding = findings.find(
28+(candidate) =>
29+candidate.code === code && (flowId === undefined || candidate.flow?.flowId === flowId),
30+);
31+if (!finding) {
32+throw new Error(`Expected ${code} finding${flowId ? ` for ${flowId}` : ""}`);
33+}
34+return finding;
35+}
36+1837async function withTaskFlowAuditStateDir(run: (root: string) => Promise<void>): Promise<void> {
1938await withOpenClawTestState(
2039{
@@ -58,13 +77,11 @@ describe("task-flow-registry audit", () => {
5877},
5978});
607961-expect(listTaskFlowAuditFindings()).toEqual([
62-expect.objectContaining({
63-severity: "error",
64-code: "restore_failed",
65-detail: expect.stringContaining("boom"),
66-}),
67-]);
80+const findings = listTaskFlowAuditFindings();
81+expect(findings).toHaveLength(1);
82+expect(findings[0]?.severity).toBe("error");
83+expect(findings[0]?.code).toBe("restore_failed");
84+expect(findings[0]?.detail).toContain("boom");
6885});
69867087it("clears restore-failed findings after a clean reset and restore", () => {
@@ -77,11 +94,9 @@ describe("task-flow-registry audit", () => {
7794},
7895});
799680-expect(listTaskFlowAuditFindings()).toEqual([
81-expect.objectContaining({
82-code: "restore_failed",
83-}),
84-]);
97+const findings = listTaskFlowAuditFindings();
98+expect(findings).toHaveLength(1);
99+expect(findings[0]?.code).toBe("restore_failed");
8510086101resetTaskFlowRegistryForTests({ persist: false });
87102configureTaskFlowRegistryRuntime({
@@ -124,17 +139,11 @@ describe("task-flow-registry audit", () => {
124139});
125140126141const findings = listTaskFlowAuditFindings({ now: 31 * 60_000 });
127-expect(findings).toEqual(
128-expect.arrayContaining([
129-expect.objectContaining({
130-code: "missing_linked_tasks",
131-flow: expect.objectContaining({ flowId: running.flowId }),
132-}),
133-expect.objectContaining({
134-code: "blocked_task_missing",
135-flow: expect.objectContaining({ flowId: blocked.flowId }),
136-}),
137-]),
142+expect(requireFinding(findings, "missing_linked_tasks", running.flowId).flow?.flowId).toBe(
143+running.flowId,
144+);
145+expect(requireFinding(findings, "blocked_task_missing", blocked.flowId).flow?.flowId).toBe(
146+blocked.flowId,
138147);
139148});
140149});
@@ -162,14 +171,13 @@ describe("task-flow-registry audit", () => {
162171lastEventAt: 1,
163172});
164173165-expect(listTaskFlowAuditFindings({ now: 31 * 60_000 })).not.toEqual(
166-expect.arrayContaining([
167-expect.objectContaining({
168-code: "missing_linked_tasks",
169-flow: expect.objectContaining({ flowId: flow.flowId }),
170-}),
171-]),
172-);
174+const findings = listTaskFlowAuditFindings({ now: 31 * 60_000 });
175+expect(
176+findings.some(
177+(finding) =>
178+finding.code === "missing_linked_tasks" && finding.flow?.flowId === flow.flowId,
179+),
180+).toBe(false);
173181});
174182});
175183@@ -191,13 +199,9 @@ describe("task-flow-registry audit", () => {
191199),
192200).toBeUndefined();
193201194-expect(listTaskFlowAuditFindings({ now: now + 26 * 60_000 })).toEqual(
195-expect.arrayContaining([
196-expect.objectContaining({
197-code: "missing_linked_tasks",
198-flow: expect.objectContaining({ flowId: flow.flowId }),
199-}),
200-]),
202+const staleFindings = listTaskFlowAuditFindings({ now: now + 26 * 60_000 });
203+expect(requireFinding(staleFindings, "missing_linked_tasks", flow.flowId).flow?.flowId).toBe(
204+flow.flowId,
201205);
202206});
203207});
@@ -214,14 +218,8 @@ describe("task-flow-registry audit", () => {
214218updatedAt: 100,
215219});
216220217-expect(listTaskFlowAuditFindings({ now: 6 * 60_000 })).toEqual(
218-expect.arrayContaining([
219-expect.objectContaining({
220-code: "cancel_stuck",
221-flow: expect.objectContaining({ flowId: flow.flowId }),
222-}),
223-]),
224-);
221+const findings = listTaskFlowAuditFindings({ now: 6 * 60_000 });
222+expect(requireFinding(findings, "cancel_stuck", flow.flowId).flow?.flowId).toBe(flow.flowId);
225223});
226224});
227225});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。