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

推荐订阅源

The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
博客园 - 司徒正美
Last Week in AI
Last Week in AI
爱范儿
爱范儿
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
量子位
V
V2EX
博客园 - 叶小钗
宝玉的分享
宝玉的分享
T
Tailwind CSS 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
fix(whatsapp): setting systemPrompt to "" suppresses the ...
Bluetegu · 2026-04-25 · via Recent Commits to openclaw:main

@@ -0,0 +1,221 @@

1+

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

2+3+

// Hoisted mocks used across tests so vi.mock factories can reference them.

4+

const { resolvePolicyMock, buildContextMock } = vi.hoisted(() => ({

5+

resolvePolicyMock: vi.fn(),

6+

buildContextMock: vi.fn(),

7+

}));

8+9+

vi.mock("../../inbound-policy.js", async (importOriginal) => {

10+

const actual = await importOriginal<typeof import("../../inbound-policy.js")>();

11+

return {

12+

...actual,

13+

resolveWhatsAppCommandAuthorized: async () => true,

14+

resolveWhatsAppInboundPolicy: resolvePolicyMock,

15+

};

16+

});

17+18+

vi.mock("./inbound-dispatch.js", async (importOriginal) => {

19+

const actual = await importOriginal<typeof import("./inbound-dispatch.js")>();

20+

return {

21+

...actual,

22+

buildWhatsAppInboundContext: buildContextMock,

23+

dispatchWhatsAppBufferedReply: async () => ({

24+

queuedFinal: false,

25+

counts: { tool: 0, block: 0, final: 0 },

26+

}),

27+

resolveWhatsAppDmRouteTarget: () => null,

28+

resolveWhatsAppResponsePrefix: () => undefined,

29+

updateWhatsAppMainLastRoute: () => {},

30+

};

31+

});

32+33+

vi.mock("../../identity.js", async (importOriginal) => {

34+

const actual = await importOriginal<typeof import("../../identity.js")>();

35+

return {

36+

...actual,

37+

getPrimaryIdentityId: () => null,

38+

getSelfIdentity: () => ({ e164: "+15550001111" }),

39+

getSenderIdentity: () => ({ name: "Alice", e164: "+15550002222" }),

40+

};

41+

});

42+43+

vi.mock("../../reconnect.js", async (importOriginal) => {

44+

const actual = await importOriginal<typeof import("../../reconnect.js")>();

45+

return { ...actual, newConnectionId: () => "test-conn-id" };

46+

});

47+48+

vi.mock("../../session.js", async (importOriginal) => {

49+

const actual = await importOriginal<typeof import("../../session.js")>();

50+

return { ...actual, formatError: (e: unknown) => String(e) };

51+

});

52+53+

vi.mock("../deliver-reply.js", async (importOriginal) => {

54+

const actual = await importOriginal<typeof import("../deliver-reply.js")>();

55+

return { ...actual, deliverWebReply: async () => {} };

56+

});

57+58+

vi.mock("../loggers.js", async (importOriginal) => {

59+

const actual = await importOriginal<typeof import("../loggers.js")>();

60+

return {

61+

...actual,

62+

whatsappInboundLog: { info: () => {}, debug: () => {} },

63+

};

64+

});

65+66+

vi.mock("./ack-reaction.js", async (importOriginal) => {

67+

const actual = await importOriginal<typeof import("./ack-reaction.js")>();

68+

return { ...actual, maybeSendAckReaction: async () => {} };

69+

});

70+71+

vi.mock("./inbound-context.js", async (importOriginal) => {

72+

const actual = await importOriginal<typeof import("./inbound-context.js")>();

73+

return {

74+

...actual,

75+

resolveVisibleWhatsAppGroupHistory: () => [],

76+

resolveVisibleWhatsAppReplyContext: () => null,

77+

};

78+

});

79+80+

vi.mock("./last-route.js", async (importOriginal) => {

81+

const actual = await importOriginal<typeof import("./last-route.js")>();

82+

return {

83+

...actual,

84+

trackBackgroundTask: () => {},

85+

updateLastRouteInBackground: () => {},

86+

};

87+

});

88+89+

vi.mock("./message-line.js", async (importOriginal) => {

90+

const actual = await importOriginal<typeof import("./message-line.js")>();

91+

return { ...actual, buildInboundLine: () => "hi" };

92+

});

93+94+

