import { describe, expect, it } from "vitest";
import { classifyAutoScanCapture, shouldAbortAfterConsecutiveMisses } from "./autoScanController";

describe("autoScanController", () => {
  it("does not count empty signatures as scanned artifacts", () => {
    expect(classifyAutoScanCapture({ signature: "", lastDetailSignature: "", seen: new Set() })).toMatchObject({ kind: "unreadable" });
  });

  it("separates stuck detail views from duplicates", () => {
    const seen = new Set(["same"]);

    expect(classifyAutoScanCapture({ signature: "same", lastDetailSignature: "same", seen })).toMatchObject({ kind: "stuck" });
    expect(classifyAutoScanCapture({ signature: "same", lastDetailSignature: "other", seen })).toMatchObject({ kind: "duplicate" });
  });

  it("accepts a new signature as a readable artifact", () => {
    expect(classifyAutoScanCapture({ signature: "new", lastDetailSignature: "old", seen: new Set(["old"]) })).toMatchObject({ kind: "new" });
  });

  it("uses a conservative miss threshold", () => {
    expect(shouldAbortAfterConsecutiveMisses(2)).toBe(false);
    expect(shouldAbortAfterConsecutiveMisses(3)).toBe(true);
  });
});
