import { describe, expect, test } from "bun:test";
import { registerProvider, resolveProviderFactory } from "../src/registry/factory";
import { resolveSourceProviderFactory } from "../src/sources/provider-factory";

describe("provider-registry", () => {
  test("resolveProviderFactory returns null for unknown type", () => {
    expect(resolveProviderFactory("nonexistent-provider-xyz")).toBeNull();
  });

  test("registerProvider + resolveProviderFactory round-trips", () => {
    const factory = (() => ({
      type: "test-provider",
      search: async () => ({ hits: [] }),
      searchKits: async () => [],
      getKit: async () => null,
      canHandle: () => false,
    })) as unknown as Parameters<typeof registerProvider>[1];
    registerProvider("test-roundtrip", factory);
    expect(resolveProviderFactory("test-roundtrip")).toBe(factory);
  });

  test("static-index is registered after import", async () => {
    // Importing triggers self-registration
    await import("../src/registry/providers/static-index");
    expect(resolveProviderFactory("static-index")).not.toBeNull();
  });

  test("skills-sh is registered after import", async () => {
    await import("../src/registry/providers/skills-sh");
    expect(resolveProviderFactory("skills-sh")).not.toBeNull();
  });

  test("filesystem stash provider is registered after import", async () => {
    await import("../src/sources/providers/filesystem");
    expect(resolveSourceProviderFactory("filesystem")).not.toBeNull();
  });
});
