mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 21:48:03 +02:00
fix(ci): support discord rate limit ctor drift
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { RateLimitError } from "@buape/carbon";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { AcpRuntimeError } from "../../../../src/acp/runtime/errors.js";
|
||||
import type { OpenClawConfig } from "../../../../src/config/config.js";
|
||||
@@ -39,6 +40,19 @@ const {
|
||||
let monitorDiscordProvider: typeof import("./provider.js").monitorDiscordProvider;
|
||||
let providerTesting: typeof import("./provider.js").__testing;
|
||||
|
||||
function createCompatRateLimitError(
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
): RateLimitError {
|
||||
const RateLimitErrorCtor = RateLimitError as unknown as new (
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
) => RateLimitError;
|
||||
return new RateLimitErrorCtor(response, body, request);
|
||||
}
|
||||
|
||||
function createConfigWithDiscordAccount(overrides: Record<string, unknown> = {}): OpenClawConfig {
|
||||
return {
|
||||
channels: {
|
||||
@@ -626,7 +640,7 @@ describe("monitorDiscordProvider", () => {
|
||||
const request = new Request("https://discord.com/api/v10/applications/commands", {
|
||||
method: "PUT",
|
||||
});
|
||||
const rateLimitError = new RateLimitError(
|
||||
const rateLimitError = createCompatRateLimitError(
|
||||
new Response(null, {
|
||||
status: 429,
|
||||
headers: {
|
||||
@@ -639,6 +653,7 @@ describe("monitorDiscordProvider", () => {
|
||||
retry_after: 193.632,
|
||||
global: false,
|
||||
},
|
||||
request,
|
||||
);
|
||||
rateLimitError.discordCode = 30034;
|
||||
clientHandleDeployRequestMock.mockRejectedValueOnce(rateLimitError);
|
||||
|
||||
@@ -23,6 +23,19 @@ let timeoutMemberDiscord: typeof import("./send.js").timeoutMemberDiscord;
|
||||
let uploadEmojiDiscord: typeof import("./send.js").uploadEmojiDiscord;
|
||||
let uploadStickerDiscord: typeof import("./send.js").uploadStickerDiscord;
|
||||
|
||||
function createCompatRateLimitError(
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
): RateLimitError {
|
||||
const RateLimitErrorCtor = RateLimitError as unknown as new (
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
) => RateLimitError;
|
||||
return new RateLimitErrorCtor(response, body, request);
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({
|
||||
@@ -423,11 +436,15 @@ function createMockRateLimitError(retryAfter = 0.001): RateLimitError {
|
||||
"X-RateLimit-Bucket": "test-bucket",
|
||||
},
|
||||
});
|
||||
return new RateLimitError(response, {
|
||||
message: "You are being rate limited.",
|
||||
retry_after: retryAfter,
|
||||
global: false,
|
||||
});
|
||||
return createCompatRateLimitError(
|
||||
response,
|
||||
{
|
||||
message: "You are being rate limited.",
|
||||
retry_after: retryAfter,
|
||||
global: false,
|
||||
},
|
||||
request,
|
||||
);
|
||||
}
|
||||
|
||||
describe("retry rate limits", () => {
|
||||
|
||||
@@ -29,6 +29,19 @@ const SUPPRESS_NOTIFICATIONS_FLAG = 1 << 12;
|
||||
const WAVEFORM_SAMPLES = 256;
|
||||
const DISCORD_OPUS_SAMPLE_RATE_HZ = 48_000;
|
||||
|
||||
function createRateLimitError(
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
): RateLimitError {
|
||||
const RateLimitErrorCtor = RateLimitError as unknown as new (
|
||||
response: Response,
|
||||
body: { message: string; retry_after: number; global: boolean },
|
||||
request?: Request,
|
||||
) => RateLimitError;
|
||||
return new RateLimitErrorCtor(response, body, request);
|
||||
}
|
||||
|
||||
export type VoiceMessageMetadata = {
|
||||
durationSecs: number;
|
||||
waveform: string; // base64 encoded
|
||||
@@ -283,11 +296,15 @@ export async function sendDiscordVoiceMessage(
|
||||
retry_after?: number;
|
||||
global?: boolean;
|
||||
};
|
||||
throw new RateLimitError(res, {
|
||||
message: retryData.message ?? "You are being rate limited.",
|
||||
retry_after: retryData.retry_after ?? 1,
|
||||
global: retryData.global ?? false,
|
||||
});
|
||||
throw createRateLimitError(
|
||||
res,
|
||||
{
|
||||
message: retryData.message ?? "You are being rate limited.",
|
||||
retry_after: retryData.retry_after ?? 1,
|
||||
global: retryData.global ?? false,
|
||||
},
|
||||
uploadUrlRequest,
|
||||
);
|
||||
}
|
||||
const errorBody = (await res.json().catch(() => null)) as {
|
||||
code?: number;
|
||||
|
||||
Reference in New Issue
Block a user