import request from "supertest";
import { describe, expect, it } from "vitest";
import { createApp } from "../src/server";

describe("POST /api/eval/run", () => {
  it("runs v2 eval using inline rawQuestions batch", async () => {
    const app = createApp();
    const response = await request(app).post("/api/eval/run").send({
      normalizeConfig: {
        promptVersion: "normalizer_v2_0_2",
        useMock: true
      },
      useMock: true,
      mode: "single-pass-strict",
      rawQuestions:
        "Проверь хвосты по поставщикам и разложи цепочку; Как вообще по ФСБУ; Покажи топ рисков за июнь 2020"
    });

    expect(response.status).toBe(200);
    expect(response.body.ok).toBe(true);
    expect(response.body.report?.schema_version).toBe("v2_0_2");
    expect(response.body.report?.cases_total).toBe(3);
    expect(typeof response.body.report?.metrics?.schema_validation_pass_rate).toBe("number");
    expect(response.body.report?.metrics?.route_resolution_accuracy).not.toBeUndefined();
    expect(response.body.report?.metrics?.execution_state_consistency_rate).not.toBeUndefined();
    expect(Array.isArray(response.body.report?.results)).toBe(true);
  });
});
