Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

2.4 KB
Raw Blame
import { describe, expect, test } from "vitest";

import { getAssistantActivityState, getRunningAssistantPartType } from "./assistant-activity-state";

describe("getAssistantActivityState", () => {
  test("does not treat output from the previous completed response as current streaming", () => {
    expect(getRunningAssistantPartType("complete", "text")).toBeUndefined();
    expect(getRunningAssistantPartType("running", "text")).toBe("text");
  });

  test("distinguishes thinking from a response that is already streaming", () => {
    expect(
      getAssistantActivityState({ isRunning: true, latestPartType: undefined, needsApproval: false, failed: false }),
    ).toBe("thinking");
    expect(
      getAssistantActivityState({ isRunning: true, latestPartType: "reasoning", needsApproval: false, failed: false }),
    ).toBe("thinking");
    expect(
      getAssistantActivityState({ isRunning: true, latestPartType: "text", needsApproval: false, failed: false }),
    ).toBe("streaming");
  });

  test("shows a waiting pattern while a tool is running", () => {
    expect(
      getAssistantActivityState({
        isRunning: true,
        latestPartType: "tool-call",
        needsApproval: false,
        failed: false,
      }),
    ).toBe("waiting");
  });

  test("returns to thinking after the latest tool completes and the next model step starts", () => {
    expect(getRunningAssistantPartType("running", "tool-call", true)).toBeUndefined();
    expect(
      getAssistantActivityState({
        isRunning: true,
        latestPartType: getRunningAssistantPartType("running", "tool-call", true),
        needsApproval: false,
        failed: false,
      }),
    ).toBe("thinking");
  });

  test("maps settled states to waiting, failure, and success glyphs", () => {
    expect(
      getAssistantActivityState({ isRunning: false, latestPartType: "text", needsApproval: true, failed: false }),
    ).toBe("waiting");
    expect(
      getAssistantActivityState({ isRunning: false, latestPartType: "text", needsApproval: false, failed: true }),
    ).toBe("error");
    expect(
      getAssistantActivityState({ isRunning: false, latestPartType: "text", needsApproval: false, failed: false }),
    ).toBe("success");
  });

  test("keeps a required action visible even if the last run also failed", () => {
    expect(
      getAssistantActivityState({ isRunning: false, latestPartType: "text", needsApproval: true, failed: true }),
    ).toBe("waiting");
  });
});