"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const util_js_1 = require("./util.js");
const constructorSpy = vitest_1.vi.fn();
// isomorphic-ws resolves to the `ws` package on Node; capture its constructor args.
// vitest hoists this mock above the static import above, so `util.ts` picks it up.
vitest_1.vi.mock('isomorphic-ws', () => ({
    default: class MockWebSocket {
        constructor(url, protocol, options) {
            constructorSpy(url, protocol, options);
        }
        addEventListener() {
            // no-op; the connect promise stays pending, which is fine for these assertions
        }
    }
}));
(0, vitest_1.describe)('connectWebSocket User-Agent', () => {
    (0, vitest_1.beforeEach)(() => {
        vitest_1.vi.useFakeTimers();
        constructorSpy.mockClear();
    });
    (0, vitest_1.afterEach)(() => {
        vitest_1.vi.clearAllTimers();
        vitest_1.vi.useRealTimers();
    });
    (0, vitest_1.it)('sends a default User-Agent and preserves maxPayload on the handshake', () => {
        void (0, util_js_1.connectWebSocket)('wss://example.com/api/v1/rpc-ws');
        (0, vitest_1.expect)(constructorSpy).toHaveBeenCalledWith('wss://example.com/api/v1/rpc-ws', undefined, vitest_1.expect.objectContaining({
            maxPayload: util_js_1.MAX_SOCKET_PAYLOAD_BYTES,
            headers: vitest_1.expect.objectContaining({ 'User-Agent': util_js_1.DEFAULT_WEBSOCKET_USER_AGENT })
        }));
    });
    (0, vitest_1.it)('lets callers override the User-Agent via options.headers', () => {
        void (0, util_js_1.connectWebSocket)('wss://example.com/api/v1/rpc-ws', { headers: { 'User-Agent': 'superblocks-cli/9.9.9' } });
        (0, vitest_1.expect)(constructorSpy).toHaveBeenCalledWith('wss://example.com/api/v1/rpc-ws', undefined, vitest_1.expect.objectContaining({
            headers: vitest_1.expect.objectContaining({ 'User-Agent': 'superblocks-cli/9.9.9' })
        }));
    });
    (0, vitest_1.it)('forwards options.protocol as the WebSocket subprotocol', () => {
        void (0, util_js_1.connectWebSocket)('wss://example.com/api/v1/rpc-ws', { protocol: 'editor' });
        (0, vitest_1.expect)(constructorSpy).toHaveBeenCalledWith('wss://example.com/api/v1/rpc-ws', 'editor', vitest_1.expect.anything());
    });
});
(0, vitest_1.describe)('buildClientUserAgent', () => {
    (0, vitest_1.it)('joins component and version with a slash', () => {
        (0, vitest_1.expect)((0, util_js_1.buildClientUserAgent)('superblocks-cli', '2.0.0-next.1')).toBe('superblocks-cli/2.0.0-next.1');
    });
    (0, vitest_1.it)('returns the bare component when no version is given', () => {
        (0, vitest_1.expect)((0, util_js_1.buildClientUserAgent)('superblocks-dev-server')).toBe('superblocks-dev-server');
    });
});
//# sourceMappingURL=util.test.js.map