






















@@ -20,14 +20,19 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
2020tmpDir = undefined;
2121});
222223-it("exposes a local audio file as a media-ticketed attachment when it is under localRoots", async () => {
23+function writeAudioFixture(bytes = [0xff, 0xfb, 0x90, 0x00]) {
2424tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
2525const audioPath = path.join(tmpDir, "clip.mp3");
26-fs.writeFileSync(audioPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
26+fs.writeFileSync(audioPath, Buffer.from(bytes));
27+return { audioPath, localRoot: tmpDir };
28+}
29+30+it("exposes a local audio file as a media-ticketed attachment when it is under localRoots", async () => {
31+const { audioPath, localRoot } = writeAudioFixture();
27322833const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
2934[{ mediaUrl: audioPath, trustedLocalMedia: true }],
30-{ localRoots: [tmpDir] },
35+{ localRoots: [localRoot] },
3136);
32373338expect(blocks).toHaveLength(1);
@@ -45,13 +50,11 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
4550});
46514752it("preserves voice-note metadata on local audio attachments", async () => {
48-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
49-const audioPath = path.join(tmpDir, "clip.mp3");
50-fs.writeFileSync(audioPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
53+const { audioPath, localRoot } = writeAudioFixture();
51545255const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
5356[{ mediaUrl: audioPath, trustedLocalMedia: true, audioAsVoice: true }],
54-{ localRoots: [tmpDir] },
57+{ localRoots: [localRoot] },
5558);
56595760expect(blocks).toHaveLength(1);
@@ -64,9 +67,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
6467});
65686669it("suppresses reasoning payload audio", async () => {
67-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
68-const audioPath = path.join(tmpDir, "clip.mp3");
69-fs.writeFileSync(audioPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
70+const { audioPath, localRoot } = writeAudioFixture();
70717172const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
7273[
@@ -77,7 +78,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
7778isReasoning: true,
7879},
7980],
80-{ localRoots: [tmpDir] },
81+{ localRoots: [localRoot] },
8182);
82838384expect(blocks).toHaveLength(0);
@@ -104,30 +105,26 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
104105});
105106106107it("dedupes repeated paths", async () => {
107-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
108-const audioPath = path.join(tmpDir, "clip.mp3");
109-fs.writeFileSync(audioPath, Buffer.from([0x00]));
108+const { audioPath, localRoot } = writeAudioFixture([0x00]);
110109111110const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
112111[
113112{ mediaUrl: audioPath, trustedLocalMedia: true },
114113{ mediaUrl: audioPath, trustedLocalMedia: true },
115114],
116-{ localRoots: [tmpDir] },
115+{ localRoots: [localRoot] },
117116);
118117expect(blocks).toHaveLength(1);
119118});
120119121120it("embeds file:// URLs pointing at a local file within localRoots", async () => {
122-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
123-const audioPath = path.join(tmpDir, "clip.mp3");
124-fs.writeFileSync(audioPath, Buffer.from([0x01]));
121+const { audioPath, localRoot } = writeAudioFixture([0x01]);
125122126123const fileUrl = pathToFileURL(audioPath).href;
127124const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
128125[{ mediaUrl: fileUrl, trustedLocalMedia: true }],
129126{
130-localRoots: [tmpDir],
127+localRoots: [localRoot],
131128},
132129);
133130@@ -194,27 +191,23 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
194191});
195192196193it("skips local audio when the opened file stat is over the cap", async () => {
197-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
198-const audioPath = path.join(tmpDir, "huge.mp3");
199-fs.writeFileSync(audioPath, Buffer.from([0x02]));
194+const { audioPath, localRoot } = writeAudioFixture([0x02]);
200195fs.truncateSync(audioPath, 16 * 1024 * 1024);
201196202197const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
203198[{ mediaUrl: audioPath, trustedLocalMedia: true }],
204-{ localRoots: [tmpDir] },
199+{ localRoots: [localRoot] },
205200);
206201207202expect(blocks).toHaveLength(0);
208203});
209204210205it("rejects untrusted local audio paths", async () => {
211-tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-webchat-audio-"));
212-const audioPath = path.join(tmpDir, "clip.mp3");
213-fs.writeFileSync(audioPath, Buffer.from([0xff, 0xfb, 0x90, 0x00]));
206+const { audioPath, localRoot } = writeAudioFixture();
214207215208const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads(
216209[{ mediaUrl: audioPath }],
217-{ localRoots: [tmpDir] },
210+{ localRoots: [localRoot] },
218211);
219212220213expect(blocks).toHaveLength(0);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。