import { describe, expect, it } from "vitest";
import {
  computeSessionHeaderSummary,
  sanitizeSessionMetaForHeader,
} from "../src/dimsdk/pages/ChatPage/logic/session-header-summary.ts";

describe("dimsdk session header summary", () => {
  it('treats "New Thread" as a placeholder while the first user message is only local', () => {
    const meta = {
      id: "thread_1",
      title: "New Thread",
      summary: "New Thread",
      updatedAt: 0,
      cwd: "",
      lastMessage: "",
      status: "idle",
      queueLength: 0,
      messageCount: 0,
    };

    expect(sanitizeSessionMetaForHeader(meta, "今天天气怎么样")?.title).toBe("");
    expect(computeSessionHeaderSummary(meta, "今天天气怎么样")).toBe("今天天气怎么样");
  });

  it('treats "(empty)" as a placeholder while the first user message is only local', () => {
    const meta = {
      id: "thread_1",
      title: "New Thread",
      summary: "(empty)",
      updatedAt: 0,
      cwd: "",
      lastMessage: "",
      status: "idle",
      queueLength: 0,
      messageCount: 0,
    };

    expect(sanitizeSessionMetaForHeader(meta, "hi")?.summary).toBe("");
    expect(computeSessionHeaderSummary(meta, "hi")).toBe("hi");
  });

  it('falls back to "New Thread" before any user message exists', () => {
    expect(computeSessionHeaderSummary(null, "")).toBe("New Thread");
  });
});
