import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { StateManager } from "./AnalysisStateManager.js";
import { AnalysisScope } from "../types/RepositoryAnalysis.js";
describe("StateManager.fromStatePath", () => {
    it("preserves the exact supplied path for a standard-prefixed file", () => {
        const stdPath = path.join(os.tmpdir(), "skyramp-analysis-some-uuid.json");
        const manager = StateManager.fromStatePath(stdPath);
        expect(manager.getStatePath()).toBe(stdPath);
    });
    it("preserves the exact supplied path for a custom filename like analyze-changes-state.json", () => {
        // This is the filename testbot uses — it does NOT match any STATE_FILE_PREFIXES entry.
        // fromStatePath must pass stateFilePath through to the constructor so the path is not rebuilt.
        const customPath = path.join(os.tmpdir(), "analyze-changes-state.json");
        const manager = StateManager.fromStatePath(customPath);
        expect(manager.getStatePath()).toBe(customPath);
    });
});
describe("StateManager.writeData", () => {
    it("creates parent directories when they do not exist", async () => {
        const nestedDir = path.join(os.tmpdir(), `skyramp-test-mkdir-${Date.now()}`);
        const nestedPath = path.join(nestedDir, "state.json");
        // Directory must not exist before the test
        expect(fs.existsSync(nestedDir)).toBe(false);
        const manager = new StateManager("analysis", undefined, undefined, nestedPath);
        await expect(manager.writeData({
            existingTests: [],
            analysisScope: AnalysisScope.CurrentBranchDiff,
            newEndpoints: [],
        })).resolves.not.toThrow();
        expect(fs.existsSync(nestedPath)).toBe(true);
        // cleanup
        await fs.promises.rm(nestedDir, { recursive: true, force: true });
    });
});
