mirror of https://github.com/openclaw/openclaw.git
refactor: share agent wait dedupe test entries
This commit is contained in:
parent
db9c755045
commit
31c8bb9167
|
|
@ -7,6 +7,25 @@ import {
|
|||
} from "./agent-wait-dedupe.js";
|
||||
|
||||
describe("agent wait dedupe helper", () => {
|
||||
function setRunEntry(params: {
|
||||
dedupe: Map<unknown, unknown>;
|
||||
kind: "agent" | "chat";
|
||||
runId: string;
|
||||
ts?: number;
|
||||
ok?: boolean;
|
||||
payload: Record<string, unknown>;
|
||||
}) {
|
||||
setGatewayDedupeEntry({
|
||||
dedupe: params.dedupe,
|
||||
key: `${params.kind}:${params.runId}`,
|
||||
entry: {
|
||||
ts: params.ts ?? Date.now(),
|
||||
ok: params.ok ?? true,
|
||||
payload: params.payload,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
__testing.resetWaiters();
|
||||
vi.useFakeTimers();
|
||||
|
|
@ -29,18 +48,15 @@ describe("agent wait dedupe helper", () => {
|
|||
await Promise.resolve();
|
||||
expect(__testing.getWaiterCount(runId)).toBe(1);
|
||||
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 100,
|
||||
endedAt: 200,
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 100,
|
||||
endedAt: 200,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -56,28 +72,22 @@ describe("agent wait dedupe helper", () => {
|
|||
it("keeps stale chat dedupe blocked while agent dedupe is in-flight", async () => {
|
||||
const dedupe = new Map();
|
||||
const runId = "run-stale-chat";
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
},
|
||||
});
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `agent:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "accepted",
|
||||
},
|
||||
kind: "agent",
|
||||
runId,
|
||||
payload: {
|
||||
runId,
|
||||
status: "accepted",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -100,30 +110,26 @@ describe("agent wait dedupe helper", () => {
|
|||
it("uses newer terminal chat snapshot when agent entry is non-terminal", () => {
|
||||
const dedupe = new Map();
|
||||
const runId = "run-nonterminal-agent-with-newer-chat";
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `agent:${runId}`,
|
||||
entry: {
|
||||
ts: 100,
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "accepted",
|
||||
},
|
||||
kind: "agent",
|
||||
runId,
|
||||
ts: 100,
|
||||
payload: {
|
||||
runId,
|
||||
status: "accepted",
|
||||
},
|
||||
});
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: 200,
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 1,
|
||||
endedAt: 2,
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
ts: 200,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 1,
|
||||
endedAt: 2,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -143,16 +149,13 @@ describe("agent wait dedupe helper", () => {
|
|||
it("ignores stale agent snapshots when waiting for an active chat run", async () => {
|
||||
const dedupe = new Map();
|
||||
const runId = "run-chat-active-ignore-agent";
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `agent:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
},
|
||||
kind: "agent",
|
||||
runId,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -173,18 +176,15 @@ describe("agent wait dedupe helper", () => {
|
|||
await Promise.resolve();
|
||||
expect(__testing.getWaiterCount(runId)).toBe(1);
|
||||
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 123,
|
||||
endedAt: 456,
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
payload: {
|
||||
runId,
|
||||
status: "ok",
|
||||
startedAt: 123,
|
||||
endedAt: 456,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -200,23 +200,20 @@ describe("agent wait dedupe helper", () => {
|
|||
const runId = "run-collision";
|
||||
const dedupe = new Map();
|
||||
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `agent:${runId}`,
|
||||
entry: {
|
||||
ts: 100,
|
||||
ok: true,
|
||||
payload: { runId, status: "ok", startedAt: 10, endedAt: 20 },
|
||||
},
|
||||
kind: "agent",
|
||||
runId,
|
||||
ts: 100,
|
||||
payload: { runId, status: "ok", startedAt: 10, endedAt: 20 },
|
||||
});
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: 200,
|
||||
ok: false,
|
||||
payload: { runId, status: "error", startedAt: 30, endedAt: 40, error: "chat failed" },
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
ts: 200,
|
||||
ok: false,
|
||||
payload: { runId, status: "error", startedAt: 30, endedAt: 40, error: "chat failed" },
|
||||
});
|
||||
|
||||
expect(
|
||||
|
|
@ -232,23 +229,19 @@ describe("agent wait dedupe helper", () => {
|
|||
});
|
||||
|
||||
const dedupeReverse = new Map();
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe: dedupeReverse,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: 100,
|
||||
ok: true,
|
||||
payload: { runId, status: "ok", startedAt: 1, endedAt: 2 },
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
ts: 100,
|
||||
payload: { runId, status: "ok", startedAt: 1, endedAt: 2 },
|
||||
});
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe: dedupeReverse,
|
||||
key: `agent:${runId}`,
|
||||
entry: {
|
||||
ts: 200,
|
||||
ok: true,
|
||||
payload: { runId, status: "timeout", startedAt: 3, endedAt: 4, error: "still running" },
|
||||
},
|
||||
kind: "agent",
|
||||
runId,
|
||||
ts: 200,
|
||||
payload: { runId, status: "timeout", startedAt: 3, endedAt: 4, error: "still running" },
|
||||
});
|
||||
|
||||
expect(
|
||||
|
|
@ -281,14 +274,11 @@ describe("agent wait dedupe helper", () => {
|
|||
await Promise.resolve();
|
||||
expect(__testing.getWaiterCount(runId)).toBe(2);
|
||||
|
||||
setGatewayDedupeEntry({
|
||||
setRunEntry({
|
||||
dedupe,
|
||||
key: `chat:${runId}`,
|
||||
entry: {
|
||||
ts: Date.now(),
|
||||
ok: true,
|
||||
payload: { runId, status: "ok" },
|
||||
},
|
||||
kind: "chat",
|
||||
runId,
|
||||
payload: { runId, status: "ok" },
|
||||
});
|
||||
|
||||
await expect(first).resolves.toEqual(
|
||||
|
|
|
|||
Loading…
Reference in New Issue