




























@@ -152,12 +152,14 @@ describe("bot-native-command-menu", () => {
152152153153it("deletes stale commands before setting new menu", async () => {
154154const callOrder: string[] = [];
155-const deleteMyCommands = vi.fn(async () => {
156-callOrder.push("delete");
157-});
158-const setMyCommands = vi.fn(async () => {
159-callOrder.push("set");
155+const deleteMyCommands = vi.fn(async (options?: { scope?: { type?: string } }) => {
156+callOrder.push(options?.scope?.type ? `delete:${options.scope.type}` : "delete:default");
160157});
158+const setMyCommands = vi.fn(
159+async (_commands: unknown, options?: { scope?: { type?: string } }) => {
160+callOrder.push(options?.scope?.type ? `set:${options.scope.type}` : "set:default");
161+},
162+);
161163162164syncMenuCommandsWithMocks({
163165 deleteMyCommands,
@@ -171,7 +173,35 @@ describe("bot-native-command-menu", () => {
171173expect(setMyCommands).toHaveBeenCalled();
172174});
173175174-expect(callOrder).toEqual(["delete", "set"]);
176+expect(callOrder).toEqual([
177+"delete:default",
178+"delete:all_group_chats",
179+"set:default",
180+"set:all_group_chats",
181+]);
182+});
183+184+it("registers the menu in default and group chat scopes", async () => {
185+const deleteMyCommands = vi.fn(async () => undefined);
186+const setMyCommands = vi.fn(async () => undefined);
187+const commands = [{ command: "cmd", description: "Command" }];
188+189+syncMenuCommandsWithMocks({
190+ deleteMyCommands,
191+ setMyCommands,
192+commandsToRegister: commands,
193+accountId: `test-scopes-${Date.now()}`,
194+botIdentity: "bot-a",
195+});
196+197+await vi.waitFor(() => {
198+expect(setMyCommands).toHaveBeenCalledTimes(2);
199+});
200+201+expect(setMyCommands).toHaveBeenCalledWith(commands);
202+expect(setMyCommands).toHaveBeenCalledWith(commands, {
203+scope: { type: "all_group_chats" },
204+});
175205});
176206177207it("produces a stable hash regardless of command order (#32017)", () => {
@@ -209,7 +239,7 @@ describe("bot-native-command-menu", () => {
209239});
210240211241await vi.waitFor(() => {
212-expect(setMyCommands).toHaveBeenCalledTimes(1);
242+expect(setMyCommands).toHaveBeenCalledTimes(2);
213243});
214244215245// Second sync with the same commands — hash is cached, should skip.
@@ -222,8 +252,8 @@ describe("bot-native-command-menu", () => {
222252botIdentity: "bot-a",
223253});
224254225-// setMyCommands should NOT have been called a second time.
226-expect(setMyCommands).toHaveBeenCalledTimes(1);
255+// setMyCommands should NOT have been called again for either scope.
256+expect(setMyCommands).toHaveBeenCalledTimes(2);
227257});
228258229259it("does not reuse cached hash across different bot identities", async () => {
@@ -241,7 +271,7 @@ describe("bot-native-command-menu", () => {
241271 accountId,
242272botIdentity: "token-bot-a",
243273});
244-await vi.waitFor(() => expect(setMyCommands).toHaveBeenCalledTimes(1));
274+await vi.waitFor(() => expect(setMyCommands).toHaveBeenCalledTimes(2));
245275246276syncMenuCommandsWithMocks({
247277 deleteMyCommands,
@@ -251,7 +281,7 @@ describe("bot-native-command-menu", () => {
251281 accountId,
252282botIdentity: "token-bot-b",
253283});
254-await vi.waitFor(() => expect(setMyCommands).toHaveBeenCalledTimes(2));
284+await vi.waitFor(() => expect(setMyCommands).toHaveBeenCalledTimes(4));
255285});
256286257287it("does not cache empty-menu hash when deleteMyCommands fails", async () => {
@@ -271,7 +301,7 @@ describe("bot-native-command-menu", () => {
271301 accountId,
272302botIdentity: "bot-a",
273303});
274-await vi.waitFor(() => expect(deleteMyCommands).toHaveBeenCalledTimes(1));
304+await vi.waitFor(() => expect(deleteMyCommands).toHaveBeenCalledTimes(2));
275305276306syncMenuCommandsWithMocks({
277307 deleteMyCommands,
@@ -281,7 +311,7 @@ describe("bot-native-command-menu", () => {
281311 accountId,
282312botIdentity: "bot-a",
283313});
284-await vi.waitFor(() => expect(deleteMyCommands).toHaveBeenCalledTimes(2));
314+await vi.waitFor(() => expect(deleteMyCommands).toHaveBeenCalledTimes(4));
285315});
286316287317it("retries with fewer commands on BOT_COMMANDS_TOO_MUCH", async () => {
@@ -307,12 +337,15 @@ describe("bot-native-command-menu", () => {
307337});
308338309339await vi.waitFor(() => {
310-expect(setMyCommands).toHaveBeenCalledTimes(2);
340+expect(setMyCommands).toHaveBeenCalledTimes(3);
311341});
312342const firstPayload = setMyCommands.mock.calls[0]?.[0] as Array<unknown>;
313343const secondPayload = setMyCommands.mock.calls[1]?.[0] as Array<unknown>;
344+const thirdPayload = setMyCommands.mock.calls[2]?.[0] as Array<unknown>;
314345expect(firstPayload).toHaveLength(100);
315346expect(secondPayload).toHaveLength(80);
347+expect(thirdPayload).toHaveLength(80);
348+expect(setMyCommands.mock.calls[2]?.[1]).toEqual({ scope: { type: "all_group_chats" } });
316349expect(runtimeLog).toHaveBeenCalledWith(
317350"Telegram rejected 100 commands (BOT_COMMANDS_TOO_MUCH); retrying with 80.",
318351);
@@ -343,7 +376,7 @@ describe("bot-native-command-menu", () => {
343376});
344377345378await vi.waitFor(() => {
346-expect(setMyCommands).toHaveBeenCalledTimes(2);
379+expect(setMyCommands).toHaveBeenCalledTimes(3);
347380});
348381expect(runtimeLog).toHaveBeenCalledWith(
349382"Telegram rejected 10 commands (BOT_COMMANDS_TOO_MUCH); retrying with 8.",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。