@@ -7,11 +7,16 @@ import path from "node:path";
77import { pathToFileURL } from "node:url" ;
88import { afterEach , describe , expect , it , vi } from "vitest" ;
99import { getDefaultLocalRoots } from "../../media/local-media-access.js" ;
10- import { __testing , buildWebchatAssistantMessageFromReplyPayloads } from "./chat-webchat-media.js" ;
10+ import { buildWebchatAssistantMessageFromReplyPayloads } from "./chat-webchat-media.js" ;
1111
12- const { buildWebchatAudioContentBlocksFromReplyPayloads } = __testing ;
12+ async function buildWebchatAudioBlocks (
13+ ...args : Parameters < typeof buildWebchatAssistantMessageFromReplyPayloads >
14+ ) : Promise < Array < Record < string , unknown > > > {
15+ const message = await buildWebchatAssistantMessageFromReplyPayloads ( ...args ) ;
16+ return message ?. content . filter ( ( block ) => block . type === "attachment" ) ?? [ ] ;
17+ }
1318
14- describe ( "buildWebchatAudioContentBlocksFromReplyPayloads " , ( ) => {
19+ describe ( "webchat audio blocks through assistant messages " , ( ) => {
1520 let tmpDir : string | undefined ;
1621
1722 afterEach ( ( ) => {
@@ -31,7 +36,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
3136 it ( "exposes a local audio file as a media-ticketed attachment when it is under localRoots" , async ( ) => {
3237 const { audioPath, localRoot } = writeAudioFixture ( ) ;
3338
34- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
39+ const blocks = await buildWebchatAudioBlocks (
3540 [ { mediaUrl : audioPath , trustedLocalMedia : true } ] ,
3641 { localRoots : [ localRoot ] } ,
3742 ) ;
@@ -53,7 +58,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
5358 it ( "exposes MPEG-2 audio files with their canonical MIME type" , async ( ) => {
5459 const { audioPath, localRoot } = writeAudioFixture ( [ 0xff , 0xfd , 0x80 , 0x00 ] , ".m2a" ) ;
5560
56- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
61+ const blocks = await buildWebchatAudioBlocks (
5762 [ { mediaUrl : audioPath , trustedLocalMedia : true } ] ,
5863 { localRoots : [ localRoot ] } ,
5964 ) ;
@@ -75,7 +80,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
7580 extension ,
7681 ) ;
7782
78- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
83+ const blocks = await buildWebchatAudioBlocks (
7984 [ { mediaUrl : audioPath , trustedLocalMedia : true } ] ,
8085 { localRoots : [ localRoot ] } ,
8186 ) ;
@@ -89,7 +94,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
8994 it ( "preserves voice-note metadata on local audio attachments" , async ( ) => {
9095 const { audioPath, localRoot } = writeAudioFixture ( ) ;
9196
92- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
97+ const blocks = await buildWebchatAudioBlocks (
9398 [ { mediaUrl : audioPath , trustedLocalMedia : true , audioAsVoice : true } ] ,
9499 { localRoots : [ localRoot ] } ,
95100 ) ;
@@ -106,7 +111,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
106111 it ( "suppresses reasoning payload audio" , async ( ) => {
107112 const { audioPath, localRoot } = writeAudioFixture ( ) ;
108113
109- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
114+ const blocks = await buildWebchatAudioBlocks (
110115 [
111116 {
112117 text : "step" ,
@@ -122,7 +127,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
122127 } ) ;
123128
124129 it ( "skips remote URLs" , async ( ) => {
125- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads ( [
130+ const blocks = await buildWebchatAudioBlocks ( [
126131 { mediaUrl : "https://example.com/a.mp3" , trustedLocalMedia : true } ,
127132 ] ) ;
128133 expect ( blocks ) . toHaveLength ( 0 ) ;
@@ -133,7 +138,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
133138 const imagePath = path . join ( tmpDir , "clip.png" ) ;
134139 fs . writeFileSync ( imagePath , Buffer . from ( [ 0x89 , 0x50 , 0x4e , 0x47 ] ) ) ;
135140
136- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
141+ const blocks = await buildWebchatAudioBlocks (
137142 [ { mediaUrl : imagePath , trustedLocalMedia : true } ] ,
138143 { localRoots : [ tmpDir ] } ,
139144 ) ;
@@ -144,7 +149,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
144149 it ( "dedupes repeated paths" , async ( ) => {
145150 const { audioPath, localRoot } = writeAudioFixture ( [ 0x00 ] ) ;
146151
147- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
152+ const blocks = await buildWebchatAudioBlocks (
148153 [
149154 { mediaUrl : audioPath , trustedLocalMedia : true } ,
150155 { mediaUrl : audioPath , trustedLocalMedia : true } ,
@@ -158,12 +163,9 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
158163 const { audioPath, localRoot } = writeAudioFixture ( [ 0x01 ] ) ;
159164
160165 const fileUrl = pathToFileURL ( audioPath ) . href ;
161- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
162- [ { mediaUrl : fileUrl , trustedLocalMedia : true } ] ,
163- {
164- localRoots : [ localRoot ] ,
165- } ,
166- ) ;
166+ const blocks = await buildWebchatAudioBlocks ( [ { mediaUrl : fileUrl , trustedLocalMedia : true } ] , {
167+ localRoots : [ localRoot ] ,
168+ } ) ;
167169
168170 expect ( blocks ) . toHaveLength ( 1 ) ;
169171 expect ( ( blocks [ 0 ] as { type ?: string } ) . type ) . toBe ( "attachment" ) ;
@@ -172,7 +174,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
172174 it ( "drops tool-result file:// URLs with remote hosts before touching the filesystem" , async ( ) => {
173175 const openSpy = vi . spyOn ( fsPromises , "open" ) ;
174176
175- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads ( [
177+ const blocks = await buildWebchatAudioBlocks ( [
176178 {
177179 text : "MEDIA:file://attacker/share/probe.mp3" ,
178180 mediaUrl : "file://attacker/share/probe.mp3" ,
@@ -196,7 +198,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
196198 fs . writeFileSync ( audioPath , Buffer . from ( [ 0x03 ] ) ) ;
197199
198200 const onLocalAudioAccessDenied = vi . fn ( ) ;
199- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
201+ const blocks = await buildWebchatAudioBlocks (
200202 [ { mediaUrl : audioPath , trustedLocalMedia : true } ] ,
201203 {
202204 localRoots : [ allowedRoot ] ,
@@ -219,7 +221,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
219221 const audioPath = path . join ( tmpDir , "clip.mp3" ) ;
220222 fs . writeFileSync ( audioPath , Buffer . from ( [ 0x04 ] ) ) ;
221223
222- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads ( [
224+ const blocks = await buildWebchatAudioBlocks ( [
223225 { mediaUrl : audioPath , trustedLocalMedia : true } ,
224226 ] ) ;
225227
@@ -231,7 +233,7 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
231233 const { audioPath, localRoot } = writeAudioFixture ( [ 0x02 ] ) ;
232234 fs . truncateSync ( audioPath , 16 * 1024 * 1024 ) ;
233235
234- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
236+ const blocks = await buildWebchatAudioBlocks (
235237 [ { mediaUrl : audioPath , trustedLocalMedia : true } ] ,
236238 { localRoots : [ localRoot ] } ,
237239 ) ;
@@ -242,10 +244,9 @@ describe("buildWebchatAudioContentBlocksFromReplyPayloads", () => {
242244 it ( "rejects untrusted local audio paths" , async ( ) => {
243245 const { audioPath, localRoot } = writeAudioFixture ( ) ;
244246
245- const blocks = await buildWebchatAudioContentBlocksFromReplyPayloads (
246- [ { mediaUrl : audioPath } ] ,
247- { localRoots : [ localRoot ] } ,
248- ) ;
247+ const blocks = await buildWebchatAudioBlocks ( [ { mediaUrl : audioPath } ] , {
248+ localRoots : [ localRoot ] ,
249+ } ) ;
249250
250251 expect ( blocks ) . toHaveLength ( 0 ) ;
251252 } ) ;
0 commit comments