Skip to content

Commit af63939

Browse files
committed
test: clarify Buzz admission and output lifetimes
1 parent 16cfc96 commit af63939

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎docs/channels/buzz.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ follows live relay-signed roster updates, including role changes. A removal
318318
invalidates queued messages immediately; cancelled admission is not committed as
319319
processed. Bounded snapshot refreshes confirm membership-change notifications.
320320
There is no per-message relay query or Gateway polling.
321+
Removing a sender does not cancel a room turn already admitted for that sender;
322+
losing the bot's own Bot role or stopping its connection still fences output.
321323

322324
Startup and reconnect recover eligible messages from the last 24 hours, but
323325
never from before that room's first activation by this Buzz account. That

‎extensions/buzz/src/buzz-bus.socket.test.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createStartAccountContext,
88
} from "openclaw/plugin-sdk/channel-test-helpers";
99
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
10+
import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
1011
import {
1112
createPluginStateKeyedStoreForTests,
1213
resetPluginStateStoreForTests,
@@ -15,6 +16,7 @@ import { afterEach, beforeEach, expect, it, vi } from "vitest";
1516
import { startBuzzBus, type BuzzBus } from "./buzz-bus.js";
1617
import { createBuzzRelayFixture } from "./buzz-relay.test-harness.js";
1718
import { startBuzzGatewayAccount } from "./gateway.js";
19+
import { handleBuzzInbound } from "./inbound.js";
1820
import { setBuzzRuntime } from "./runtime.js";
1921
import { resolveBuzzAccount } from "./types.js";
2022

@@ -152,6 +154,88 @@ it("keeps removal denied through stale snapshots and accepts a confirmed rejoin"
152154
}
153155
});
154156

157+
it("finishes an admitted room turn after its sender is removed", async () => {
158+
const fixture = await createBuzzRelayFixture();
159+
const runtime = createPluginRuntimeMock();
160+
runtime.state.openKeyedStore = (options) => createPluginStateKeyedStoreForTests("buzz", options);
161+
setBuzzRuntime(runtime);
162+
const dispatched = createDeferred<void>();
163+
const continueTurn = createDeferred<void>();
164+
const completed = createDeferred<void>();
165+
const cfg = {
166+
channels: {
167+
buzz: {
168+
relayUrl: fixture.relayUrl,
169+
privateKey: fixture.botPrivateKey,
170+
groupPolicy: "open",
171+
groups: { [fixture.roomId]: { requireMention: false } },
172+
},
173+
},
174+
} satisfies OpenClawConfig;
175+
const account = resolveBuzzAccount({ cfg });
176+
vi.mocked(runtime.channel.inbound.dispatch).mockImplementation(async (params) => {
177+
dispatched.resolve();
178+
await continueTurn.promise;
179+
await params.delivery.deliver({ text: "admitted room reply" }, { kind: "final" });
180+
return {
181+
admission: { kind: "dispatch" },
182+
dispatched: true,
183+
ctxPayload: params.ctxPayload,
184+
routeSessionKey: params.route.sessionKey,
185+
dispatchResult: { queuedFinal: true, counts: { tool: 0, block: 0, final: 1 } },
186+
};
187+
});
188+
let bus: BuzzBus | undefined;
189+
try {
190+
bus = await startBuzzBus({
191+
accountId: account.accountId,
192+
relayUrl: fixture.relayUrl,
193+
privateKey: fixture.botPrivateKey,
194+
channelIds: [fixture.roomId],
195+
onMessage: async (message, activeBus, signal, assertCurrent) => {
196+
await handleBuzzInbound({ account, cfg, bus: activeBus, message, signal, assertCurrent });
197+
completed.resolve();
198+
},
199+
onMessageError: completed.reject,
200+
});
201+
const message = fixture.sendMessage("accepted before removal");
202+
await dispatched.promise;
203+
const initial = fixture.events.find((event) => event.kind === 39002)!;
204+
fixture.broadcast(
205+
fixture.signRelay({
206+
kind: 39002,
207+
created_at: initial.created_at + 1,
208+
content: "",
209+
tags: initial.tags.filter((tag) => tag[0] !== "p" || tag[1] !== fixture.senderPublicKey),
210+
}),
211+
);
212+
await vi.waitFor(() =>
213+
expect(
214+
bus?.directory
215+
.listGroupMembers({ groupId: fixture.roomId })
216+
.some((member) => member.id === fixture.senderPublicKey),
217+
).toBe(false),
218+
);
219+
continueTurn.resolve();
220+
await completed.promise;
221+
const replies = fixture.events.filter(
222+
(event) => event.pubkey === fixture.botPublicKey && event.kind === 9,
223+
);
224+
expect(replies).toHaveLength(1);
225+
expect(replies[0]).toMatchObject({
226+
content: "admitted room reply",
227+
tags: expect.arrayContaining([
228+
["h", fixture.roomId],
229+
["e", message.id, "", "reply"],
230+
]),
231+
});
232+
} finally {
233+
continueTurn.resolve();
234+
await bus?.close();
235+
await fixture.close();
236+
}
237+
});
238+
155239
it("revokes the active bot immediately on a signed role downgrade", async () => {
156240
const fixture = await createBuzzRelayFixture();
157241
const fatal: Error[] = [];
@@ -186,6 +270,9 @@ it("revokes the active bot immediately on a signed role downgrade", async () =>
186270
await vi.waitFor(() => expect(fatal).toHaveLength(1));
187271
expect(fatal[0]?.message).toContain("no longer has the Bot role");
188272
expect(turnSignal?.aborted).toBe(true);
273+
await expect(
274+
bus.sendText({ channelId: fixture.roomId, text: "retired bot reply" }),
275+
).rejects.toThrow("no longer has the Bot role");
189276
} finally {
190277
await bus?.close();
191278
await fixture.close();

0 commit comments

Comments
 (0)