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

推荐订阅源

G
Google Developers Blog
D
Docker
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
H
Help Net Security
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
MongoDB | Blog
MongoDB | Blog
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
博客园 - 司徒正美
C
Check Point Blog
B
Blog
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
F
Fortinet All Blogs
美团技术团队
D
DataBreaches.Net

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
refactor(discord): distill reply hydration tests · opencl...
obviyus · 2026-06-10 · via Recent Commits to openclaw:main
1-

// Discord tests cover message handler.hydration plugin behavior.

21

import { MessageReferenceType, MessageType } from "discord-api-types/v10";

32

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

43

import { Message } from "../internal/discord.js";

@@ -8,13 +7,65 @@ import {

87

} from "../internal/test-builders.test-support.js";

98

import { hydrateDiscordMessageIfNeeded } from "./message-handler.hydration.js";

10910+

const TEST_TIMESTAMP = "2026-01-01T00:00:00.000Z";

11+12+

function createMessagePayload(overrides = {}) {

13+

return {

14+

id: "m1",

15+

channel_id: "c1",

16+

content: "what did this mean?",

17+

attachments: [],

18+

embeds: [],

19+

mentions: [],

20+

mention_roles: [],

21+

mention_everyone: false,

22+

timestamp: TEST_TIMESTAMP,

23+

edited_timestamp: null,

24+

author: {

25+

id: "u1",

26+

username: "alice",

27+

global_name: null,

28+

discriminator: "0",

29+

avatar: null,

30+

},

31+

type: MessageType.Default,

32+

tts: false,

33+

pinned: false,

34+

flags: 0,

35+

...overrides,

36+

};

37+

}

38+39+

function createDefaultReplyPayload(overrides = {}) {

40+

return createMessagePayload({

41+

message_reference: {

42+

type: MessageReferenceType.Default,

43+

message_id: "m0",

44+

channel_id: "c1",

45+

},

46+

type: MessageType.Reply,

47+

...overrides,

48+

});

49+

}

50+51+

function createReferencedMessagePayload(content: string) {

52+

return createMessagePayload({

53+

id: "m0",

54+

content,

55+

author: {

56+

id: "u2",

57+

username: "bob",

58+

discriminator: "0",

59+

avatar: null,

60+

},

61+

});

62+

}

63+1164

