"use strict";
/**
 * Cross-Memory Socket Bridge (Phase 6) — bidirectional editor ↔ daemon test
 *
 * Tests the TCP bridge that lets editors (Cursor, VSCode) push events to
 * Fivo Cell, stores them in the shared DB, and broadcasts them to other
 * connected clients.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const net = __importStar(require("net"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'cell-bridge-test-'));
const originalHome = process.env.USERPROFILE;
process.env.USERPROFILE = tempHome;
process.env.HOME = tempHome;
process.env.FIVO_CELL_HOME = tempHome;
const database_1 = require("../walls/06-memory/database/database");
const socket_bridge_1 = require("../walls/07-runtime/watcher/socket-bridge");
const event_capture_1 = require("../walls/01-context/sessions/event-capture");
let TEST_PORT = 19877;
function connect(port) {
    return new Promise((resolve, reject) => {
        const sock = net.createConnection({ port, host: '127.0.0.1' }, () => {
            resolve(sock);
        });
        sock.on('error', reject);
    });
}
function sendMessage(sock, msg) {
    return new Promise((resolve) => {
        const onData = (chunk) => {
            const text = chunk.toString('utf8');
            const lines = text.split('\n').filter(l => l.trim().length > 0);
            for (const line of lines) {
                try {
                    const parsed = JSON.parse(line);
                    sock.off('data', onData);
                    resolve(parsed);
                    return;
                }
                catch { /* keep reading */ }
            }
        };
        sock.on('data', onData);
        sock.write(JSON.stringify(msg) + '\n');
    });
}
function readMessages(sock, count, timeoutMs = 1000) {
    return new Promise((resolve) => {
        const collected = [];
        const timer = setTimeout(() => {
            sock.off('data', onData);
            resolve(collected);
        }, timeoutMs);
        const onData = (chunk) => {
            const text = chunk.toString('utf8');
            const lines = text.split('\n').filter(l => l.trim().length > 0);
            for (const line of lines) {
                try {
                    collected.push(JSON.parse(line));
                }
                catch { /* skip */ }
            }
            if (collected.length >= count) {
                clearTimeout(timer);
                sock.off('data', onData);
                resolve(collected);
            }
        };
        sock.on('data', onData);
    });
}
describe('Cross-Memory Socket Bridge (Phase 6)', () => {
    beforeEach(async () => {
        try {
            (0, socket_bridge_1.stopBridge)();
        }
        catch { /* ignore */ }
        try {
            (0, database_1.closeDb)();
        }
        catch { /* ignore */ }
        (0, database_1.initializeDatabase)();
        TEST_PORT = 19877 + Math.floor(Math.random() * 1000);
        await new Promise(r => setTimeout(r, 100));
        const db = (0, database_1.getDb)();
        const tables = ['live_events', 'sessions', 'session_approaches', 'session_files',
            'session_questions', 'decisions'];
        for (const t of tables) {
            try {
                db.exec(`DELETE FROM ${t}`);
            }
            catch { /* ignore */ }
        }
    });
    afterAll(() => {
        try {
            (0, socket_bridge_1.stopBridge)();
        }
        catch { /* ignore */ }
        try {
            (0, database_1.closeDb)();
        }
        catch { /* ignore */ }
        process.env.USERPROFILE = originalHome;
        process.env.HOME = originalHome;
        try {
            fs.rmSync(tempHome, { recursive: true, force: true });
        }
        catch { /* ignore */ }
    });
    afterEach(() => {
        try {
            (0, socket_bridge_1.stopBridge)();
        }
        catch { /* ignore */ }
    });
    it('is not running initially', () => {
        expect((0, socket_bridge_1.isBridgeRunning)()).toBe(false);
        const info = (0, socket_bridge_1.getBridgeInfo)();
        expect(info.running).toBe(false);
        expect(info.clientCount).toBe(0);
    });
    it('starts and stops cleanly', async () => {
        const info = await (0, socket_bridge_1.startBridge)(TEST_PORT);
        expect(info.running).toBe(true);
        expect(info.port).toBe(TEST_PORT);
        expect(info.host).toBe('127.0.0.1');
        expect((0, socket_bridge_1.isBridgeRunning)()).toBe(true);
        expect((0, socket_bridge_1.stopBridge)()).toBe(true);
        expect((0, socket_bridge_1.isBridgeRunning)()).toBe(false);
    });
    it('detects port in use', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const inUse = await (0, socket_bridge_1.isPortInUse)(TEST_PORT);
        expect(inUse).toBe(true);
        (0, socket_bridge_1.stopBridge)();
        const notInUse = await (0, socket_bridge_1.isPortInUse)(TEST_PORT);
        expect(notInUse).toBe(false);
    });
    it('rejects when port is already in use', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        await expect((0, socket_bridge_1.startBridge)(TEST_PORT)).rejects.toThrow(/already running/);
    });
    it('accepts a client connection', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = connect(TEST_PORT);
        const client = await sock;
        expect(client).toBeDefined();
        client.destroy();
    });
    it('responds to ping with pong', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, { type: 'ping' });
        expect(reply.type).toBe('pong');
        expect(typeof reply.uptimeSeconds).toBe('number');
        sock.destroy();
    });
    it('stores a file_save event from a client', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'file_save', filePath: 'src/api.ts' },
        });
        expect(reply.type).toBe('ack');
        expect(reply.id).toBeGreaterThan(0);
        sock.destroy();
        await new Promise(r => setTimeout(r, 50));
        const events = (0, event_capture_1.getTimeline)({ project: 'demo' });
        expect(events.length).toBe(1);
        expect(events[0].eventType).toBe('file_save');
        expect(events[0].filePath).toBe('src/api.ts');
    });
    it('stores cursor_move with line+column', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'cursor_move', filePath: 'src/x.ts', line: 42, column: 7 },
        });
        sock.destroy();
        await new Promise(r => setTimeout(r, 50));
        const events = (0, event_capture_1.getTimeline)({ project: 'demo' });
        expect(events.length).toBe(1);
        expect(events[0].eventType).toBe('cursor_move');
        expect(events[0].line).toBe(42);
    });
    it('stores terminal_command with cwd', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'terminal_command', command: 'npm test', metadata: { cwd: '/home/user/proj' } },
        });
        sock.destroy();
        await new Promise(r => setTimeout(r, 50));
        const events = (0, event_capture_1.getTimeline)({ project: 'demo' });
        expect(events[0].eventType).toBe('terminal_command');
        expect(events[0].command).toBe('npm test');
    });
    it('stores AI prompt and response', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'ai_prompt', toolName: 'claude-code', taskType: 'code' },
        });
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'ai_response', toolName: 'claude-code', durationMs: 1234, success: true },
        });
        sock.destroy();
        await new Promise(r => setTimeout(r, 50));
        const counts = (0, event_capture_1.getEventCounts)('demo');
        expect(counts.ai_prompt).toBe(1);
        expect(counts.ai_response).toBe(1);
    });
    it('stores test_pass and test_fail', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'test_pass', filePath: 'a.test.ts', testName: 'works' },
        });
        await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'test_fail', filePath: 'b.test.ts', testName: 'breaks', errorMessage: 'oops' },
        });
        sock.destroy();
        await new Promise(r => setTimeout(r, 50));
        const counts = (0, event_capture_1.getEventCounts)('demo');
        expect(counts.test_pass).toBe(1);
        expect(counts.test_fail).toBe(1);
    });
    it('returns error for missing project field', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'event',
            project: '',
            event: { eventType: 'file_save', filePath: 'a.ts' },
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('returns error for missing eventType', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'event',
            project: 'demo',
            event: {},
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('returns error for invalid JSON', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const promise = new Promise((resolve) => {
            sock.once('data', (chunk) => {
                const text = chunk.toString('utf8');
                const line = text.split('\n')[0];
                resolve(JSON.parse(line));
            });
        });
        sock.write('not json\n');
        const reply = await promise;
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('returns error for unknown message type', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, { type: 'unknown_type' });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('broadcasts events to other connected clients', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sockA = await connect(TEST_PORT);
        const sockB = await connect(TEST_PORT);
        // wait for ack on B's connection
        const bMessagesPromise = readMessages(sockB, 1, 2000);
        await sendMessage(sockA, {
            type: 'event',
            project: 'demo',
            event: { eventType: 'file_save', filePath: 'shared.ts' },
        });
        const bMessages = await bMessagesPromise;
        expect(bMessages.length).toBeGreaterThanOrEqual(1);
        const broadcast = bMessages.find(m => m.type === 'event');
        expect(broadcast).toBeDefined();
        sockA.destroy();
        sockB.destroy();
    });
    it('tracks multiple clients in info', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock1 = await connect(TEST_PORT);
        const sock2 = await connect(TEST_PORT);
        const sock3 = await connect(TEST_PORT);
        await new Promise(r => setTimeout(r, 200));
        const info = (0, socket_bridge_1.getBridgeInfo)();
        expect(info.clientCount).toBeGreaterThanOrEqual(2);
        expect(info.clientCount).toBeLessThanOrEqual(3);
        sock1.destroy();
        sock2.destroy();
        sock3.destroy();
    });
    it('stops the bridge and clears all clients', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock1 = await connect(TEST_PORT);
        const sock2 = await connect(TEST_PORT);
        await new Promise(r => setTimeout(r, 200));
        expect((0, socket_bridge_1.getBridgeInfo)().clientCount).toBeGreaterThanOrEqual(2);
        // Stop the bridge — this should disconnect all clients
        const ok = (0, socket_bridge_1.stopBridge)();
        expect(ok).toBe(true);
        expect((0, socket_bridge_1.isBridgeRunning)()).toBe(false);
        expect((0, socket_bridge_1.getBridgeInfo)().clientCount).toBe(0);
        expect((0, socket_bridge_1.getBridgeInfo)().running).toBe(false);
        sock1.destroy();
        sock2.destroy();
    });
    it('counts events received in client info', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, { type: 'event', project: 'p', event: { eventType: 'file_save', filePath: '1.ts' } });
        await sendMessage(sock, { type: 'event', project: 'p', event: { eventType: 'file_save', filePath: '2.ts' } });
        await sendMessage(sock, { type: 'event', project: 'p', event: { eventType: 'file_save', filePath: '3.ts' } });
        const info = (0, socket_bridge_1.getBridgeInfo)();
        expect(info.totalEventsReceived).toBe(3);
        expect(info.clients[0].eventsReceived).toBe(3);
        sock.destroy();
    });
    it('killStaleBridge returns false when no pid file', () => {
        const result = (0, socket_bridge_1.killStaleBridge)();
        expect(typeof result).toBe('boolean');
    });
    // ─── Editor Presence (Feature #2) ───────────────────────────────────────
    it('stores editor_state from a client', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'editor_state',
            state: {
                editorName: 'vscode',
                filePath: 'src/auth.ts',
                line: 42,
                column: 7,
                isDirty: true,
                project: 'demo',
                language: 'typescript',
            },
        });
        expect(reply.type).toBe('ack');
        await new Promise(r => setTimeout(r, 50));
        const states = (0, socket_bridge_1.getEditorStates)('demo');
        expect(states.length).toBe(1);
        expect(states[0].editorName).toBe('vscode');
        expect(states[0].filePath).toBe('src/auth.ts');
        expect(states[0].line).toBe(42);
        expect(states[0].column).toBe(7);
        expect(states[0].isDirty).toBe(true);
        expect(states[0].project).toBe('demo');
        sock.destroy();
    });
    it('stores unsaved buffer in editor_state', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'editor_state',
            state: {
                editorName: 'cursor',
                filePath: 'src/api.ts',
                line: 1,
                column: 1,
                isDirty: true,
                unsavedBuffer: 'function login() { /* unsaved */ }',
                unsavedLength: 33,
                project: 'demo',
            },
        });
        await new Promise(r => setTimeout(r, 50));
        const state = (0, socket_bridge_1.getEditorState)('demo');
        expect(state).not.toBeNull();
        expect(state.unsavedBuffer).toBe('function login() { /* unsaved */ }');
        expect(state.unsavedLength).toBe(33);
        sock.destroy();
    });
    it('rejects editor_state without editorName', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'editor_state',
            state: { filePath: 'a.ts', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('rejects editor_state without filePath', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('rejects editor_state without project', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 1, column: 1, isDirty: false },
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('rejects editor_state with non-numeric line/column', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: '1', column: 1, isDirty: false, project: 'demo' },
        });
        expect(reply.type).toBe('error');
        sock.destroy();
    });
    it('returns current editor state via editor_state_query', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sockA = await connect(TEST_PORT);
        const sockB = await connect(TEST_PORT);
        await sendMessage(sockA, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 10, column: 5, isDirty: false, project: 'p1' },
        });
        await sendMessage(sockB, {
            type: 'editor_state',
            state: { editorName: 'cursor', filePath: 'b.ts', line: 20, column: 8, isDirty: true, project: 'p1' },
        });
        const reply = await sendMessage(sockB, { type: 'editor_state_query', project: 'p1' });
        expect(reply.type).toBe('editor_state_response');
        const states = reply.states;
        expect(states.length).toBe(2);
        const editors = states.map((s) => s.editorName).sort();
        expect(editors).toEqual(['cursor', 'vscode']);
        sockA.destroy();
        sockB.destroy();
    });
    it('returns empty array for project with no editors', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const reply = await sendMessage(sock, { type: 'editor_state_query', project: 'no-such-project' });
        expect(reply.type).toBe('editor_state_response');
        expect(reply.states).toEqual([]);
        sock.destroy();
    });
    it('updates existing editor state on repeat push', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 20));
        await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 50, column: 0, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 50));
        const states = (0, socket_bridge_1.getEditorStates)('demo');
        expect(states.length).toBe(1);
        expect(states[0].line).toBe(50);
        sock.destroy();
    });
    it('keeps editor state after client disconnect (presence sticks)', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 50));
        expect((0, socket_bridge_1.getEditorStates)('demo').length).toBe(1);
        sock.destroy();
        // Wait for server-side close to process
        await new Promise(r => setTimeout(r, 200));
        // State should STILL be present (it's presence, not connection)
        expect((0, socket_bridge_1.getEditorStates)('demo').length).toBe(1);
    });
    it('getEditorState returns the most recent state', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sockA = await connect(TEST_PORT);
        const sockB = await connect(TEST_PORT);
        await sendMessage(sockA, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 5, column: 0, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 30));
        await sendMessage(sockB, {
            type: 'editor_state',
            state: { editorName: 'cursor', filePath: 'b.ts', line: 99, column: 0, isDirty: false, project: 'demo' },
        });
        const state = (0, socket_bridge_1.getEditorState)('demo');
        expect(state).not.toBeNull();
        expect(state.line).toBe(99);
        expect(state.editorName).toBe('cursor');
        sockA.destroy();
        sockB.destroy();
    });
    it('info includes editor states', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 50));
        const info = (0, socket_bridge_1.getBridgeInfo)();
        expect(info.editorStates.length).toBe(1);
        expect(info.editorStates[0].editorName).toBe('vscode');
        sock.destroy();
    });
    it('stopBridge clears editor states', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        await sendMessage(sock, {
            type: 'editor_state',
            state: { editorName: 'vscode', filePath: 'a.ts', line: 1, column: 1, isDirty: false, project: 'demo' },
        });
        await new Promise(r => setTimeout(r, 50));
        expect((0, socket_bridge_1.getEditorStates)('demo').length).toBe(1);
        (0, socket_bridge_1.stopBridge)();
        expect((0, socket_bridge_1.getEditorStates)('demo').length).toBe(0);
        sock.destroy();
    });
    it('stores many event types end-to-end', async () => {
        await (0, socket_bridge_1.startBridge)(TEST_PORT);
        const sock = await connect(TEST_PORT);
        const types = [
            { eventType: 'file_save', filePath: 'a.ts' },
            { eventType: 'file_create', filePath: 'b.ts' },
            { eventType: 'file_delete', filePath: 'c.ts' },
            { eventType: 'file_focus', filePath: 'd.ts' },
            { eventType: 'file_blur', filePath: 'e.ts' },
            { eventType: 'cursor_move', filePath: 'f.ts', line: 1, column: 1 },
            { eventType: 'terminal_command', command: 'ls', metadata: { cwd: '/x' } },
            { eventType: 'terminal_command_done', command: 'ls', metadata: { cwd: '/x' } },
            { eventType: 'test_run' },
            { eventType: 'test_pass', filePath: 'a.test.ts', testName: 't' },
            { eventType: 'test_fail', filePath: 'b.test.ts', testName: 't', errorMessage: 'e' },
            { eventType: 'error', errorMessage: 'big error' },
            { eventType: 'build_start' },
            { eventType: 'build_end', durationMs: 100, success: true },
            { eventType: 'git_commit', commitHash: 'abc123', message: 'fix bug' },
            { eventType: 'ai_prompt', toolName: 'cursor' },
            { eventType: 'ai_response', toolName: 'cursor', durationMs: 500 },
            { eventType: 'session_start', toolName: 'cursor' },
            { eventType: 'session_end', toolName: 'cursor' },
        ];
        for (const ev of types) {
            await sendMessage(sock, { type: 'event', project: 'e2e', event: ev });
        }
        sock.destroy();
        await new Promise(r => setTimeout(r, 100));
        const counts = (0, event_capture_1.getEventCounts)('e2e');
        expect(counts.file_save).toBe(1);
        expect(counts.file_create).toBe(1);
        expect(counts.file_delete).toBe(1);
        expect(counts.file_focus).toBe(1);
        expect(counts.cursor_move).toBe(1);
        expect(counts.terminal_command).toBe(1);
        expect(counts.terminal_command_done).toBe(1);
        expect(counts.test_run).toBe(1);
        expect(counts.test_pass).toBe(1);
        expect(counts.test_fail).toBe(1);
        expect(counts.error).toBe(1);
        expect(counts.build_start).toBe(1);
        expect(counts.build_end).toBe(1);
        expect(counts.git_commit).toBe(1);
        expect(counts.ai_prompt).toBe(1);
        expect(counts.ai_response).toBe(1);
        expect(counts.session_start).toBe(1);
        expect(counts.session_end).toBe(1);
    });
});
//# sourceMappingURL=cross-memory-socket-bridge.test.js.map