@@ -36,7 +36,7 @@ async function freshGenerate() {
3636 return module . heygenVideoGenerate ;
3737}
3838
39- async function listenVideoServer ( ) {
39+ async function listenVideoServer ( t ) {
4040 const server = http . createServer ( ( req , res ) => {
4141 if ( req . url !== "/video.mp4" ) {
4242 res . writeHead ( 404 ) . end ( ) ;
@@ -51,23 +51,33 @@ async function listenVideoServer() {
5151 await new Promise ( ( resolve ) => server . listen ( 0 , resolve ) ) ;
5252 const address = server . address ( ) ;
5353 assert . ok ( address && typeof address !== "string" ) ;
54- return {
55- server,
56- url : `http://127.0.0.1:${ address . port } /video.mp4` ,
57- } ;
54+ // Keep the provider URL public; only the test transport reaches the local fixture.
55+ const url = "https://media.example.com/video.mp4" ;
56+ const originalFetch = globalThis . fetch ;
57+ t . mock . method ( globalThis , "fetch" , ( requested , options ) => {
58+ assert . equal ( requested , url ) ;
59+ assert . equal ( options . redirect , "manual" ) ;
60+ return originalFetch ( `http://127.0.0.1:${ address . port } /video.mp4` , options ) ;
61+ } ) ;
62+ return { server, url } ;
5863}
5964
60- async function listenFailingVideoServer ( ) {
65+ async function listenFailingVideoServer ( t ) {
6166 const server = http . createServer ( ( req , res ) => {
6267 res . writeHead ( 500 ) . end ( ) ;
6368 } ) ;
6469 await new Promise ( ( resolve ) => server . listen ( 0 , resolve ) ) ;
6570 const address = server . address ( ) ;
6671 assert . ok ( address && typeof address !== "string" ) ;
67- return {
68- server,
69- url : `http://127.0.0.1:${ address . port } /video.mp4` ,
70- } ;
72+ // Keep the provider URL public; only the test transport reaches the local fixture.
73+ const url = "https://media.example.com/video.mp4" ;
74+ const originalFetch = globalThis . fetch ;
75+ t . mock . method ( globalThis , "fetch" , ( requested , options ) => {
76+ assert . equal ( requested , url ) ;
77+ assert . equal ( options . redirect , "manual" ) ;
78+ return originalFetch ( `http://127.0.0.1:${ address . port } /video.mp4` , options ) ;
79+ } ) ;
80+ return { server, url } ;
7181}
7282
7383function closeServer ( server ) {
@@ -144,8 +154,8 @@ function bodyFromInvocation(invocation) {
144154 return JSON . parse ( invocation . slice ( start + marker . length ) ) ;
145155}
146156
147- test ( "downloads a generated avatar video and returns the generated MP4 result" , async ( ) => {
148- const { server, url } = await listenVideoServer ( ) ;
157+ test ( "downloads a generated avatar video and returns the generated MP4 result" , async ( t ) => {
158+ const { server, url } = await listenVideoServer ( t ) ;
149159 let localPath ;
150160 try {
151161 await withFakeHeygen (
@@ -191,8 +201,8 @@ test("downloads a generated avatar video and returns the generated MP4 result",
191201 }
192202} ) ;
193203
194- test ( "tags video creation but not avatar or voice discovery" , async ( ) => {
195- const { server, url } = await listenVideoServer ( ) ;
204+ test ( "tags video creation but not avatar or voice discovery" , async ( t ) => {
205+ const { server, url } = await listenVideoServer ( t ) ;
196206 let localPath ;
197207 try {
198208 await withFakeHeygen (
@@ -218,8 +228,8 @@ test("tags video creation but not avatar or voice discovery", async () => {
218228 }
219229} ) ;
220230
221- test ( "uses explicit avatar and voice overrides without discovery" , async ( ) => {
222- const { server, url } = await listenVideoServer ( ) ;
231+ test ( "uses explicit avatar and voice overrides without discovery" , async ( t ) => {
232+ const { server, url } = await listenVideoServer ( t ) ;
223233 let localPath ;
224234 try {
225235 await withFakeHeygen (
@@ -249,8 +259,8 @@ test("uses explicit avatar and voice overrides without discovery", async () => {
249259 }
250260} ) ;
251261
252- test ( "caches discovered avatar and voice IDs for the process" , async ( ) => {
253- const { server, url } = await listenVideoServer ( ) ;
262+ test ( "caches discovered avatar and voice IDs for the process" , async ( t ) => {
263+ const { server, url } = await listenVideoServer ( t ) ;
254264 const localPaths = new Set ( ) ;
255265 try {
256266 await withFakeHeygen (
@@ -349,8 +359,8 @@ test("onboards and returns null when avatar/voice discovery itself is unauthenti
349359 } ) ;
350360} ) ;
351361
352- test ( "download failure after a successful create returns null and logs a diagnostic" , async ( ) => {
353- const { server, url } = await listenFailingVideoServer ( ) ;
362+ test ( "download failure after a successful create returns null and logs a diagnostic" , async ( t ) => {
363+ const { server, url } = await listenFailingVideoServer ( t ) ;
354364 try {
355365 await withFakeHeygen ( { response : JSON . stringify ( { data : { video_url : url } } ) } , async ( ) => {
356366 const heygenVideoGenerate = await freshGenerate ( ) ;
0 commit comments