mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 06:47:26 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
18
test/helpers/dispatch-inbound-capture.ts
Normal file
18
test/helpers/dispatch-inbound-capture.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function buildDispatchInboundCaptureMock<T extends Record<string, unknown>>(
|
||||
actual: T,
|
||||
setCtx: (ctx: unknown) => void,
|
||||
) {
|
||||
const dispatchInboundMessage = vi.fn(async (params: { ctx: unknown }) => {
|
||||
setCtx(params.ctx);
|
||||
return { queuedFinal: false, counts: { tool: 0, block: 0, final: 0 } };
|
||||
});
|
||||
|
||||
return {
|
||||
...actual,
|
||||
dispatchInboundMessage,
|
||||
dispatchInboundMessageWithDispatcher: dispatchInboundMessage,
|
||||
dispatchInboundMessageWithBufferedDispatcher: dispatchInboundMessage,
|
||||
};
|
||||
}
|
||||
23
test/helpers/mock-incoming-request.ts
Normal file
23
test/helpers/mock-incoming-request.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { IncomingMessage } from "node:http";
|
||||
import { EventEmitter } from "node:events";
|
||||
|
||||
export function createMockIncomingRequest(chunks: string[]): IncomingMessage {
|
||||
const req = new EventEmitter() as IncomingMessage & { destroyed?: boolean; destroy: () => void };
|
||||
req.destroyed = false;
|
||||
req.headers = {};
|
||||
req.destroy = () => {
|
||||
req.destroyed = true;
|
||||
};
|
||||
|
||||
void Promise.resolve().then(() => {
|
||||
for (const chunk of chunks) {
|
||||
req.emit("data", Buffer.from(chunk, "utf-8"));
|
||||
if (req.destroyed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
req.emit("end");
|
||||
});
|
||||
|
||||
return req;
|
||||
}
|
||||
Reference in New Issue
Block a user