fix: harden message aborts + bluebubbles dm create (#1751) (thanks @tyler6204)
This commit is contained in:
@@ -321,6 +321,44 @@ describe("runMessageAction context isolation", () => {
|
||||
}),
|
||||
).rejects.toThrow(/Cross-context messaging denied/);
|
||||
});
|
||||
|
||||
it("aborts send when abortSignal is already aborted", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
|
||||
await expect(
|
||||
runMessageAction({
|
||||
cfg: slackConfig,
|
||||
action: "send",
|
||||
params: {
|
||||
channel: "slack",
|
||||
target: "#C12345678",
|
||||
message: "hi",
|
||||
},
|
||||
dryRun: true,
|
||||
abortSignal: controller.signal,
|
||||
}),
|
||||
).rejects.toMatchObject({ name: "AbortError" });
|
||||
});
|
||||
|
||||
it("aborts broadcast when abortSignal is already aborted", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
|
||||
await expect(
|
||||
runMessageAction({
|
||||
cfg: slackConfig,
|
||||
action: "broadcast",
|
||||
params: {
|
||||
targets: ["channel:C12345678"],
|
||||
channel: "slack",
|
||||
message: "hi",
|
||||
},
|
||||
dryRun: true,
|
||||
abortSignal: controller.signal,
|
||||
}),
|
||||
).rejects.toMatchObject({ name: "AbortError" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("runMessageAction sendAttachment hydration", () => {
|
||||
|
||||
@@ -526,6 +526,7 @@ async function handleBroadcastAction(
|
||||
input: RunMessageActionParams,
|
||||
params: Record<string, unknown>,
|
||||
): Promise<MessageActionRunResult> {
|
||||
throwIfAborted(input.abortSignal);
|
||||
const broadcastEnabled = input.cfg.tools?.message?.broadcast?.enabled !== false;
|
||||
if (!broadcastEnabled) {
|
||||
throw new Error("Broadcast is disabled. Set tools.message.broadcast.enabled to true.");
|
||||
@@ -550,8 +551,11 @@ async function handleBroadcastAction(
|
||||
error?: string;
|
||||
result?: MessageSendResult;
|
||||
}> = [];
|
||||
const isAbortError = (err: unknown): boolean => err instanceof Error && err.name === "AbortError";
|
||||
for (const targetChannel of targetChannels) {
|
||||
throwIfAborted(input.abortSignal);
|
||||
for (const target of rawTargets) {
|
||||
throwIfAborted(input.abortSignal);
|
||||
try {
|
||||
const resolved = await resolveChannelTarget({
|
||||
cfg: input.cfg,
|
||||
@@ -575,6 +579,7 @@ async function handleBroadcastAction(
|
||||
result: sendResult.kind === "send" ? sendResult.sendResult : undefined,
|
||||
});
|
||||
} catch (err) {
|
||||
if (isAbortError(err)) throw err;
|
||||
results.push({
|
||||
channel: targetChannel,
|
||||
to: target,
|
||||
|
||||
Reference in New Issue
Block a user