const defaultSpawnResult = (overrides) => ({
    exitCode: 0,
    durationMs: 0,
    stdout: "",
    stderr: "",
    ...overrides
});
const defaultAutonomousResult = (overrides) => ({
    summary: "",
    log: "",
    output: "",
    stdout: "",
    text: "",
    toolCalls: [],
    sessionResult: {
        toolCalls: []
    },
    ...overrides
});
function getMockFactory() {
    const vitest = globalThis.vi;
    if (vitest === undefined) {
        throw new Error("createSpawnMock() requires Vitest globals. Run this helper inside a Vitest test.");
    }
    return vitest;
}
export function createSpawnMock(options = {}) {
    let mocks;
    const ensureMocks = () => {
        if (mocks) {
            return mocks;
        }
        const { fn } = getMockFactory();
        const autonomous = fn(async () => defaultAutonomousResult(options.autonomousResult));
        const spawn = Object.assign(fn(async () => defaultSpawnResult(options.spawnResult)), { autonomous });
        mocks = {
            spawn,
            autonomous
        };
        return mocks;
    };
    return {
        factory() {
            return {
                spawn: ensureMocks().spawn
            };
        },
        get spawn() {
            return ensureMocks().spawn;
        },
        get autonomous() {
            return ensureMocks().autonomous;
        }
    };
}
