Skip to content

Commit 1052650

Browse files
committed
test(channels): split ingress admission coverage
1 parent 4788e94 commit 1052650

2 files changed

Lines changed: 51 additions & 24 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { afterEach, describe, expect, it, vi } from "vitest";
2+
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
3+
import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js";
4+
import { createChannelIngressMonitor } from "./ingress-monitor.js";
5+
import { createChannelIngressQueue } from "./ingress-queue.js";
6+
7+
type RawEvent = { id: string; text: string };
8+
type StoredEvent = { version: 1; rawEvent: string };
9+
10+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
11+
12+
afterEach(() => {
13+
closeOpenClawStateDatabaseForTest();
14+
vi.restoreAllMocks();
15+
});
16+
17+
describe("channel ingress monitor admission", () => {
18+
it("reports whether each durable admission inserted a new row", async () => {
19+
const queue = createChannelIngressQueue<StoredEvent>({
20+
channelId: "test",
21+
accountId: "a",
22+
stateDir: tempDirs.make("openclaw-ingress-monitor-admission-"),
23+
});
24+
const admissions: boolean[] = [];
25+
const monitor = createChannelIngressMonitor<RawEvent, string, StoredEvent>({
26+
queue,
27+
inspect: (raw) => ({ eventId: raw.id, laneKey: "lane:a" }),
28+
payload: {
29+
storage: "raw-event",
30+
version: 1,
31+
serialize: (raw) => JSON.stringify(raw),
32+
deserialize: (body) => JSON.parse(body) as RawEvent,
33+
createClaimError: (kind) => new Error(kind),
34+
},
35+
deliver: vi.fn(),
36+
pollIntervalMs: 10,
37+
retention: { pruneIntervalMs: 60_000 },
38+
onDurableAdmission: (_raw, { isNew }) => {
39+
admissions.push(isNew);
40+
},
41+
});
42+
43+
try {
44+
await monitor.admit({ id: "event-one", text: "hello" });
45+
await monitor.admit({ id: "event-one", text: "hello" });
46+
expect(admissions).toEqual([true, false]);
47+
} finally {
48+
await monitor.stop();
49+
}
50+
});
51+
});

‎src/channels/message/ingress-monitor.test.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
createChannelIngressMonitor,
1717
type ChannelIngressMonitorDeliveryResult,
1818
type ChannelIngressMonitorLifecycle,
19-
type CreateChannelIngressMonitorOptions,
2019
} from "./ingress-monitor.js";
2120
import { createChannelIngressQueue, type ChannelIngressQueue } from "./ingress-queue.js";
2221
import type { IngressRetryPolicyConfig } from "./ingress-retry-policy.js";
@@ -73,12 +72,6 @@ function createMonitor(
7372
retryPolicy?: IngressRetryPolicyConfig;
7473
deferredLaneOccupancy?: "hold" | "release";
7574
runPumpTask?: (work: () => Promise<void>) => Promise<void>;
76-
onDurableAdmission?: CreateChannelIngressMonitorOptions<
77-
RawEvent,
78-
string,
79-
StoredEvent,
80-
unknown
81-
>["onDurableAdmission"];
8275
},
8376
onError?: (error: unknown) => void,
8477
abortSignal?: AbortSignal,
@@ -206,23 +199,6 @@ describe("channel ingress monitor", () => {
206199
});
207200
});
208201

209-
it("reports whether each durable admission inserted a new row", async () => {
210-
await withQueue(async (queue) => {
211-
const admissions: boolean[] = [];
212-
const monitor = createMonitor(queue, vi.fn(), {
213-
onDurableAdmission: (_raw, { isNew }) => {
214-
admissions.push(isNew);
215-
},
216-
});
217-
218-
await monitor.admit({ id: "event-one", lane: "a", text: "hello" });
219-
await monitor.admit({ id: "event-one", lane: "a", text: "hello" });
220-
221-
expect(admissions).toEqual([true, false]);
222-
await monitor.stop();
223-
});
224-
});
225-
226202
it("skips ignored events and prunes once before one admission enqueue", async () => {
227203
await withQueue(async (queue) => {
228204
const prune = vi.spyOn(queue, "prune");

0 commit comments

Comments
 (0)