diff --git a/src/plugin-sdk/test-helpers/plugin-runtime-mock.test.ts b/src/plugin-sdk/test-helpers/plugin-runtime-mock.test.ts index 3d5c300f9f2f..cac189e5593a 100644 --- a/src/plugin-sdk/test-helpers/plugin-runtime-mock.test.ts +++ b/src/plugin-sdk/test-helpers/plugin-runtime-mock.test.ts @@ -27,10 +27,17 @@ describe("createPluginRuntimeMock", () => { id: raw.id, rawText: "hello", })); - const recordInboundSession = vi.fn(); - const runDispatch = vi.fn(async () => ({ - visibleReplySent: true, - })); + const events: string[] = []; + const recordInboundSession = vi.fn(() => { + events.push("record"); + }); + const afterRecord = vi.fn(() => { + events.push("afterRecord"); + }); + const runDispatch = vi.fn(async () => { + events.push("dispatch"); + return { visibleReplySent: true }; + }); const resolveTurn = vi.fn(async () => ({ channel, storePath: "/tmp/openclaw-test", @@ -41,6 +48,7 @@ describe("createPluginRuntimeMock", () => { SessionKey: "agent:main:test:direct:u1", }, recordInboundSession, + afterRecord, runDispatch, })); @@ -65,6 +73,7 @@ describe("createPluginRuntimeMock", () => { sessionKey: "agent:main:test:direct:u1", }), ); + expect(events).toEqual(["record", "afterRecord", "dispatch"]); expect(runDispatch).toHaveBeenCalled(); expect(result).toEqual( expect.objectContaining({ diff --git a/src/plugin-sdk/test-helpers/plugin-runtime-mock.ts b/src/plugin-sdk/test-helpers/plugin-runtime-mock.ts index 717b5c5436ac..449e9ed5822a 100644 --- a/src/plugin-sdk/test-helpers/plugin-runtime-mock.ts +++ b/src/plugin-sdk/test-helpers/plugin-runtime-mock.ts @@ -190,6 +190,7 @@ export function createPluginRuntimeMock(overrides: DeepPartial = onRecordError: record?.onRecordError ?? (() => undefined), trackSessionMetaTask: record?.trackSessionMetaTask, }); + await (params.afterRecord as (() => void | Promise) | undefined)?.(); const dispatchResult = await dispatchReplyWithBufferedBlockDispatcher({ ctx: ctxPayload, cfg: params.cfg, @@ -224,6 +225,7 @@ export function createPluginRuntimeMock(overrides: DeepPartial = onRecordError: params.record?.onRecordError ?? (() => undefined), trackSessionMetaTask: params.record?.trackSessionMetaTask, }); + await params.afterRecord?.(); } catch (err) { try { await params.onPreDispatchFailure?.(err);