mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 13:43:33 +00:00
fix: add runtime.events regression tests (#16044) (thanks @scifantastic)
This commit is contained in:
35
src/sessions/transcript-events.test.ts
Normal file
35
src/sessions/transcript-events.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user