惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
J
Java Code Geeks
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
U
Unit 42
B
Blog
宝玉的分享
宝玉的分享
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
博客园 - Franky
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
博客园 - 叶小钗

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test(telegram): cover message context perf guards · openc...
vincentkoc · 2026-05-07 · via Recent Commits to openclaw:main

@@ -0,0 +1,146 @@

1+

import { beforeEach, describe, expect, it, vi } from "vitest";

2+

import type { BuildTelegramMessageContextParams } from "./bot-message-context.types.js";

3+4+

const inboundBodyMock = vi.hoisted(() =>

5+

vi.fn(async () => ({

6+

bodyText: "hello",

7+

rawBody: "hello",

8+

historyKey: undefined,

9+

commandAuthorized: false,

10+

effectiveWasMentioned: false,

11+

canDetectMention: true,

12+

shouldBypassMention: false,

13+

stickerCacheHit: false,

14+

locationData: undefined,

15+

})),

16+

);

17+18+

vi.mock("./bot-message-context.body.js", () => ({

19+

resolveTelegramInboundBody: (...args: unknown[]) => inboundBodyMock(...args),

20+

}));

21+22+

const { buildTelegramMessageContextForTest } =

23+

await import("./bot-message-context.test-harness.js");

24+25+

type CreateStatusReactionController = NonNullable<

26+

NonNullable<BuildTelegramMessageContextParams["runtime"]>["createStatusReactionController"]

27+

>;

28+

type StatusReactionControllerParams = Parameters<CreateStatusReactionController>[0];

29+30+

function createStatusReactionControllerStub() {

31+

const controller = {

32+

setQueued: vi.fn(async () => undefined),

33+

setThinking: vi.fn(async () => undefined),

34+

setTool: vi.fn(async () => undefined),

35+

setCompacting: vi.fn(async () => undefined),

36+

cancelPending: vi.fn(),

37+

setDone: vi.fn(async () => undefined),

38+

setError: vi.fn(async () => undefined),

39+

clear: vi.fn(async () => undefined),

40+

restoreInitial: vi.fn(async () => undefined),

41+

};

42+

const createStatusReactionController = vi.fn((params: StatusReactionControllerParams) => {

43+

return controller;

44+

});

45+

return { controller, createStatusReactionController };

46+

}

47+48+

describe("buildTelegramMessageContext reactions", () => {

49+

beforeEach(() => {

50+

inboundBodyMock.mockClear();

51+

});

52+53+

it("does not create status reactions when the ack gate blocks an unmentioned group message", async () => {

54+

const setMessageReaction = vi.fn(async () => undefined);

55+

const { createStatusReactionController } = createStatusReactionControllerStub();

56+57+

const ctx = await buildTelegramMessageContextForTest({

58+

message: {

59+

message_id: 12,

60+

chat: { id: -1001234567890, type: "group", title: "Ops" },

61+

date: 1_700_000_000,

62+

text: "hello",

63+

from: { id: 42, first_name: "Alice" },

64+

},

65+

cfg: {

66+

agents: {

67+

defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" },

68+

},

69+

channels: {

70+

telegram: {

71+

groupPolicy: "open",

72+

groups: { "*": { requireMention: true } },

73+

},

74+

},

75+

messages: {

76+

ackReaction: "👀",

77+

groupChat: { mentionPatterns: [] },

78+

statusReactions: { enabled: true },

79+

},

80+

},

81+

ackReactionScope: "group-mentions",

82+

botApi: { setMessageReaction },

83+

runtime: { createStatusReactionController },

84+

resolveGroupActivation: () => true,

85+

resolveGroupRequireMention: () => true,

86+

resolveTelegramGroupConfig: () => ({

87+

groupConfig: { requireMention: true },

88+

topicConfig: undefined,

89+

}),

90+

});

91+92+

expect(ctx).not.toBeNull();

93+

expect(ctx?.ackReactionPromise).toBeNull();

94+

expect(ctx?.statusReactionController).toBeNull();

95+

expect(createStatusReactionController).not.toHaveBeenCalled();

96+

expect(setMessageReaction).not.toHaveBeenCalled();

97+

});

98+99+

it("keeps Telegram status reaction variants available for configured emoji fallbacks", async () => {

100+

const setMessageReaction = vi.fn(async () => undefined);

101+

const { controller, createStatusReactionController } = createStatusReactionControllerStub();

102+103+

const ctx = await buildTelegramMessageContextForTest({

104+

message: {

105+

message_id: 34,

106+

chat: {

107+

id: 1234,

108+

type: "private",

109+

available_reactions: [{ type: "emoji", emoji: "👍" }],

110+

},

111+

date: 1_700_000_000,

112+

text: "hello",

113+

from: { id: 42, first_name: "Alice" },

114+

},

115+

cfg: {

116+

agents: {

117+

defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" },

118+

},

119+

channels: { telegram: { dmPolicy: "open", allowFrom: ["*"] } },

120+

messages: {

121+

ackReaction: "👀",

122+

groupChat: { mentionPatterns: [] },

123+

statusReactions: {

124+

enabled: true,

125+

emojis: { done: "✅" },

126+

},

127+

},

128+

},

129+

ackReactionScope: "direct",

130+

botApi: { setMessageReaction },

131+

runtime: { createStatusReactionController },

132+

});

133+134+

await expect(ctx?.ackReactionPromise).resolves.toBe(true);

135+

expect(controller.setQueued).toHaveBeenCalledTimes(1);

136+

expect(createStatusReactionController).toHaveBeenCalledTimes(1);

137+138+

const params = createStatusReactionController.mock.calls[0]?.[0];

139+

expect(params?.initialEmoji).toBe("👀");

140+

expect(params?.emojis?.done).toBe("✅");

141+142+

await params?.adapter.setReaction("✅");

143+144+

expect(setMessageReaction).toHaveBeenCalledWith(1234, 34, [{ type: "emoji", emoji: "👍" }]);

145+

});

146+

});