mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
test: tighten runtime channel assertions
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createRuntimeChannel } from "./runtime-channel.js";
|
||||
|
||||
function requireWatcherEvent(mock: ReturnType<typeof vi.fn>, index: number) {
|
||||
const event = mock.mock.calls[index]?.[0] as { type?: string } | undefined;
|
||||
if (!event) {
|
||||
throw new Error(`Expected watcher event ${index}`);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
describe("runtimeContexts", () => {
|
||||
it("registers, resolves, watches, and unregisters contexts", () => {
|
||||
const channel = createRuntimeChannel();
|
||||
@@ -145,16 +153,8 @@ describe("runtimeContexts", () => {
|
||||
capability: "approval.native",
|
||||
}),
|
||||
).toEqual({ client: "ok" });
|
||||
expect(badWatcher).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "registered",
|
||||
}),
|
||||
);
|
||||
expect(goodWatcher).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "registered",
|
||||
}),
|
||||
);
|
||||
expect(requireWatcherEvent(badWatcher, 0).type).toBe("registered");
|
||||
expect(requireWatcherEvent(goodWatcher, 0).type).toBe("registered");
|
||||
|
||||
lease.dispose();
|
||||
|
||||
@@ -165,16 +165,8 @@ describe("runtimeContexts", () => {
|
||||
capability: "approval.native",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(badWatcher).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "unregistered",
|
||||
}),
|
||||
);
|
||||
expect(goodWatcher).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "unregistered",
|
||||
}),
|
||||
);
|
||||
expect(requireWatcherEvent(badWatcher, 1).type).toBe("unregistered");
|
||||
expect(requireWatcherEvent(goodWatcher, 1).type).toBe("unregistered");
|
||||
});
|
||||
|
||||
it("auto-disposes when a watcher aborts during the registered event", () => {
|
||||
@@ -208,18 +200,8 @@ describe("runtimeContexts", () => {
|
||||
capability: "approval.native",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(onEvent).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
type: "registered",
|
||||
}),
|
||||
);
|
||||
expect(onEvent).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
type: "unregistered",
|
||||
}),
|
||||
);
|
||||
expect(requireWatcherEvent(onEvent, 0).type).toBe("registered");
|
||||
expect(requireWatcherEvent(onEvent, 1).type).toBe("unregistered");
|
||||
|
||||
lease.dispose();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user