feat(M3): Direct Execution

This commit is contained in:
2026-05-18 18:11:45 -05:00
parent fe94629797
commit a2cfa7027e
2 changed files with 29 additions and 7 deletions
+16 -4
View File
@@ -4,6 +4,7 @@ import { EventEmitter } from "node:events";
import { Readable } from "node:stream";
import { executePrompt } from "../src/execute.js";
import { ClientNotFoundError, ExecError } from "../src/types.js";
import type { ClientName } from "../src/types.js";
interface MockScenario {
stdout?: string;
@@ -14,7 +15,7 @@ interface MockScenario {
}
function createMockChildProcess(scenario: MockScenario): any {
const child = new EventEmitter();
const child = new EventEmitter() as any;
child.stdout = Readable.from(
scenario.stdout !== undefined ? [scenario.stdout] : []
);
@@ -61,8 +62,8 @@ function createMockChildProcess(scenario: MockScenario): any {
function mockSpawn(
scenarios: Map<string, MockScenario>
): (cmd: string, args: string[], opts: any) => any {
return (cmd: string, args: string[], _opts: any) => {
): any {
return (cmd: string, args: string[], _opts: any): any => {
const key = [cmd, ...args].join(" ");
const scenario = scenarios.get(key);
if (!scenario) {
@@ -74,7 +75,7 @@ function mockSpawn(
};
}
function mockExistsSync(allowedPaths: Set<string>): (p: string) => boolean {
function mockExistsSync(allowedPaths: Set<string>): any {
return (p: string) => allowedPaths.has(p);
}
@@ -191,4 +192,15 @@ describe("executePrompt", () => {
err instanceof ExecError && err.message.includes("empty")
);
});
it("throws ExecError for invalid client at runtime", async () => {
await assert.rejects(
executePrompt("bogus" as unknown as ClientName, "hello", {
spawn: mockSpawn(new Map()),
existsSync: () => true,
}),
(err: unknown) =>
err instanceof ExecError && err.message.includes("Unknown client")
);
});
});