import { describe, expect, it } from "vitest";
import { validateManifest } from "../src/inference/model-metadata";
import { resolveOutputIndex } from "../src/inference/classifier";

const manifest = {
  source: "wagesj45/toxic-comment-classifier",
  revision: "abc123",
  architecture: "DistilBertForSequenceClassification",
  labels: { toxic: 1, nonToxic: 0, names: { toxic: 1, non_toxic: 0 } },
  maxLength: 512,
  quantization: "int8-dynamic",
  runtime: "onnxruntime-web-wasm"
};

describe("model contract", () => {
  it("accepts a binary manifest and resolves common output labels", () => {
    expect(validateManifest(manifest)).toEqual(manifest);
    expect(resolveOutputIndex("LABEL_1", manifest)).toBe(1);
    expect(resolveOutputIndex("not-toxic", manifest)).toBe(0);
    expect(resolveOutputIndex("toxic", manifest)).toBe(1);
  });

  it("rejects incomplete metadata", () => {
    expect(() => validateManifest({ ...manifest, labels: { toxic: 1, nonToxic: 1, names: {} } })).toThrow();
    expect(() => validateManifest({ ...manifest, maxLength: 0 })).toThrow();
    expect(() => validateManifest({ ...manifest, labels: undefined as unknown as typeof manifest.labels })).toThrow();
  });
});
