import { describe, expect, it, vi, afterEach } from "vitest";
import { homedir, platform } from "node:os";
import { join } from "node:path";
// We need to mock os.platform() to test cross-platform behavior
vi.mock("node:os", async (importOriginal) => {
    const actual = await importOriginal();
    return {
        ...actual,
        platform: vi.fn(() => actual.platform()),
    };
});
const mockedPlatform = vi.mocked(platform);
// Dynamic import so mocks are active
async function importPaths() {
    vi.resetModules();
    vi.doMock("node:os", async (importOriginal) => {
        const actual = await importOriginal();
        return {
            ...actual,
            platform: mockedPlatform,
        };
    });
    return import("../paths.js");
}
describe("paths", () => {
    const home = homedir();
    const originalAppData = process.env.APPDATA;
    const originalXdgConfig = process.env.XDG_CONFIG_HOME;
    afterEach(() => {
        process.env.APPDATA = originalAppData;
        process.env.XDG_CONFIG_HOME = originalXdgConfig;
    });
    describe("getConfigDir", () => {
        it("should return correct config dir for macOS", async () => {
            mockedPlatform.mockReturnValue("darwin");
            const { getConfigDir } = await importPaths();
            expect(getConfigDir()).toBe(join(home, "Library", "Application Support", "pocketcoder"));
        });
        it("should return correct config dir for Linux", async () => {
            mockedPlatform.mockReturnValue("linux");
            delete process.env.XDG_CONFIG_HOME;
            const { getConfigDir } = await importPaths();
            expect(getConfigDir()).toBe(join(home, ".config", "pocketcoder"));
        });
        it("should return correct config dir for Windows", async () => {
            mockedPlatform.mockReturnValue("win32");
            process.env.APPDATA = join(home, "AppData", "Roaming");
            const { getConfigDir } = await importPaths();
            expect(getConfigDir()).toBe(join(home, "AppData", "Roaming", "pocketcoder"));
        });
        it("should respect XDG_CONFIG_HOME on Linux", async () => {
            mockedPlatform.mockReturnValue("linux");
            process.env.XDG_CONFIG_HOME = "/custom/config";
            const { getConfigDir } = await importPaths();
            expect(getConfigDir()).toBe(join("/custom/config", "pocketcoder"));
        });
    });
    describe("getAuthPath", () => {
        it("should return correct auth.json path", async () => {
            mockedPlatform.mockReturnValue("linux");
            delete process.env.XDG_CONFIG_HOME;
            const { getAuthPath } = await importPaths();
            expect(getAuthPath()).toBe(join(home, ".config", "pocketcoder", "auth.json"));
        });
    });
    describe("getDbPath", () => {
        it("should return correct daemon.db path", async () => {
            mockedPlatform.mockReturnValue("linux");
            delete process.env.XDG_CONFIG_HOME;
            const { getDbPath } = await importPaths();
            expect(getDbPath()).toBe(join(home, ".config", "pocketcoder", "daemon.db"));
        });
    });
    describe("getLogDir", () => {
        it("should return correct log directory path", async () => {
            const { getLogDir } = await importPaths();
            expect(getLogDir()).toBe(join(home, ".pocketcoder", "logs"));
        });
    });
    describe("getPidPath", () => {
        it("should return correct PID file path", async () => {
            const { getPidPath } = await importPaths();
            expect(getPidPath()).toBe(join(home, ".pocketcoder", "daemon.pid"));
        });
    });
});
//# sourceMappingURL=paths.test.js.map