Files
OmniRoute/tests/unit/event-bus.test.ts
Diego Rodrigues de Sa e Souza 78f09c8d9f Release v3.8.41 (#5327)
Release v3.8.41 — 52 commits since v3.8.40 (19 CHANGELOG bullets, 11 contributors).

All gating CI green: Unit×8, Coverage×8, Vitest, Package Artifact, Quality Ratchet, CodeQL, Lint, Docs Sync (Strict), Node 24/26 compat, E2E×9, Integration, Electron smoke.

Advisory checks overridden (main unprotected): PR Test Policy = test-masking heuristic on the cumulative 52-commit assert delta (legitimate dead-code-sweep removals + consolidations, reviewed per-PR); SonarCloud/SonarQube = new-code maintainability/coverage quality gate (CodeQL/Semgrep/Security/npm-audit/Dependabot all clean — not a security finding).
2026-06-29 16:51:03 -03:00

62 lines
1.7 KiB
TypeScript

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
import {
emit,
getEventHistory,
on,
onAny,
type HistoryEntry,
} from "../../src/lib/events/eventBus.ts";
import * as eventBusPublicApi from "../../src/lib/events/eventBus.ts";
const requestStartedPayload = {
id: "req-1",
model: "gpt-test",
provider: "openai",
timestamp: 123,
};
describe("eventBus", () => {
beforeEach(() => {
globalThis.__omnirouteEventBus = undefined;
});
it("public surface excludes unused listener management helpers", () => {
assert.equal("off" in eventBusPublicApi, false);
assert.equal("removeAllListeners" in eventBusPublicApi, false);
assert.equal("getBusStats" in eventBusPublicApi, false);
});
it("emits to specific and wildcard listeners until unsubscribed", () => {
const received: (typeof requestStartedPayload)[] = [];
const wildcardEvents: string[] = [];
const unsubscribe = on("request.started", (payload) => {
received.push(payload);
});
const unsubscribeAny = onAny((event) => {
wildcardEvents.push(event);
});
emit("request.started", requestStartedPayload);
unsubscribe();
unsubscribeAny();
emit("request.started", { ...requestStartedPayload, id: "req-2" });
assert.deepEqual(received, [requestStartedPayload]);
assert.deepEqual(wildcardEvents, ["request.started"]);
});
it("keeps recent event history for late subscribers", () => {
emit("request.started", requestStartedPayload);
const history: HistoryEntry[] = getEventHistory(undefined, 1);
assert.equal(history.length, 1);
assert.equal(history[0]?.event, "request.started");
assert.deepEqual(history[0]?.payload, requestStartedPayload);
});
});