"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const v3_js_1 = require("../../lib/v3/v3.js");
const MOCK_SESSION_ID = "session-123";
const MOCK_SESSION_URL = `https://www.browserbase.com/sessions/${MOCK_SESSION_ID}`;
const MOCK_DEBUG_URL = `https://debug.browserbase.com/${MOCK_SESSION_ID}`;
vitest_1.vi.mock("../../lib/v3/understudy/context", () => {
    class MockConnection {
        onTransportClosed = vitest_1.vi.fn();
        offTransportClosed = vitest_1.vi.fn();
        send = vitest_1.vi.fn(async () => { });
    }
    class MockV3Context {
        static async create() {
            return new MockV3Context();
        }
        conn = new MockConnection();
        pages() {
            return [];
        }
        async close() {
            // noop
        }
    }
    return { V3Context: MockV3Context };
});
vitest_1.vi.mock("../../lib/v3/launch/browserbase", () => ({
    createBrowserbaseSession: vitest_1.vi.fn(async () => ({
        ws: "wss://mock-browserbase",
        sessionId: MOCK_SESSION_ID,
        bb: {
            sessions: {
                debug: vitest_1.vi.fn(async () => ({ debuggerUrl: MOCK_DEBUG_URL })),
            },
        },
    })),
}));
vitest_1.vi.mock("../../lib/v3/launch/local", () => ({
    launchLocalChrome: vitest_1.vi.fn(async () => ({
        ws: "ws://local-cdp",
        chrome: { kill: vitest_1.vi.fn(async () => { }) },
    })),
}));
(0, vitest_1.describe)("browserbase accessors", () => {
    (0, vitest_1.beforeEach)(() => {
        process.env.BROWSERBASE_API_KEY = "fake-key";
        process.env.BROWSERBASE_PROJECT_ID = "fake-project";
    });
    (0, vitest_1.afterEach)(() => {
        delete process.env.BROWSERBASE_API_KEY;
        delete process.env.BROWSERBASE_PROJECT_ID;
        vitest_1.vi.clearAllMocks();
    });
    (0, vitest_1.it)("exposes Browserbase session and debug URLs after init", async () => {
        const v3 = new v3_js_1.V3({
            env: "BROWSERBASE",
            disableAPI: true,
            verbose: 0,
        });
        try {
            await v3.init();
            (0, vitest_1.expect)(v3.browserbaseSessionURL).toBe(MOCK_SESSION_URL);
            (0, vitest_1.expect)(v3.browserbaseDebugURL).toBe(MOCK_DEBUG_URL);
        }
        finally {
            await v3.close().catch(() => { });
        }
    });
    (0, vitest_1.it)("clears stored URLs after close", async () => {
        const v3 = new v3_js_1.V3({
            env: "BROWSERBASE",
            disableAPI: true,
            verbose: 0,
        });
        await v3.init();
        await v3.close();
        (0, vitest_1.expect)(v3.browserbaseSessionURL).toBeUndefined();
        (0, vitest_1.expect)(v3.browserbaseDebugURL).toBeUndefined();
    });
});
(0, vitest_1.describe)("local accessors", () => {
    (0, vitest_1.it)("stay empty for LOCAL environments", async () => {
        const v3 = new v3_js_1.V3({
            env: "LOCAL",
            disableAPI: true,
            verbose: 0,
            localBrowserLaunchOptions: {
                cdpUrl: "ws://local-existing-session",
            },
        });
        try {
            await v3.init();
            (0, vitest_1.expect)(v3.browserbaseSessionURL).toBeUndefined();
            (0, vitest_1.expect)(v3.browserbaseDebugURL).toBeUndefined();
        }
        finally {
            await v3.close().catch(() => { });
        }
    });
});
//# sourceMappingURL=browserbase-session-accessors.test.js.map