|
1 | 1 | // Imessage tests cover monitor.watch subscribe retry plugin behavior. |
| 2 | +import { redactIdentifier } from "openclaw/plugin-sdk/logging-core"; |
2 | 3 | import type { waitForTransportReady } from "openclaw/plugin-sdk/transport-ready-runtime"; |
3 | 4 | import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 5 | import type { createIMessageRpcClient, IMessageRpcClient } from "./client.js"; |
5 | 6 | import { monitorIMessageProvider } from "./monitor.js"; |
6 | 7 | import type { attachIMessageMonitorAbortHandler } from "./monitor/abort-handler.js"; |
| 8 | +import { rememberPersistedIMessageEcho } from "./monitor/persisted-echo-cache.js"; |
7 | 9 | import { |
8 | 10 | installIMessageFailingStateRuntimeForTest, |
9 | 11 | installIMessageStateRuntimeForTest, |
@@ -33,6 +35,7 @@ function createRuntime() { |
33 | 35 | return { |
34 | 36 | log: vi.fn(), |
35 | 37 | error: vi.fn(), |
| 38 | + exit: vi.fn(), |
36 | 39 | }; |
37 | 40 | } |
38 | 41 |
|
@@ -269,4 +272,60 @@ describe("monitorIMessageProvider watch.subscribe startup retry", () => { |
269 | 272 | expect(diagnostics[0]).not.toContain("private message text"); |
270 | 273 | expect(diagnostics[0]).not.toContain("+15550001111"); |
271 | 274 | }); |
| 275 | + |
| 276 | + it("redacts the conversation identifier in rate-limit suppression warnings", async () => { |
| 277 | + vi.useRealTimers(); |
| 278 | + installIMessageStateRuntimeForTest(); |
| 279 | + const runtime = createRuntime(); |
| 280 | + const sender = "+15550002222"; |
| 281 | + const chatId = 456; |
| 282 | + const scope = `default:chat_id:${chatId}`; |
| 283 | + rememberPersistedIMessageEcho({ scope, text: "loop echo" }); |
| 284 | + let onNotification: |
| 285 | + | ((message: { method: string; params: unknown }) => void | Promise<void>) |
| 286 | + | undefined; |
| 287 | + const notify = async (id: number, text: string) => { |
| 288 | + await onNotification?.({ |
| 289 | + method: "message", |
| 290 | + params: { |
| 291 | + message: { |
| 292 | + id, |
| 293 | + guid: `p:0/message-${id}`, |
| 294 | + chat_id: chatId, |
| 295 | + sender, |
| 296 | + is_from_me: false, |
| 297 | + is_group: true, |
| 298 | + text, |
| 299 | + created_at: new Date().toISOString(), |
| 300 | + }, |
| 301 | + }, |
| 302 | + }); |
| 303 | + }; |
| 304 | + const client = createRpcClient({ |
| 305 | + waitForClose: async () => { |
| 306 | + for (let id = 1; id <= 5; id += 1) { |
| 307 | + await notify(id, "loop echo"); |
| 308 | + } |
| 309 | + await notify(6, "legitimate inbound"); |
| 310 | + }, |
| 311 | + }); |
| 312 | + createIMessageRpcClientMock.mockImplementation(async (params) => { |
| 313 | + onNotification = params?.onNotification; |
| 314 | + return client; |
| 315 | + }); |
| 316 | + |
| 317 | + await monitorIMessageProvider({ |
| 318 | + config: { channels: { imessage: { groupPolicy: "open" } } }, |
| 319 | + runtime, |
| 320 | + }); |
| 321 | + |
| 322 | + await new Promise((resolve) => { |
| 323 | + setTimeout(resolve, 50); |
| 324 | + }); |
| 325 | + const logs = runtime.log.mock.calls.map(([message]) => String(message)); |
| 326 | + const warning = logs.find((message) => message.includes("rate limiter tripped")); |
| 327 | + expect(warning, `logs: ${JSON.stringify(logs)}`).toBeDefined(); |
| 328 | + expect(warning).toContain(`group:${redactIdentifier(`group:${chatId}`)}`); |
| 329 | + expect(warning).not.toContain(sender); |
| 330 | + }); |
272 | 331 | }); |
0 commit comments