import { describe, expect, it } from "vitest";
import {
  getDefaultModelId,
  isBuiltinProviderBaseUrlEditable,
  listBuiltinProviders,
} from "../src/dimsdk/compat/archships/dim-agent/providers/index.ts";

describe("provider registry", () => {
  it("includes required built-in providers", () => {
    const ids = listBuiltinProviders().map((provider) => provider.id);
    expect(ids).toContain("openai");
    expect(ids).toContain("bailian-coding-plan");
    expect(ids).toContain("zhipuai");
    expect(ids).toContain("zhipuai-coding-plan");
    expect(ids).toContain("zai");
    expect(ids).toContain("zai-coding-plan");
    expect(ids).toContain("deepseek");
    expect(ids).toContain("zenmux");
    expect(ids).toContain("moonshot");
    expect(ids).toContain("moonshot-ai");
    expect(ids).toContain("siliconflow");
    expect(ids).toContain("siliconflow-com");
    expect(ids).toContain("ppinfra");
    expect(ids).toContain("ark-code");
    expect(ids).not.toContain("custom");
  });

  it("picks default model when available", () => {
    const provider = listBuiltinProviders().find((entry) => entry.id === "zai-coding-plan");
    expect(provider).toBeDefined();
    expect(getDefaultModelId(provider)).toBe(String(provider?.defaultModelId ?? "").trim());
  });

  it("limits builtin base URL editing to the allowlist only", () => {
    expect(isBuiltinProviderBaseUrlEditable("openai")).toBe(true);
    expect(isBuiltinProviderBaseUrlEditable("google")).toBe(true);
    expect(isBuiltinProviderBaseUrlEditable("anthropic")).toBe(true);
    expect(isBuiltinProviderBaseUrlEditable("ollama")).toBe(true);
    expect(isBuiltinProviderBaseUrlEditable("lm-studio")).toBe(true);

    expect(isBuiltinProviderBaseUrlEditable("deepseek")).toBe(false);
    expect(isBuiltinProviderBaseUrlEditable("bailian-coding-plan")).toBe(false);
    expect(isBuiltinProviderBaseUrlEditable("cp_custom_openai")).toBe(false);
    expect(isBuiltinProviderBaseUrlEditable("custom")).toBe(false);
  });
});
