mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 18:44:31 +00:00
test(signal): dedupe monitor tool-result test payload fixtures
This commit is contained in:
@@ -111,6 +111,52 @@ function getDirectSignalEventsFor(sender: string) {
|
|||||||
return peekSystemEvents(route.sessionKey);
|
return peekSystemEvents(route.sessionKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeBaseEnvelope(overrides: Record<string, unknown> = {}) {
|
||||||
|
return {
|
||||||
|
sourceNumber: "+15550001111",
|
||||||
|
sourceName: "Ada",
|
||||||
|
timestamp: 1,
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function receiveSingleEnvelope(
|
||||||
|
envelope: Record<string, unknown>,
|
||||||
|
opts?: Partial<Parameters<(typeof import("./monitor.js"))["monitorSignalProvider"]>[0]>,
|
||||||
|
) {
|
||||||
|
await receiveSignalPayloads({
|
||||||
|
payloads: [{ envelope }],
|
||||||
|
opts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectNoReplyDeliveryOrRouteUpdate() {
|
||||||
|
expect(replyMock).not.toHaveBeenCalled();
|
||||||
|
expect(sendMock).not.toHaveBeenCalled();
|
||||||
|
expect(updateLastRouteMock).not.toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setReactionNotificationConfig(mode: "all" | "own", extra: Record<string, unknown> = {}) {
|
||||||
|
setSignalToolResultTestConfig(
|
||||||
|
createSignalConfig({
|
||||||
|
autoStart: false,
|
||||||
|
dmPolicy: "open",
|
||||||
|
allowFrom: ["*"],
|
||||||
|
reactionNotifications: mode,
|
||||||
|
...extra,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectWaitForTransportReadyTimeout(timeoutMs: number) {
|
||||||
|
expect(waitForTransportReadyMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(waitForTransportReadyMock).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
timeoutMs,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
describe("monitorSignalProvider tool results", () => {
|
describe("monitorSignalProvider tool results", () => {
|
||||||
it("uses bounded readiness checks when auto-starting the daemon", async () => {
|
it("uses bounded readiness checks when auto-starting the daemon", async () => {
|
||||||
const runtime = createMonitorRuntime();
|
const runtime = createMonitorRuntime();
|
||||||
@@ -150,12 +196,7 @@ describe("monitorSignalProvider tool results", () => {
|
|||||||
startupTimeoutMs: 90_000,
|
startupTimeoutMs: 90_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(waitForTransportReadyMock).toHaveBeenCalledTimes(1);
|
expectWaitForTransportReadyTimeout(90_000);
|
||||||
expect(waitForTransportReadyMock).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
timeoutMs: 90_000,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caps startupTimeoutMs at 2 minutes", async () => {
|
it("caps startupTimeoutMs at 2 minutes", async () => {
|
||||||
@@ -170,12 +211,7 @@ describe("monitorSignalProvider tool results", () => {
|
|||||||
runtime,
|
runtime,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(waitForTransportReadyMock).toHaveBeenCalledTimes(1);
|
expectWaitForTransportReadyTimeout(120_000);
|
||||||
expect(waitForTransportReadyMock).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
timeoutMs: 120_000,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips tool summaries with responsePrefix", async () => {
|
it("skips tool summaries with responsePrefix", async () => {
|
||||||
@@ -227,78 +263,43 @@ describe("monitorSignalProvider tool results", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ignores reaction-only messages", async () => {
|
it("ignores reaction-only messages", async () => {
|
||||||
await receiveSignalPayloads({
|
await receiveSingleEnvelope({
|
||||||
payloads: [
|
...makeBaseEnvelope(),
|
||||||
{
|
reactionMessage: {
|
||||||
envelope: {
|
emoji: "👍",
|
||||||
sourceNumber: "+15550001111",
|
targetAuthor: "+15550002222",
|
||||||
sourceName: "Ada",
|
targetSentTimestamp: 2,
|
||||||
timestamp: 1,
|
},
|
||||||
reactionMessage: {
|
|
||||||
emoji: "👍",
|
|
||||||
targetAuthor: "+15550002222",
|
|
||||||
targetSentTimestamp: 2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replyMock).not.toHaveBeenCalled();
|
expectNoReplyDeliveryOrRouteUpdate();
|
||||||
expect(sendMock).not.toHaveBeenCalled();
|
|
||||||
expect(updateLastRouteMock).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ignores reaction-only dataMessage.reaction events (don’t treat as broken attachments)", async () => {
|
it("ignores reaction-only dataMessage.reaction events (don’t treat as broken attachments)", async () => {
|
||||||
await receiveSignalPayloads({
|
await receiveSingleEnvelope({
|
||||||
payloads: [
|
...makeBaseEnvelope(),
|
||||||
{
|
dataMessage: {
|
||||||
envelope: {
|
reaction: {
|
||||||
sourceNumber: "+15550001111",
|
emoji: "👍",
|
||||||
sourceName: "Ada",
|
targetAuthor: "+15550002222",
|
||||||
timestamp: 1,
|
targetSentTimestamp: 2,
|
||||||
dataMessage: {
|
|
||||||
reaction: {
|
|
||||||
emoji: "👍",
|
|
||||||
targetAuthor: "+15550002222",
|
|
||||||
targetSentTimestamp: 2,
|
|
||||||
},
|
|
||||||
attachments: [{}],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
attachments: [{}],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(replyMock).not.toHaveBeenCalled();
|
expectNoReplyDeliveryOrRouteUpdate();
|
||||||
expect(sendMock).not.toHaveBeenCalled();
|
|
||||||
expect(updateLastRouteMock).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("enqueues system events for reaction notifications", async () => {
|
it("enqueues system events for reaction notifications", async () => {
|
||||||
setSignalToolResultTestConfig(
|
setReactionNotificationConfig("all");
|
||||||
createSignalConfig({
|
await receiveSingleEnvelope({
|
||||||
autoStart: false,
|
...makeBaseEnvelope(),
|
||||||
dmPolicy: "open",
|
reactionMessage: {
|
||||||
allowFrom: ["*"],
|
emoji: "✅",
|
||||||
reactionNotifications: "all",
|
targetAuthor: "+15550002222",
|
||||||
}),
|
targetSentTimestamp: 2,
|
||||||
);
|
},
|
||||||
await receiveSignalPayloads({
|
|
||||||
payloads: [
|
|
||||||
{
|
|
||||||
envelope: {
|
|
||||||
sourceNumber: "+15550001111",
|
|
||||||
sourceName: "Ada",
|
|
||||||
timestamp: 1,
|
|
||||||
reactionMessage: {
|
|
||||||
emoji: "✅",
|
|
||||||
targetAuthor: "+15550002222",
|
|
||||||
targetSentTimestamp: 2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const events = getDirectSignalEventsFor("+15550001111");
|
const events = getDirectSignalEventsFor("+15550001111");
|
||||||
@@ -306,31 +307,15 @@ describe("monitorSignalProvider tool results", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("notifies on own reactions when target includes uuid + phone", async () => {
|
it("notifies on own reactions when target includes uuid + phone", async () => {
|
||||||
setSignalToolResultTestConfig(
|
setReactionNotificationConfig("own", { account: "+15550002222" });
|
||||||
createSignalConfig({
|
await receiveSingleEnvelope({
|
||||||
autoStart: false,
|
...makeBaseEnvelope(),
|
||||||
dmPolicy: "open",
|
reactionMessage: {
|
||||||
allowFrom: ["*"],
|
emoji: "✅",
|
||||||
account: "+15550002222",
|
targetAuthor: "+15550002222",
|
||||||
reactionNotifications: "own",
|
targetAuthorUuid: "123e4567-e89b-12d3-a456-426614174000",
|
||||||
}),
|
targetSentTimestamp: 2,
|
||||||
);
|
},
|
||||||
await receiveSignalPayloads({
|
|
||||||
payloads: [
|
|
||||||
{
|
|
||||||
envelope: {
|
|
||||||
sourceNumber: "+15550001111",
|
|
||||||
sourceName: "Ada",
|
|
||||||
timestamp: 1,
|
|
||||||
reactionMessage: {
|
|
||||||
emoji: "✅",
|
|
||||||
targetAuthor: "+15550002222",
|
|
||||||
targetAuthorUuid: "123e4567-e89b-12d3-a456-426614174000",
|
|
||||||
targetSentTimestamp: 2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const events = getDirectSignalEventsFor("+15550001111");
|
const events = getDirectSignalEventsFor("+15550001111");
|
||||||
|
|||||||
Reference in New Issue
Block a user