mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-18 18:31:43 +00:00
test(plugin-sdk): mirror after-record lifecycle
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user