Skip to content
File

Blob: tests/client/log-events.test.ts

typescript33 lines
1import { describe, expect, it } from "vitest";
2 
3import { LogEvent } from "@/contracts";
4import { mergeLogEventBySeq } from "@/client/lib";
5 
6const makeEvent = (seq: number) =>
7 LogEvent.assertDecode({
8 id: `run_test:log:${seq}`,
9 runId: "run_0000000000000000000000",
10 seq,
11 stream: "stdout",
12 chunk: `line ${seq}\n`,
13 createdAt: "2026-03-26T00:00:00.000Z",
14 });
15 
16describe("mergeLogEventBySeq", () => {
17 it("appends newer events at the tail", () => {
18 expect(mergeLogEventBySeq([makeEvent(1), makeEvent(2)], makeEvent(3)).map((event) => event.seq)).toEqual([1, 2, 3]);
19 });
20 
21 it("inserts older out-of-order events into the correct slot", () => {
22 expect(mergeLogEventBySeq([makeEvent(1), makeEvent(4)], makeEvent(2)).map((event) => event.seq)).toEqual([1, 2, 4]);
23 expect(
24 mergeLogEventBySeq([makeEvent(1), makeEvent(2), makeEvent(5)], makeEvent(4)).map((event) => event.seq),
25 ).toEqual([1, 2, 4, 5]);
26 });
27 
28 it("ignores duplicate seq values", () => {
29 const existing = [makeEvent(1), makeEvent(2)];
30 expect(mergeLogEventBySeq(existing, makeEvent(2))).toBe(existing);
31 });
32});