vi.mock("./runtime-api.js", async (importOriginal) => {

95+

const actual = await importOriginal<typeof import("./runtime-api.js")>();

96+

return {

97+

...actual,

98+

buildHistoryContextFromEntries: () => "hi",

99+

createChannelReplyPipeline: () => ({ onModelSelected: () => {}, responsePrefix: undefined }),

100+

formatInboundEnvelope: () => "hi",

101+

logVerbose: () => {},

102+

normalizeE164: (v: string) => v,

103+

recordSessionMetaFromInbound: async () => {},

104+

resolveChannelContextVisibilityMode: () => "off",

105+

resolveInboundSessionEnvelopeContext: () => ({

106+

storePath: "/tmp",

107+

envelopeOptions: {},

108+

previousTimestamp: undefined,

109+

}),

110+

resolvePinnedMainDmOwnerFromAllowlist: () => null,

111+

shouldComputeCommandAuthorized: () => false,

112+

shouldLogVerbose: () => false,

113+

};

114+

});

115+116+

import { processMessage } from "./process-message.js";

117+118+

// ---------------------------------------------------------------------------

119+

// Helpers

120+

// ---------------------------------------------------------------------------

121+122+

function makeAccount(groups: Record<string, { systemPrompt?: string }> = {}): {

123+

accountId: string;

124+

authDir: string;

125+

groups: Record<string, { systemPrompt?: string }>;

126+

} {

127+

return { accountId: "default", authDir: "/tmp/wa-test-auth", groups };

128+

}

129+130+

function makePolicy(account: ReturnType<typeof makeAccount>) {

131+

return {

132+

account,

133+

dmPolicy: "pairing",

134+

groupPolicy: "allowlist",

135+

configuredAllowFrom: [],

136+

dmAllowFrom: [],

137+

groupAllowFrom: [],

138+

isSelfChat: false,

139+

providerMissingFallbackApplied: false,

140+

shouldReadStorePairingApprovals: true,

141+

isSamePhone: () => false,

142+

isDmSenderAllowed: () => false,

143+

isGroupSenderAllowed: () => false,

144+

resolveConversationGroupPolicy: () => "allowlist",

145+

resolveConversationRequireMention: () => false,

146+

};

147+

}

148+149+

const GROUP_JID = "123@g.us";

150+151+

const baseMsg = {

152+

id: "msg1",

153+

from: GROUP_JID,

154+

to: "+15550001111",

155+

conversationId: GROUP_JID,

156+

accountId: "default",

157+

chatId: GROUP_JID,

158+

chatType: "group" as const,

159+

body: "hi",

160+

sendComposing: async () => {},

161+

reply: async () => {},

162+

sendMedia: async () => {},

163+

};

164+165+

const baseRoute = {

166+

agentId: "main",

167+

channel: "whatsapp",

168+

accountId: "default",

169+

sessionKey: "agent:main:whatsapp:group:123@g.us",

170+

mainSessionKey: "agent:main:whatsapp:group:123@g.us",

171+

lastRoutePolicy: "main",

172+

matchedBy: "default",

173+

};

174+175+

function callProcessMessage() {

176+

return processMessage({

177+

cfg: {} as never,

178+

msg: baseMsg as never,

179+

route: baseRoute as never,

180+

groupHistoryKey: "whatsapp:default:group:123@g.us",

181+

groupHistories: new Map(),

182+

groupMemberNames: new Map(),

183+

connectionId: "conn-1",

184+

verbose: false,

185+

maxMediaBytes: 1024,

186+

replyResolver: (async () => undefined) as never,

187+

replyLogger: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,

188+

backgroundTasks: new Set(),

189+

rememberSentText: () => {},

190+

echoHas: () => false,

191+

echoForget: () => {},

192+

buildCombinedEchoKey: ({ sessionKey }) => sessionKey,

193+

});

194+

}

195+196+

// ---------------------------------------------------------------------------

197+

// Tests

198+

// ---------------------------------------------------------------------------

199+200+

describe("processMessage group system prompt wiring", () => {

201+

beforeEach(() => {

202+

buildContextMock.mockReset();

203+

resolvePolicyMock.mockReset();

204+

buildContextMock.mockImplementation(

205+

(params: { groupSystemPrompt?: string; combinedBody?: string }) => ({

206+

GroupSystemPrompt: params.groupSystemPrompt,

207+

Body: params.combinedBody ?? "",

208+

}),

209+

);

210+

});

211+212+

it("resolves group systemPrompt from account config and passes it into buildWhatsAppInboundContext", async () => {

213+

resolvePolicyMock.mockReturnValue(

214+

makePolicy(makeAccount({ [GROUP_JID]: { systemPrompt: "from config" } })),

215+

);

216+217+

await callProcessMessage();

218+219+

expect(buildContextMock.mock.calls[0][0].groupSystemPrompt).toBe("from config");

220+

});

221+

});