import path from "path";
import { SESSION_STORAGE_FILENAME } from "../../types/TestTypes.js";
import { resolveSessionPaths } from "./resolveSessionPaths.js";
describe("resolveSessionPaths", () => {
    const outputDir = "/abs/output";
    const defaultPath = path.join(outputDir, SESSION_STORAGE_FILENAME);
    const baseArgs = {
        loadOverride: undefined,
        saveOverride: undefined,
        outputDir,
        sessionExists: false,
    };
    describe("mode=auto", () => {
        it("captures into the default path when no session exists", () => {
            expect(resolveSessionPaths({ ...baseArgs, mode: "auto" })).toEqual({
                savePath: defaultPath,
            });
        });
        it("reuses (loads) the default path when a session exists, without saving", () => {
            expect(resolveSessionPaths({ ...baseArgs, mode: "auto", sessionExists: true })).toEqual({ loadPath: defaultPath });
        });
        it("respects an explicit load override when given (auto + sessionExists)", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "auto",
                sessionExists: true,
                loadOverride: "/elsewhere/session.json",
            })).toEqual({ loadPath: "/elsewhere/session.json" });
        });
        it("respects an explicit save override (auto + no session)", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "auto",
                saveOverride: "auth.json",
            })).toEqual({ savePath: path.join(outputDir, "auth.json") });
        });
    });
    describe("mode=capture", () => {
        it("always saves at the default path, never loads", () => {
            expect(resolveSessionPaths({ ...baseArgs, mode: "capture" })).toEqual({
                savePath: defaultPath,
            });
        });
        it("ignores a load override (capture is a clean slate)", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "capture",
                loadOverride: "/elsewhere/session.json",
            })).toEqual({ savePath: defaultPath });
        });
        it("honors an explicit save override", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "capture",
                saveOverride: "/tmp/custom.json",
            })).toEqual({ savePath: "/tmp/custom.json" });
        });
        it("still captures even when a session file already exists (we're recapturing)", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "capture",
                sessionExists: true,
            })).toEqual({ savePath: defaultPath });
        });
    });
    describe("mode=reuse", () => {
        it("loads the default path, does not save (preserves the session file)", () => {
            expect(resolveSessionPaths({ ...baseArgs, mode: "reuse" })).toEqual({
                loadPath: defaultPath,
            });
        });
        it("honors an explicit load override", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "reuse",
                loadOverride: "/elsewhere/session.json",
            })).toEqual({ loadPath: "/elsewhere/session.json" });
        });
        it("allows an explicit save override even in reuse (caller wants to refresh)", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "reuse",
                saveOverride: "/tmp/refreshed.json",
            })).toEqual({ loadPath: defaultPath, savePath: "/tmp/refreshed.json" });
        });
    });
    describe("mode=ignore", () => {
        it("loads and saves nothing by default", () => {
            expect(resolveSessionPaths({ ...baseArgs, mode: "ignore" })).toEqual({});
        });
        it("honors explicit overrides only", () => {
            expect(resolveSessionPaths({
                ...baseArgs,
                mode: "ignore",
                loadOverride: "/in/session.json",
                saveOverride: "/out/session.json",
            })).toEqual({
                loadPath: "/in/session.json",
                savePath: "/out/session.json",
            });
        });
    });
});
