import { describe, expect, it } from "vitest"; import { __evalRouteAsyncTestUtils } from "../src/routes/eval"; describe("eval async job sync", () => { it("marks cases as completed when report already contains case results", () => { const job = { job_id: "job-sync-report", status: "running", created_at: "2026-04-11T00:00:00.000Z", updated_at: "2026-04-11T00:00:00.000Z", eval_target: "assistant_stage1", run_id: "assistant-stage1-ut-sync-report", case_set_file: "dummy.json", analysis_date: "2017-07-10", total_cases: 2, completed_cases: 0, cases: [ { case_id: "AUTO-001", turns_total: 1, status: "queued", messages: [] }, { case_id: "AUTO-002", turns_total: 1, status: "queued", messages: [] } ], error: null, report: { results: [{ case_id: "AUTO-001" }, { case_id: "AUTO-002" }] } } as any; __evalRouteAsyncTestUtils.syncJobWithSessions(job); expect(job.completed_cases).toBe(2); expect(job.status).toBe("completed"); expect(job.cases.map((item: any) => item.status)).toEqual(["completed", "completed"]); }); it("keeps terminal case state when job is already completed and session file is missing", () => { const job = { job_id: "job-sync-sticky", status: "completed", created_at: "2026-04-11T00:00:00.000Z", updated_at: "2026-04-11T00:00:00.000Z", eval_target: "assistant_stage1", run_id: "assistant-stage1-ut-sync-sticky", case_set_file: "dummy.json", analysis_date: null, total_cases: 1, completed_cases: 1, cases: [ { case_id: "AUTO-001", turns_total: 1, status: "completed", messages: [] } ], error: null, report: null } as any; __evalRouteAsyncTestUtils.syncJobWithSessions(job); expect(job.completed_cases).toBe(1); expect(job.status).toBe("completed"); expect(job.cases[0].status).toBe("completed"); }); });