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

test("conversation window renders only the latest requested turns", () => {
  const turns = Array.from({ length: 205 }, (_, index) => ({ id: `turn-${index}` }));

  const window = conversationWindow(turns, 80);

  assert.equal(window.hiddenTurnCount, 125);
  assert.equal(window.visibleTurns.length, 80);
  assert.equal(window.visibleTurns[0].id, "turn-125");
  assert.equal(window.visibleTurns.at(-1).id, "turn-204");
});
test("conversation window expands without changing turn order", () => {
  const turns = Array.from({ length: 205 }, (_, index) => ({ id: `turn-${index}` }));

  const window = conversationWindow(turns, 160);

  assert.equal(window.hiddenTurnCount, 45);
  assert.deepEqual(window.visibleTurns.slice(0, 2).map((turn) => turn.id), ["turn-45", "turn-46"]);
});
