// Task 168 — shared test helper for per-tool emit assertions.
//
// Spies global fetch, sets PLATFORM_PORT so withWriteEvent reaches the
// loopback URL (instead of stderr-fallback), and exposes the captured
// POST bodies. Each test pairs this with whatever per-tool deps it must
// mock so the wrapped body either resolves or throws.
import { vi } from "vitest";
export function setupEmitCapture(port = "12345") {
    process.env.PLATFORM_PORT = port;
    const originalFetch = globalThis.fetch;
    const fetchSpy = vi.fn().mockResolvedValue(new Response('{"ok":true}', { status: 200 }));
    globalThis.fetch = fetchSpy;
    return {
        fetchSpy,
        captures: () => fetchSpy.mock.calls.map((call) => {
            const init = call[1];
            return JSON.parse(init.body);
        }),
        restore: () => {
            globalThis.fetch = originalFetch;
            delete process.env.PLATFORM_PORT;
        },
    };
}
/**
 * Build a Neo4j Session stub whose `.run()` returns records constructed from
 * row objects. Each call to `.run()` consumes the next entry from rowSequence.
 * A row is a plain object — its keys are accessed by `record.get(key)`.
 */
export function makeMockSession(rowSequence = []) {
    let i = 0;
    return {
        run: vi.fn().mockImplementation(async () => {
            const rows = rowSequence[i++] ?? [];
            return {
                records: rows.map((row) => ({
                    get: (key) => row[key],
                })),
            };
        }),
        close: vi.fn().mockResolvedValue(undefined),
    };
}
//# sourceMappingURL=emit-capture.js.map