Skip to content

Commit c0f3fb0

Browse files
committed
undo all log changes
1 parent 8650807 commit c0f3fb0

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

lib/vitest/hooks.mjs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import os from 'os';
2020
import path from 'path';
2121
import { vi } from 'vitest';
2222
import 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
}

sdk.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ class TestDriverSDK {
11021102

11031103
// Store os and resolution for API requests
11041104
this.os = options.os || "linux";
1105-
this.emitter.emit(events.log.debug, `Setting this.os = ${this.os} (from options.os = ${options.os})`);
1105+
console.log(`[SDK Constructor] Setting this.os = ${this.os} (from options.os = ${options.os})`);
11061106
this.resolution = options.resolution || "1366x768";
11071107

11081108
// Store newSandbox preference from options
@@ -1270,26 +1270,26 @@ class TestDriverSDK {
12701270

12711271
await this.exec(shell, createLogCmd, 10000, true);
12721272

1273-
this.emitter.emit(events.log.debug, 'Adding web logs to dashcam...');
1273+
console.log('[provision.chrome] Adding web logs to dashcam...');
12741274
try {
12751275
const urlObj = new URL(url);
12761276
const domain = urlObj.hostname;
12771277
const pattern = `*${domain}*`;
12781278
await this._dashcam.addWebLog(pattern, 'Web Logs');
1279-
this.emitter.emit(events.log.debug, `✅ Web logs added to dashcam (pattern: ${pattern})`);
1279+
console.log(`[provision.chrome] ✅ Web logs added to dashcam (pattern: ${pattern})`);
12801280

12811281
await this._dashcam.addFileLog(logPath, "TestDriver Log");
12821282

12831283
} catch (error) {
1284-
this.emitter.emit(events.log.warn, `⚠️ Failed to add web logs: ${error.message}`);
1284+
console.warn('[provision.chrome] ⚠️ Failed to add web logs:', error.message);
12851285
}
12861286
}
12871287

12881288
// Automatically start dashcam if not already recording
12891289
if (!this._dashcam || !this._dashcam.recording) {
1290-
this.emitter.emit(events.log.debug, 'Starting dashcam...');
1290+
console.log('[provision.chrome] Starting dashcam...');
12911291
await this.dashcam.start();
1292-
this.emitter.emit(events.log.debug, '✅ Dashcam started');
1292+
console.log('[provision.chrome] ✅ Dashcam started');
12931293
}
12941294

12951295
// Set up Chrome profile with preferences
@@ -1345,7 +1345,7 @@ class TestDriverSDK {
13451345
: `cat > "${prefsPath}" << 'EOF'\n${prefsJson}\nEOF`;
13461346

13471347
await this.exec(shell, writePrefCmd, 10000, true);
1348-
this.emitter.emit(events.log.debug, '✅ Chrome preferences configured');
1348+
console.log('[provision.chrome] ✅ Chrome preferences configured');
13491349

13501350
// Build Chrome launch command
13511351
const chromeArgs = [];
@@ -1384,15 +1384,15 @@ class TestDriverSDK {
13841384
const urlObj = new URL(url);
13851385
const domain = urlObj.hostname;
13861386

1387-
this.emitter.emit(events.log.debug, `Waiting for domain "${domain}" to appear in URL bar...`);
1387+
console.log(`[provision.chrome] Waiting for domain "${domain}" to appear in URL bar...`);
13881388

13891389
for (let attempt = 0; attempt < 30; attempt++) {
13901390
const result = await this.find(`${domain}`);
13911391

1392-
this.emitter.emit(events.log.debug, `Checking for domain in URL bar (attempt ${attempt + 1}/30)...`);
1392+
console.log(`[provision.chrome] Checking for domain in URL bar (attempt ${attempt + 1}/30)...`);
13931393

13941394
if (result.found()) {
1395-
this.emitter.emit(events.log.debug, `✅ Chrome ready at ${url}`);
1395+
console.log(`[provision.chrome] ✅ Chrome ready at ${url}`);
13961396
break;
13971397
} else {
13981398
await new Promise(resolve => setTimeout(resolve, 1000));
@@ -1451,7 +1451,7 @@ class TestDriverSDK {
14511451

14521452
// Wait for VS Code to be ready
14531453
await this.focusApplication('Visual Studio Code');
1454-
this.emitter.emit(events.log.debug, '✅ VS Code ready');
1454+
console.log('[provision.vscode] ✅ VS Code ready');
14551455
},
14561456

14571457
/**
@@ -1488,7 +1488,7 @@ class TestDriverSDK {
14881488
}
14891489

14901490
await this.focusApplication('Electron');
1491-
this.emitter.emit(events.log.debug, '✅ Electron app ready');
1491+
console.log('[provision.electron] ✅ Electron app ready');
14921492
},
14931493
};
14941494
}
@@ -1590,11 +1590,11 @@ class TestDriverSDK {
15901590

15911591
// Ensure this.os reflects the actual sandbox OS (important for vitest reporter)
15921592
// After buildEnv, agent.sandboxOs should contain the correct OS value
1593-
this.emitter.emit(events.log.debug, `After buildEnv: this.agent.sandboxOs = ${this.agent.sandboxOs}, this.os (before) = ${this.os}`);
1593+
console.log(`[SDK] After buildEnv: this.agent.sandboxOs = ${this.agent.sandboxOs}, this.os (before) = ${this.os}`);
15941594
if (this.agent.sandboxOs) {
15951595
this.os = this.agent.sandboxOs;
15961596
}
1597-
this.emitter.emit(events.log.debug, `After buildEnv: this.os (after) = ${this.os}`);
1597+
console.log(`[SDK] After buildEnv: this.os (after) = ${this.os}`);
15981598

15991599
// Also ensure sandbox.os is set for consistency
16001600
if (this.agent.sandbox && this.os) {

0 commit comments

Comments
 (0)