test(plugin-sdk): mirror after-record lifecycle

This commit is contained in:
Vincent Koc
2026-06-16 16:28:34 +08:00
parent f943c12aab
commit 55718a24fd
2 changed files with 15 additions and 4 deletions

View File

@@ -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({

View File

@@ -190,6 +190,7 @@ export function createPluginRuntimeMock(overrides: DeepPartial<PluginRuntime> =
onRecordError: record?.onRecordError ?? (() => undefined),
trackSessionMetaTask: record?.trackSessionMetaTask,
});
await (params.afterRecord as (() => void | Promise<void>) | undefined)?.();
const dispatchResult = await dispatchReplyWithBufferedBlockDispatcher({
ctx: ctxPayload,
cfg: params.cfg,
@@ -224,6 +225,7 @@ export function createPluginRuntimeMock(overrides: DeepPartial<PluginRuntime> =
onRecordError: params.record?.onRecordError ?? (() => undefined),
trackSessionMetaTask: params.record?.trackSessionMetaTask,
});
await params.afterRecord?.();
} catch (err) {
try {
await params.onPreDispatchFailure?.(err);