import { afterEach, describe, expect, it } from "vitest";

import { resolveSearchVisionModel } from "./search-vision-model.js";

const originalEnv = { ...process.env };

describe("resolveSearchVisionModel", () => {
  afterEach(() => {
    process.env = { ...originalEnv };
  });

  it("prefers the stage-specific search vision model over the legacy alias and global model", () => {
    process.env.SEARCH_VISION_LLM_MODEL = "stage-search-model";
    process.env.SEARCH_VISION_MODEL = "legacy-search-model";
    process.env.LLM_MODEL = "global-model";

    expect(resolveSearchVisionModel()).toBe("stage-search-model");
  });

  it("keeps SEARCH_VISION_MODEL as a compatibility alias before falling back to LLM_MODEL and the code default", () => {
    process.env.SEARCH_VISION_LLM_MODEL = "";
    process.env.SEARCH_VISION_MODEL = "legacy-search-model";
    process.env.LLM_MODEL = "global-model";
    expect(resolveSearchVisionModel()).toBe("legacy-search-model");

    process.env.SEARCH_VISION_MODEL = "  ";
    expect(resolveSearchVisionModel()).toBe("global-model");

    process.env.LLM_MODEL = "";
    expect(resolveSearchVisionModel()).toBe("gemini-2.5-pro-preview-p");
  });
});
