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

推荐订阅源

博客园_首页
H
Help Net Security
量子位
The Cloudflare Blog
博客园 - Franky
博客园 - 聂微东
博客园 - 司徒正美
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
罗磊的独立博客
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
MongoDB | Blog
MongoDB | 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(discord): restore voice note audio preflight · opencl...
steipete · 2026-04-25 · via Recent Commits to openclaw:main

@@ -0,0 +1,127 @@

1+

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

2+3+

const transcribeFirstAudioMock = vi.hoisted(() => vi.fn());

4+5+

vi.mock("./preflight-audio.runtime.js", () => ({

6+

transcribeFirstAudio: transcribeFirstAudioMock,

7+

}));

8+9+

import { resolveDiscordPreflightAudioMentionContext } from "./preflight-audio.js";

10+11+

const cfg = {} as import("openclaw/plugin-sdk/config-runtime").OpenClawConfig;

12+13+

describe("resolveDiscordPreflightAudioMentionContext", () => {

14+

beforeEach(() => {

15+

transcribeFirstAudioMock.mockReset();

16+

});

17+18+

it("preflights direct-message audio without requiring a mention", async () => {

19+

transcribeFirstAudioMock.mockResolvedValue("hello from dm");

20+21+

const result = await resolveDiscordPreflightAudioMentionContext({

22+

message: {

23+

attachments: [

24+

{

25+

url: "https://cdn.discordapp.com/attachments/voice.ogg",

26+

content_type: "audio/ogg",

27+

filename: "voice.ogg",

28+

},

29+

],

30+

},

31+

isDirectMessage: true,

32+

shouldRequireMention: false,

33+

mentionRegexes: [],

34+

cfg,

35+

});

36+37+

expect(transcribeFirstAudioMock).toHaveBeenCalledWith(

38+

expect.objectContaining({

39+

ctx: expect.objectContaining({

40+

MediaUrls: ["https://cdn.discordapp.com/attachments/voice.ogg"],

41+

MediaTypes: ["audio/ogg"],

42+

}),

43+

}),

44+

);

45+

expect(result).toEqual({

46+

hasAudioAttachment: true,

47+

hasTypedText: false,

48+

transcript: "hello from dm",

49+

});

50+

});

51+52+

it("preflights audio by filename when Discord omits content type", async () => {

53+

transcribeFirstAudioMock.mockResolvedValue("filename transcript");

54+55+

await resolveDiscordPreflightAudioMentionContext({

56+

message: {

57+

attachments: [

58+

{

59+

url: "https://cdn.discordapp.com/attachments/voice.opus",

60+

filename: "voice.opus",

61+

},

62+

],

63+

},

64+

isDirectMessage: true,

65+

shouldRequireMention: false,

66+

mentionRegexes: [],

67+

cfg,

68+

});

69+70+

expect(transcribeFirstAudioMock).toHaveBeenCalledWith(

71+

expect.objectContaining({

72+

ctx: expect.objectContaining({

73+

MediaUrls: ["https://cdn.discordapp.com/attachments/voice.opus"],

74+

MediaTypes: ["audio/opus"],

75+

}),

76+

}),

77+

);

78+

});

79+80+

it("does not preflight typed direct-message audio", async () => {

81+

const result = await resolveDiscordPreflightAudioMentionContext({

82+

message: {

83+

content: "typed caption",

84+

attachments: [

85+

{

86+

url: "https://cdn.discordapp.com/attachments/voice.ogg",

87+

content_type: "audio/ogg",

88+

filename: "voice.ogg",

89+

},

90+

],

91+

},

92+

isDirectMessage: true,

93+

shouldRequireMention: false,

94+

mentionRegexes: [],

95+

cfg,

96+

});

97+98+

expect(transcribeFirstAudioMock).not.toHaveBeenCalled();

99+

expect(result).toEqual({

100+

hasAudioAttachment: true,

101+

hasTypedText: true,

102+

});

103+

});

104+105+

it("ignores URL-less audio attachments", async () => {

106+

const result = await resolveDiscordPreflightAudioMentionContext({

107+

message: {

108+

attachments: [

109+

{

110+

content_type: "audio/ogg",

111+

filename: "voice.ogg",

112+

},

113+

],

114+

},

115+

isDirectMessage: true,

116+

shouldRequireMention: false,

117+

mentionRegexes: [],

118+

cfg,

119+

});

120+121+

expect(transcribeFirstAudioMock).not.toHaveBeenCalled();

122+

expect(result).toEqual({

123+

hasAudioAttachment: false,

124+

hasTypedText: false,

125+

});

126+

});

127+

});