Skip to content

The platform for continuously improving AI agents.

1.9 KB
Raw Blame
// covers: console-logic
/** The poll must terminate: the key carries page and filters, so a
 * never-stopping interval means one live 5s loop per visited page. */
import { describe, expect, it } from "vitest";

import { finetuningJobsPollInterval } from "./use-finetuning";

describe("finetuningJobsPollInterval", () => {
  it("stops once every job is terminal", () => {
    expect(
      finetuningJobsPollInterval([
        { status: "succeeded" },
        { status: "failed" },
        { status: "cancelled" },
      ])
    ).toBe(false);
    expect(finetuningJobsPollInterval([])).toBe(false);
  });

  it("continues until the native evaluation plan finishes", () => {
    expect(
      finetuningJobsPollInterval([
        { nativeEvaluation: { state: "final_candidate" }, status: "succeeded" },
      ])
    ).toBe(5_000);
    expect(
      finetuningJobsPollInterval([
        { nativeEvaluation: { state: "completed" }, status: "succeeded" },
      ])
    ).toBe(false);
    expect(
      finetuningJobsPollInterval([
        { nativeEvaluation: { state: "submission_unknown" }, status: "succeeded" },
      ])
    ).toBe(false);
  });

  it("polls while any job is unfinished, and before the first response", () => {
    expect(finetuningJobsPollInterval([{ status: "succeeded" }, { status: "running" }])).toBe(
      5_000
    );
    // Unknown statuses count as unfinished — a new backend state must not
    // silently freeze the poll.
    expect(finetuningJobsPollInterval([{ status: "uploading" }])).toBe(5_000);
    expect(finetuningJobsPollInterval(undefined)).toBe(5_000);
  });

  it("stops polling deleted evaluations without hiding unfinished training", () => {
    const nativeEvaluation = { deletedAt: new Date(), state: "paused" };
    expect(finetuningJobsPollInterval([{ nativeEvaluation, status: "succeeded" }])).toBe(false);
    expect(finetuningJobsPollInterval([{ nativeEvaluation, status: "running" }])).toBe(5_000);
  });
});