mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 20:21:13 +00:00
fix(plugins): finish channel lint cleanup
This commit is contained in:
@@ -116,9 +116,13 @@ describe("CDP screenshot params", () => {
|
||||
|
||||
const setCalls = sentMessages.filter((m) => m.method === "Emulation.setDeviceMetricsOverride");
|
||||
expect(setCalls.length).toBe(2);
|
||||
const [firstSetCall, secondSetCall] = setCalls;
|
||||
if (!firstSetCall || !secondSetCall) {
|
||||
throw new Error("expected two viewport updates");
|
||||
}
|
||||
|
||||
// Expand: uses saved DPR, mobile defaults to false
|
||||
expect(setCalls[0]!.params).toMatchObject({
|
||||
expect(firstSetCall.params).toMatchObject({
|
||||
width: 1200,
|
||||
height: 3000,
|
||||
deviceScaleFactor: 2,
|
||||
@@ -130,7 +134,7 @@ describe("CDP screenshot params", () => {
|
||||
expect(clearCall).toBeDefined();
|
||||
|
||||
// Viewport drifted after clear → re-apply saved dimensions
|
||||
expect(setCalls[1]!.params).toMatchObject({
|
||||
expect(secondSetCall.params).toMatchObject({
|
||||
width: 800,
|
||||
height: 600,
|
||||
deviceScaleFactor: 2,
|
||||
|
||||
@@ -57,7 +57,7 @@ function createCfg(): OpenClawConfig {
|
||||
}
|
||||
|
||||
function resolveAccount(cfg: OpenClawConfig, accountId = "default"): ResolvedDiscordAccount {
|
||||
return discordPlugin.config.resolveAccount(cfg, accountId) as ResolvedDiscordAccount;
|
||||
return discordPlugin.config.resolveAccount(cfg, accountId);
|
||||
}
|
||||
|
||||
function startDiscordAccount(cfg: OpenClawConfig, accountId = "default") {
|
||||
@@ -414,7 +414,7 @@ describe("discordPlugin security", () => {
|
||||
|
||||
const result = resolveDmPolicy({
|
||||
cfg,
|
||||
account: discordPlugin.config.resolveAccount(cfg, "default") as ResolvedDiscordAccount,
|
||||
account: discordPlugin.config.resolveAccount(cfg, "default"),
|
||||
});
|
||||
if (!result) {
|
||||
throw new Error("discord resolveDmPolicy returned null");
|
||||
|
||||
@@ -24,6 +24,10 @@ function jsonResponse(value: unknown): Response {
|
||||
});
|
||||
}
|
||||
|
||||
function resolveFetchUrl(input: string | URL | Request): string {
|
||||
return typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
}
|
||||
|
||||
describe("discord directory live lookups", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
@@ -50,7 +54,7 @@ describe("discord directory live lookups", () => {
|
||||
|
||||
it("filters group channels by query and respects limit", async () => {
|
||||
vi.spyOn(globalThis, "fetch").mockImplementation(async (input) => {
|
||||
const url = String(input);
|
||||
const url = resolveFetchUrl(input);
|
||||
if (url.endsWith("/users/@me/guilds")) {
|
||||
return jsonResponse([
|
||||
{ id: "g1", name: "Guild 1" },
|
||||
@@ -79,7 +83,7 @@ describe("discord directory live lookups", () => {
|
||||
|
||||
it("returns ranked peer results and caps member search by limit", async () => {
|
||||
vi.spyOn(globalThis, "fetch").mockImplementation(async (input) => {
|
||||
const url = String(input);
|
||||
const url = resolveFetchUrl(input);
|
||||
if (url.endsWith("/users/@me/guilds")) {
|
||||
return jsonResponse([{ id: "g1", name: "Guild 1" }]);
|
||||
}
|
||||
|
||||
@@ -41,11 +41,12 @@ function createPairingStoreMocks() {
|
||||
}
|
||||
|
||||
const conversationRuntimeModule = await import("openclaw/plugin-sdk/conversation-runtime");
|
||||
vi.spyOn(conversationRuntimeModule, "readChannelAllowFromStore").mockImplementation(
|
||||
createPairingStoreMocks().readChannelAllowFromStore,
|
||||
const pairingStoreMocks = createPairingStoreMocks();
|
||||
vi.spyOn(conversationRuntimeModule, "readChannelAllowFromStore").mockImplementation((...args) =>
|
||||
pairingStoreMocks.readChannelAllowFromStore(...args),
|
||||
);
|
||||
vi.spyOn(conversationRuntimeModule, "upsertChannelPairingRequest").mockImplementation(
|
||||
createPairingStoreMocks().upsertChannelPairingRequest,
|
||||
vi.spyOn(conversationRuntimeModule, "upsertChannelPairingRequest").mockImplementation((...args) =>
|
||||
pairingStoreMocks.upsertChannelPairingRequest(...args),
|
||||
);
|
||||
|
||||
const configRuntimeModule = await import("openclaw/plugin-sdk/config-runtime");
|
||||
|
||||
@@ -187,8 +187,9 @@ function createAllowedGuildEntries(requireMention = false) {
|
||||
|
||||
function createHydratedGuildClient(restPayload: Record<string, unknown>) {
|
||||
const restGet = vi.fn(async () => restPayload);
|
||||
const baseClient = createGuildTextClient(CHANNEL_ID);
|
||||
const client = {
|
||||
...createGuildTextClient(CHANNEL_ID),
|
||||
...Object.assign(Object.create(Object.getPrototypeOf(baseClient)), baseClient),
|
||||
rest: {
|
||||
get: restGet,
|
||||
},
|
||||
|
||||
@@ -480,8 +480,9 @@ describe("preflightDiscordMessage", () => {
|
||||
bot: true,
|
||||
},
|
||||
}));
|
||||
const baseClient = createThreadClient({ threadId, parentId });
|
||||
const client = {
|
||||
...createThreadClient({ threadId, parentId }),
|
||||
...Object.assign(Object.create(Object.getPrototypeOf(baseClient)), baseClient),
|
||||
rest: {
|
||||
get: restGet,
|
||||
},
|
||||
|
||||
@@ -75,9 +75,7 @@ function createDispatchSpy() {
|
||||
tool: 0,
|
||||
},
|
||||
} as never);
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(
|
||||
dispatcherModule.dispatchReplyWithDispatcher as typeof import("openclaw/plugin-sdk/reply-runtime").dispatchReplyWithDispatcher,
|
||||
);
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(dispatcherModule.dispatchReplyWithDispatcher);
|
||||
return dispatchSpy;
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ describe("Discord native slash commands with commands.allowFrom", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(
|
||||
dispatcherModule.dispatchReplyWithDispatcher as typeof import("openclaw/plugin-sdk/reply-runtime").dispatchReplyWithDispatcher,
|
||||
dispatcherModule.dispatchReplyWithDispatcher,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -240,9 +240,7 @@ function createDispatchSpy() {
|
||||
const dispatchSpy = vi
|
||||
.spyOn(dispatcherModule, "dispatchReplyWithDispatcher")
|
||||
.mockResolvedValue({} as never);
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(
|
||||
dispatcherModule.dispatchReplyWithDispatcher as typeof import("openclaw/plugin-sdk/reply-runtime").dispatchReplyWithDispatcher,
|
||||
);
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(dispatcherModule.dispatchReplyWithDispatcher);
|
||||
return dispatchSpy;
|
||||
}
|
||||
|
||||
@@ -251,7 +249,7 @@ describe("Discord model picker interactions", () => {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
nativeCommandTesting.setDispatchReplyWithDispatcher(
|
||||
dispatcherModule.dispatchReplyWithDispatcher as typeof import("openclaw/plugin-sdk/reply-runtime").dispatchReplyWithDispatcher,
|
||||
dispatcherModule.dispatchReplyWithDispatcher,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ function createNativeCommand(
|
||||
if (!command) {
|
||||
throw new Error(`missing native command: ${name}`);
|
||||
}
|
||||
const baseCfg = (opts?.cfg ?? {}) as ReturnType<typeof loadConfig>;
|
||||
const baseCfg: ReturnType<typeof loadConfig> = opts?.cfg ?? {};
|
||||
const discordConfig = (opts?.discordConfig ?? baseCfg.channels?.discord ?? {}) as NonNullable<
|
||||
OpenClawConfig["channels"]
|
||||
>["discord"];
|
||||
|
||||
@@ -1566,7 +1566,7 @@ describe("thread binding lifecycle", () => {
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
resolveThreadBindingInactivityExpiresAt({
|
||||
record: disabled!,
|
||||
record: disabled,
|
||||
defaultIdleTimeoutMs: manager.getIdleTimeoutMs(),
|
||||
}),
|
||||
).toBeUndefined();
|
||||
|
||||
@@ -561,12 +561,14 @@ describe("DiscordVoiceManager", () => {
|
||||
|
||||
it("DiscordVoiceReadyListener: propagates autoJoin errors fire-and-forget without throwing", async () => {
|
||||
const manager = createManager();
|
||||
vi.spyOn(manager, "autoJoin").mockRejectedValue(new Error("autoJoin rejected"));
|
||||
const autoJoinSpy = vi
|
||||
.spyOn(manager, "autoJoin")
|
||||
.mockRejectedValue(new Error("autoJoin rejected"));
|
||||
|
||||
const { DiscordVoiceReadyListener } = managerModule;
|
||||
const listener = new DiscordVoiceReadyListener(manager);
|
||||
|
||||
await expect(listener.handle(undefined, undefined as never)).resolves.not.toThrow();
|
||||
expect(manager.autoJoin).toHaveBeenCalledTimes(1);
|
||||
expect(autoJoinSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,7 +46,8 @@ function createAutoAbortController() {
|
||||
async function runMonitorWithMocks(opts: MonitorSignalProviderOptions) {
|
||||
return monitorSignalProvider({
|
||||
config: config as OpenClawConfig,
|
||||
waitForTransportReady: waitForTransportReadyMock as any,
|
||||
waitForTransportReady:
|
||||
waitForTransportReadyMock as MonitorSignalProviderOptions["waitForTransportReady"],
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ type MonitorSignalProviderOptions = Parameters<typeof monitorSignalProvider>[0];
|
||||
async function runMonitorWithMocks(opts: MonitorSignalProviderOptions) {
|
||||
return monitorSignalProvider({
|
||||
config: config as OpenClawConfig,
|
||||
waitForTransportReady: waitForTransportReadyMock as any,
|
||||
waitForTransportReady:
|
||||
waitForTransportReadyMock as MonitorSignalProviderOptions["waitForTransportReady"],
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -713,7 +713,8 @@ describe("monitorSlackProvider tool results", () => {
|
||||
expect(replyMock).not.toHaveBeenCalled();
|
||||
expect(upsertPairingRequestMock).toHaveBeenCalled();
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
expectPairingReplyText(String(sendMock.mock.calls[0]?.[1] ?? ""), {
|
||||
const sentText = sendMock.mock.calls[0]?.[1];
|
||||
expectPairingReplyText(typeof sentText === "string" ? sentText : "", {
|
||||
channel: "slack",
|
||||
idLine: "Your Slack user id: U1",
|
||||
code: "PAIRCODE",
|
||||
|
||||
@@ -152,7 +152,9 @@ describe("SlackExecApprovalHandler", () => {
|
||||
const buttons = Array.isArray(actionsBlock?.elements) ? actionsBlock.elements : [];
|
||||
const buttonTexts = buttons.map((button) =>
|
||||
typeof button === "object" && button && typeof button.text === "object" && button.text
|
||||
? String((button.text as { text?: unknown }).text ?? "")
|
||||
? typeof (button.text as { text?: unknown }).text === "string"
|
||||
? (button.text as { text: string }).text
|
||||
: ""
|
||||
: "",
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user