import { describe, expect, it } from "vitest"; import { createTelemetryBatcher, renderTelemetryWorkerJs, } from "../web/worker.js"; describe("ui telemetry worker", () => { it("batches raw events", () => { const batcher = createTelemetryBatcher({ maxBatch: 2 }); expect(batcher.add({ type: "click", target: "SEND" })).toEqual([]); expect(batcher.add({ type: "scroll", y: 20, dwellMs: 100 })).toEqual([ { type: "click", target: "SEND" }, { type: "scroll", y: 20, dwellMs: 100 }, ]); }); it("redacts selection and input text before flush", () => { const batcher = createTelemetryBatcher({ maxBatch: 10 }); batcher.add({ type: "selection", text: "private" }); expect(batcher.flush()).toEqual([ { type: "selection", text: "[redacted 7 chars]" }, ]); }); it("renders browser worker source", () => { const source = renderTelemetryWorkerJs(); expect(source).toContain("postMessage"); expect(source).toContain("telemetry_batch"); }); });