@@ -20,7 +20,6 @@ import os from 'os';
2020import path from 'path' ;
2121import { vi } from 'vitest' ;
2222import TestDriverSDK from '../../sdk.js' ;
23- import { events } from '../../agent/events.js' ;
2423
2524/**
2625 * Set up console spies using Vitest's vi.spyOn to intercept console logs
@@ -104,7 +103,7 @@ function setupConsoleSpy(client, taskId) {
104103 // Store spies on client for cleanup
105104 client . _consoleSpies = { logSpy, errorSpy, warnSpy, infoSpy } ;
106105
107- client . emitter . emit ( events . log . debug , ` Console spy set up for task: ${ taskId } `) ;
106+ console . log ( `[testdriver] Console spy set up for task: ${ taskId } `) ;
108107}
109108
110109/**
@@ -167,7 +166,9 @@ export function TestDriver(context, options = {}) {
167166 // Priority: test options > plugin options > environment variable > default (linux)
168167 if ( ! mergedOptions . os && process . env . TD_OS ) {
169168 mergedOptions . os = process . env . TD_OS ;
169+ console . log ( `[testdriver] Set mergedOptions.os = ${ mergedOptions . os } from TD_OS environment variable` ) ;
170170 }
171+ console . log ( `[testdriver] Final mergedOptions.os = ${ mergedOptions . os } ` ) ;
171172
172173 // Extract TestDriver-specific options
173174 const apiKey = mergedOptions . apiKey || process . env . TD_API_KEY ;
@@ -185,27 +186,21 @@ export function TestDriver(context, options = {}) {
185186 testdriver . __vitestContext = context . task ;
186187 testDriverInstances . set ( context . task , testdriver ) ;
187188
188- // Log OS detection after testdriver is created
189- if ( process . env . TD_OS ) {
190- testdriver . emitter . emit ( events . log . debug , `Set mergedOptions.os = ${ mergedOptions . os } from TD_OS environment variable` ) ;
191- }
192- testdriver . emitter . emit ( events . log . debug , `Final mergedOptions.os = ${ mergedOptions . os } ` ) ;
193-
194189 // Auto-connect if enabled (default: true)
195190 const autoConnect = config . autoConnect !== undefined ? config . autoConnect : true ;
196191 const debugConsoleSpy = process . env . TD_DEBUG_CONSOLE_SPY === 'true' ;
197192
198193 if ( autoConnect ) {
199194 testdriver . __connectionPromise = ( async ( ) => {
200- testdriver . emitter . emit ( events . log . debug , ' Connecting to sandbox...') ;
195+ console . log ( '[testdriver] Connecting to sandbox...') ;
201196 if ( debugConsoleSpy ) {
202197 console . log ( '[DEBUG] Before auth - sandbox.instanceSocketConnected:' , testdriver . sandbox ?. instanceSocketConnected ) ;
203198 }
204199
205200 await testdriver . auth ( ) ;
206201 await testdriver . connect ( ) ;
207202
208- testdriver . emitter . emit ( events . log . debug , ' ✅ Connected to sandbox') ;
203+ console . log ( '[testdriver] ✅ Connected to sandbox') ;
209204
210205 if ( debugConsoleSpy ) {
211206 console . log ( '[DEBUG] After connect - sandbox.instanceSocketConnected:' , testdriver . sandbox ?. instanceSocketConnected ) ;
@@ -226,8 +221,8 @@ export function TestDriver(context, options = {}) {
226221 : `touch ${ logPath } ` ;
227222
228223 await testdriver . exec ( shell , createLogCmd , 10000 , true ) ;
229- testdriver . emitter . emit ( events . log . debug , ` ✅ Created log file: ${ logPath } ` ) ;
230-
224+ console . log ( '[testdriver] ✅ Created log file:' , logPath ) ;
225+
231226 // Add automatic log tracking when dashcam starts
232227 // Store original start method
233228
@@ -239,20 +234,20 @@ export function TestDriver(context, options = {}) {
239234 // Register cleanup handler with dashcam.stop()
240235 if ( ! lifecycleHandlers . has ( context . task ) ) {
241236 const cleanup = async ( ) => {
242- testdriver . emitter . emit ( events . log . debug , ' Cleaning up TestDriver client...') ;
237+ console . log ( '[testdriver] Cleaning up TestDriver client...') ;
243238 try {
244239 // Stop dashcam if it was started - with timeout to prevent hanging
245240 if ( testdriver . _dashcam && testdriver . _dashcam . recording ) {
246241 try {
247242 const dashcamUrl = await testdriver . dashcam . stop ( ) ;
248- testdriver . emitter . emit ( events . log . debug , ` 🎥 Dashcam URL: ${ dashcamUrl } ` ) ;
243+ console . log ( ' 🎥 Dashcam URL:' , dashcamUrl ) ;
249244
250245 // Write test result to file for the reporter (cross-process communication)
251246 // This should happen regardless of whether dashcam succeeded, to ensure platform info is available
252247 const testId = context . task . id ;
253- testdriver . emitter . emit ( events . log . debug , ` testdriver.os value: ${ testdriver . os } `) ;
248+ console . log ( `[testdriver] testdriver.os value: ${ testdriver . os } `) ;
254249 const platform = testdriver . os || 'linux' ;
255- testdriver . emitter . emit ( events . log . debug , ` Using platform: ${ platform } `) ;
250+ console . log ( `[testdriver] Using platform: ${ platform } `) ;
256251 const absolutePath = context . task . file ?. filepath || context . task . file ?. name || 'unknown' ;
257252 const projectRoot = process . cwd ( ) ;
258253 const testFile = absolutePath !== 'unknown'
@@ -276,12 +271,12 @@ export function TestDriver(context, options = {}) {
276271 } ;
277272
278273 fs . writeFileSync ( testResultFile , JSON . stringify ( testResult , null , 2 ) ) ;
279- testdriver . emitter . emit ( events . log . debug , ` ✅ Wrote test result to ${ testResultFile } `) ;
274+ console . log ( `[testdriver] ✅ Wrote test result to ${ testResultFile } `) ;
280275
281276 // Also register in memory if plugin is available
282277 if ( globalThis . __testdriverPlugin ?. registerDashcamUrl ) {
283278 globalThis . __testdriverPlugin . registerDashcamUrl ( testId , dashcamUrl , platform ) ;
284- testdriver . emitter . emit ( events . log . debug , ` ✅ Registered test result in memory for test ${ testId } `) ;
279+ console . log ( `[testdriver] ✅ Registered test result in memory for test ${ testId } `) ;
285280 }
286281 } catch ( error ) {
287282 // Log more detailed error information for debugging
@@ -311,7 +306,7 @@ export function TestDriver(context, options = {}) {
311306 testdriver . disconnect ( ) ,
312307 new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) // 5s timeout for disconnect
313308 ] ) ;
314- testdriver . emitter . emit ( events . log . debug , '✅ Client disconnected' ) ;
309+ console . log ( '✅ Client disconnected' ) ;
315310 } catch ( error ) {
316311 console . error ( 'Error disconnecting client:' , error ) ;
317312 }
0 commit comments