refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View 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,
};
}

View 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;
}