import test from "node:test";
import assert from "node:assert/strict";
import { conversationDisplayTitle } from "./conversation-title.js";

test("conversation title falls back to the first visible user message", () => {
  const turns = [{
    userText: "First request",
    userMessages: [{ text: "First request" }, { text: "Follow-up" }]
  }];

  assert.equal(conversationDisplayTitle({ session: {}, turns, fallback: "New chat" }), "First request");
  assert.equal(conversationDisplayTitle({ session: { conversationTitle: "Codex title" }, turns, fallback: "New chat" }), "Codex title");
  assert.equal(conversationDisplayTitle({ transition: { label: "Opening title" }, turns, fallback: "New chat" }), "Opening title");
  assert.equal(conversationDisplayTitle({ turns: [], fallback: "New chat" }), "New chat");
});