describe("hydrateDiscordMessageIfNeeded", () => {

1265

it("hydrates partial internal messages without assigning over getters", async () => {

1366

const client = createInternalTestClient();

1467

const rest = createFakeRestClient([

15-

{

16-

id: "m1",

17-

channel_id: "c1",

68+

createMessagePayload({

1869

content: "hello <@u2>",

1970

attachments: [{ id: "a1", filename: "note.txt" }],

2071

embeds: [{ title: "Embed" }],

@@ -29,39 +80,17 @@ describe("hydrateDiscordMessageIfNeeded", () => {

2980

],

3081

mention_roles: ["role1"],

3182

mention_everyone: false,

32-

timestamp: new Date().toISOString(),

33-

author: {

34-

id: "u1",

35-

username: "alice",

36-

discriminator: "0",

37-

avatar: null,

38-

},

39-

referenced_message: {

83+

referenced_message: createMessagePayload({

4084

id: "m0",

41-

channel_id: "c1",

4285

content: "earlier",

43-

attachments: [],

44-

embeds: [],

45-

mentions: [],

46-

mention_roles: [],

47-

mention_everyone: false,

48-

timestamp: new Date().toISOString(),

4986

author: {

5087

id: "u3",

5188

username: "carol",

5289

discriminator: "0",

5390

avatar: null,

5491

},

55-

type: 0,

56-

tts: false,

57-

pinned: false,

58-

flags: 0,

59-

},

60-

type: 0,

61-

tts: false,

62-

pinned: false,

63-

flags: 0,

64-

},

92+

}),

93+

}),

6594

]);

6695

const message = new Message<true>(client, { id: "m1", channelId: "c1" }) as unknown as Message;

6796

@@ -83,80 +112,11 @@ describe("hydrateDiscordMessageIfNeeded", () => {

83112

it("hydrates reply references when Discord omits referenced_message", async () => {

84113

const client = createInternalTestClient();

85114

const rest = createFakeRestClient([

86-

{

87-

id: "m1",

88-

channel_id: "c1",

89-

content: "what did this mean?",

90-

attachments: [],

91-

embeds: [],

92-

mentions: [],

93-

mention_roles: [],

94-

mention_everyone: false,

95-

timestamp: new Date().toISOString(),

96-

author: {

97-

id: "u1",

98-

username: "alice",

99-

discriminator: "0",

100-

avatar: null,

101-

},

102-

message_reference: {

103-

type: MessageReferenceType.Default,

104-

message_id: "m0",

105-

channel_id: "c1",

106-

},

107-

referenced_message: {

108-

id: "m0",

109-

channel_id: "c1",

110-

content: "the replied-to message",

111-

attachments: [],

112-

embeds: [],

113-

mentions: [],

114-

mention_roles: [],

115-

mention_everyone: false,

116-

timestamp: new Date().toISOString(),

117-

author: {

118-

id: "u2",

119-

username: "bob",

120-

discriminator: "0",

121-

avatar: null,

122-

},

123-

type: MessageType.Default,

124-

tts: false,

125-

pinned: false,

126-

flags: 0,

127-

},

128-

type: MessageType.Reply,

129-

tts: false,

130-

pinned: false,

131-

flags: 0,

132-

},

115+

createDefaultReplyPayload({

116+

referenced_message: createReferencedMessagePayload("the replied-to message"),

117+

}),

133118

]);

134-

const message = new Message(client, {

135-

id: "m1",

136-

channel_id: "c1",

137-

content: "what did this mean?",

138-

attachments: [],

139-

embeds: [],

140-

mentions: [],

141-

mention_roles: [],

142-

mention_everyone: false,

143-

timestamp: new Date().toISOString(),

144-

author: {

145-

id: "u1",

146-

username: "alice",

147-

global_name: null,

148-

discriminator: "0",

149-

avatar: null,

150-

},

151-

message_reference: {

152-

type: MessageReferenceType.Default,

153-

message_id: "m0",

154-

channel_id: "c1",

155-

},

156-

type: MessageType.Reply,

157-

tts: false,

158-

pinned: false,

159-

});

119+

const message = new Message(client, createDefaultReplyPayload());

160120161121

const hydrated = await hydrateDiscordMessageIfNeeded({

162122

client: { rest },

@@ -175,32 +135,7 @@ describe("hydrateDiscordMessageIfNeeded", () => {

175135

throw Object.assign(new Error("Missing Access"), { status: 403 });

176136

});

177137

rest.get = get;

178-

const message = new Message(client, {

179-

id: "m1",

180-

channel_id: "c1",

181-

content: "what did this mean?",

182-

attachments: [],

183-

embeds: [],

184-

mentions: [],

185-

mention_roles: [],

186-

mention_everyone: false,

187-

timestamp: new Date().toISOString(),

188-

author: {

189-

id: "u1",

190-

username: "alice",

191-

global_name: null,

192-

discriminator: "0",

193-

avatar: null,

194-

},

195-

message_reference: {

196-

type: MessageReferenceType.Default,

197-

message_id: "m0",

198-

channel_id: "c1",

199-

},

200-

type: MessageType.Reply,

201-

tts: false,

202-

pinned: false,

203-

});

138+

const message = new Message(client, createDefaultReplyPayload());

204139205140

const hydrated = await hydrateDiscordMessageIfNeeded({

206141

client: { rest },

@@ -216,46 +151,22 @@ describe("hydrateDiscordMessageIfNeeded", () => {

216151

it("does not hydrate known-deleted or forwarded references", async () => {

217152

const client = createInternalTestClient();

218153

const rest = createFakeRestClient();

219-

const baseMessage = {

220-

id: "m1",

221-

channel_id: "c1",

222-

content: "what did this mean?",

223-

attachments: [],

224-

embeds: [],

225-

mentions: [],

226-

mention_roles: [],

227-

mention_everyone: false,

228-

timestamp: new Date().toISOString(),

229-

author: {

230-

id: "u1",

231-

username: "alice",

232-

global_name: null,

233-

discriminator: "0",

234-

avatar: null,

235-

},

236-

tts: false,

237-

pinned: false,

238-

};

239-240-

const deletedReply = new Message(client, {

241-

...baseMessage,

242-

message_reference: {

243-

type: MessageReferenceType.Default,

244-

message_id: "m0",

245-

channel_id: "c1",

246-

},

247-

referenced_message: null,

248-

type: MessageType.Reply,

249-

});

250-

const forwardedMessage = new Message(client, {

251-

...baseMessage,

252-

message_reference: {

253-

type: MessageReferenceType.Forward,

254-

message_id: "m0",

255-

channel_id: "c1",

256-

},

257-

type: MessageType.Default,

258-

});

154+

const deletedReply = new Message(

155+

client,

156+

createDefaultReplyPayload({

157+

referenced_message: null,

158+

}),

159+

);

160+

const forwardedMessage = new Message(

161+

client,

162+

createMessagePayload({

163+

message_reference: {

164+

type: MessageReferenceType.Forward,

165+

message_id: "m0",

166+

channel_id: "c1",

167+

},

168+

}),

169+

);

259170260171

await hydrateDiscordMessageIfNeeded({

261172

client: { rest },