fix: add runtime.events regression tests (#16044) (thanks @scifantastic)

This commit is contained in:
Peter Steinberger
2026-03-03 01:37:37 +00:00
parent 85f01cd9eb
commit ee646dae82
3 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { emitSessionTranscriptUpdate, onSessionTranscriptUpdate } from "./transcript-events.js";
const cleanup: Array<() => void> = [];
afterEach(() => {
while (cleanup.length > 0) {
cleanup.pop()?.();
}
});
describe("transcript events", () => {
it("emits trimmed session file updates", () => {
const listener = vi.fn();
cleanup.push(onSessionTranscriptUpdate(listener));
emitSessionTranscriptUpdate(" /tmp/session.jsonl ");
expect(listener).toHaveBeenCalledTimes(1);
expect(listener).toHaveBeenCalledWith({ sessionFile: "/tmp/session.jsonl" });
});
it("continues notifying other listeners when one throws", () => {
const first = vi.fn(() => {
throw new Error("boom");
});
const second = vi.fn();
cleanup.push(onSessionTranscriptUpdate(first));
cleanup.push(onSessionTranscriptUpdate(second));
expect(() => emitSessionTranscriptUpdate("/tmp/session.jsonl")).not.toThrow();
expect(first).toHaveBeenCalledTimes(1);
expect(second).toHaveBeenCalledTimes(1);
});
});