mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 05:50:47 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
102 lines
3.3 KiB
TypeScript
102 lines
3.3 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import type { TelegramAccountConfig } from "../../../src/config/types.js";
|
|
import {
|
|
createNativeCommandsHarness,
|
|
deliverReplies,
|
|
executePluginCommand,
|
|
getPluginCommandSpecs,
|
|
matchPluginCommand,
|
|
} from "./bot-native-commands.test-helpers.js";
|
|
|
|
type GetPluginCommandSpecsMock = {
|
|
mockReturnValue: (
|
|
value: ReturnType<typeof import("../../../src/plugins/commands.js").getPluginCommandSpecs>,
|
|
) => unknown;
|
|
};
|
|
type MatchPluginCommandMock = {
|
|
mockReturnValue: (
|
|
value: ReturnType<typeof import("../../../src/plugins/commands.js").matchPluginCommand>,
|
|
) => unknown;
|
|
};
|
|
type ExecutePluginCommandMock = {
|
|
mockResolvedValue: (
|
|
value: Awaited<
|
|
ReturnType<typeof import("../../../src/plugins/commands.js").executePluginCommand>
|
|
>,
|
|
) => unknown;
|
|
};
|
|
|
|
const getPluginCommandSpecsMock = getPluginCommandSpecs as unknown as GetPluginCommandSpecsMock;
|
|
const matchPluginCommandMock = matchPluginCommand as unknown as MatchPluginCommandMock;
|
|
const executePluginCommandMock = executePluginCommand as unknown as ExecutePluginCommandMock;
|
|
|
|
describe("registerTelegramNativeCommands (plugin auth)", () => {
|
|
it("does not register plugin commands in menu when native=false but keeps handlers available", () => {
|
|
const specs = Array.from({ length: 101 }, (_, i) => ({
|
|
name: `cmd_${i}`,
|
|
description: `Command ${i}`,
|
|
acceptsArgs: false,
|
|
}));
|
|
getPluginCommandSpecsMock.mockReturnValue(specs);
|
|
|
|
const { handlers, setMyCommands, log } = createNativeCommandsHarness({
|
|
cfg: {} as OpenClawConfig,
|
|
telegramCfg: {} as TelegramAccountConfig,
|
|
nativeEnabled: false,
|
|
});
|
|
|
|
expect(setMyCommands).not.toHaveBeenCalled();
|
|
expect(log).not.toHaveBeenCalledWith(expect.stringContaining("registering first 100"));
|
|
expect(Object.keys(handlers)).toHaveLength(101);
|
|
});
|
|
|
|
it("allows requireAuth:false plugin command even when sender is unauthorized", async () => {
|
|
const command = {
|
|
name: "plugin",
|
|
description: "Plugin command",
|
|
pluginId: "test-plugin",
|
|
requireAuth: false,
|
|
handler: vi.fn(),
|
|
} as const;
|
|
|
|
getPluginCommandSpecsMock.mockReturnValue([
|
|
{ name: "plugin", description: "Plugin command", acceptsArgs: false },
|
|
]);
|
|
matchPluginCommandMock.mockReturnValue({ command, args: undefined });
|
|
executePluginCommandMock.mockResolvedValue({ text: "ok" });
|
|
|
|
const { handlers, bot } = createNativeCommandsHarness({
|
|
cfg: {} as OpenClawConfig,
|
|
telegramCfg: {} as TelegramAccountConfig,
|
|
allowFrom: ["999"],
|
|
nativeEnabled: false,
|
|
});
|
|
|
|
const ctx = {
|
|
message: {
|
|
chat: { id: 123, type: "private" },
|
|
from: { id: 111, username: "nope" },
|
|
message_id: 10,
|
|
date: 123456,
|
|
},
|
|
match: "",
|
|
};
|
|
|
|
await handlers.plugin?.(ctx);
|
|
|
|
expect(matchPluginCommand).toHaveBeenCalled();
|
|
expect(executePluginCommand).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
isAuthorizedSender: false,
|
|
}),
|
|
);
|
|
expect(deliverReplies).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
replies: [{ text: "ok" }],
|
|
}),
|
|
);
|
|
expect(bot.api.sendMessage).not.toHaveBeenCalled();
|
|
});
|
|
});
|