import { describe, expect, it } from "vitest"; import { longOutputModel, toggleLongOutput, } from "../web/components/long-output.js"; import { virtualWindow } from "../web/components/virtual-stream.js"; describe("ui stream performance guards", () => { it("truncates long output and preserves expansion state", () => { const text = "x".repeat(2_000); expect(longOutputModel("e1", text, new Set(), 120)).toMatchObject({ id: "e1", truncated: true, text: "x".repeat(120), }); const expanded = toggleLongOutput("e1", new Set()); expect(longOutputModel("e1", text, expanded, 120)).toMatchObject({ truncated: false, text, }); }); it("returns ordered virtual windows around selected item", () => { const events = Array.from({ length: 100 }, (_, index) => ({ id: index + 1, })); expect( virtualWindow(events, { selectedId: 50, threshold: 20, radius: 3 }).map( (e) => e.id, ), ).toEqual([47, 48, 49, 50, 51, 52, 53]); expect( virtualWindow(events, { selectedId: 2, threshold: 200, radius: 3 }), ).toEqual(events); }); });