testdriverai 7.8.0-test.53 → 7.8.0-test.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  const useStderr = process.env.TD_STDIO === 'stderr';
10
+ const isDebug = process.env.DEBUG === 'true';
10
11
 
11
12
  /**
12
13
  * Log a message - uses stdout by default, stderr if TD_STDIO=stderr
@@ -40,6 +41,19 @@ function warn(...args) {
40
41
  }
41
42
  }
42
43
 
44
+ /**
45
+ * Log a debug message - only outputs when DEBUG=true
46
+ * @param {...any} args - Arguments to log
47
+ */
48
+ function debug(...args) {
49
+ if (!isDebug) return;
50
+ if (useStderr) {
51
+ console.error(...args);
52
+ } else {
53
+ console.log(...args);
54
+ }
55
+ }
56
+
43
57
  /**
44
58
  * Check if logger is configured to use stderr
45
59
  * @returns {boolean}
@@ -50,6 +64,7 @@ function isStderrMode() {
50
64
 
51
65
  module.exports = {
52
66
  log,
67
+ debug,
53
68
  error,
54
69
  warn,
55
70
  isStderrMode,
@@ -85,7 +85,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
85
85
  suspendedRetryTimeout: 15000, // retry from suspended every 15s (default 30s)
86
86
  });
87
87
 
88
- logger.log(`[realtime] Connecting as sdk-${this._sandboxId}...`);
88
+ logger.debug(`[realtime] Connecting as sdk-${this._sandboxId}...`);
89
89
 
90
90
  await new Promise(function (resolve, reject) {
91
91
  self._ably.connection.on("connected", resolve);
@@ -99,7 +99,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
99
99
 
100
100
  this._sessionChannel = this._ably.channels.get(channelName);
101
101
 
102
- logger.log(`[realtime] Channel initialized: ${channelName}`);
102
+ logger.debug(`[realtime] Channel initialized: ${channelName}`);
103
103
 
104
104
  // Enter presence on the session channel so the API can count connected SDK clients
105
105
  try {
@@ -107,7 +107,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
107
107
  sandboxId: this._sandboxId,
108
108
  connectedAt: Date.now(),
109
109
  });
110
- logger.log(`[realtime] Entered presence on session channel (sandbox=${this._sandboxId})`);
110
+ logger.debug(`[realtime] Entered presence on session channel (sandbox=${this._sandboxId})`);
111
111
  } catch (e) {
112
112
  // Non-fatal — presence is used for concurrency counting, not critical path
113
113
  logger.warn("Failed to enter presence on session channel: " + (e.message || e));
@@ -118,7 +118,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
118
118
  var message = msg.data;
119
119
  if (!message) return;
120
120
 
121
- logger.log(`[realtime] Received response: type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
121
+ logger.debug(`[realtime] Received response: type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
122
122
 
123
123
  if (message.type === "sandbox.progress") {
124
124
  emitter.emit(events.sandbox.progress, {
@@ -212,7 +212,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
212
212
  var resolveAge = resolveEntry.startTime
213
213
  ? ((Date.now() - resolveEntry.startTime) / 1000).toFixed(1) + 's'
214
214
  : '?';
215
- logger.log(
215
+ logger.debug(
216
216
  '[realtime] Promise RESOLVED: requestId=' + message.requestId +
217
217
  ' | type=' + (resolveEntry.message ? resolveEntry.message.type : 'unknown') +
218
218
  ' | age=' + resolveAge
@@ -241,7 +241,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
241
241
  this._onFileMsg = function (msg) {
242
242
  var message = msg.data;
243
243
  if (!message) return;
244
- logger.log(`[realtime] Received file: type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
244
+ logger.debug(`[realtime] Received file: type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
245
245
  if (message.requestId && self.ps[message.requestId]) {
246
246
  emitter.emit(events.sandbox.received);
247
247
  self.ps[message.requestId].resolve(message);
@@ -260,7 +260,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
260
260
  const chState = this._sessionChannel ? this._sessionChannel.state : 'null';
261
261
  const pendingIds = Object.keys(this.ps);
262
262
  const pending = pendingIds.length;
263
- logger.log(`[realtime][stats] connection=${connState} | sandbox=${this._sandboxId} | pending=${pending} | channel=${chState}`);
263
+ logger.debug(`[realtime][stats] connection=${connState} | sandbox=${this._sandboxId} | pending=${pending} | channel=${chState}`);
264
264
  if (pending > 0) {
265
265
  const now = Date.now();
266
266
  for (const rid of pendingIds) {
@@ -268,20 +268,20 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
268
268
  if (!entry) continue;
269
269
  const type = entry.message ? entry.message.type : 'unknown';
270
270
  const ageSec = ((now - (entry.startTime || now)) / 1000).toFixed(1);
271
- logger.log(`[realtime][stats] pending: requestId=${rid} | type=${type} | age=${ageSec}s`);
271
+ logger.debug(`[realtime][stats] pending: requestId=${rid} | type=${type} | age=${ageSec}s`);
272
272
  }
273
273
  }
274
274
  }, 10000);
275
275
  if (this._statsInterval.unref) this._statsInterval.unref();
276
276
 
277
277
  this._ably.connection.on("disconnected", function () {
278
- logger.log("[realtime] Connection: disconnected - will auto-reconnect");
278
+ logger.debug("[realtime] Connection: disconnected - will auto-reconnect");
279
279
  self._disconnectedAt = Date.now();
280
280
  });
281
281
 
282
282
  this._ably.connection.on("connected", function () {
283
283
  // Log reconnection so the user knows the blip was recovered
284
- logger.log("[realtime] Connection: reconnected");
284
+ logger.debug("[realtime] Connection: reconnected");
285
285
  // Extend any pending command timeouts by the disconnection duration so
286
286
  // commands whose timer was counting down while the connection was down
287
287
  // don't get incorrectly timed out.
@@ -290,7 +290,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
290
290
  self._disconnectedAt = null;
291
291
  var pendingIds = Object.keys(self.ps);
292
292
  if (pendingIds.length > 0) {
293
- logger.log(
293
+ logger.debug(
294
294
  '[realtime] Extending ' + pendingIds.length + ' pending timeout(s) by ' +
295
295
  disconnectionDurationMs + 'ms after disconnection'
296
296
  );
@@ -353,7 +353,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
353
353
  var entry = subs[i];
354
354
  if (!entry.sub) continue;
355
355
  try {
356
- logger.log('[realtime] Discontinuity recovery: fetching historyBeforeSubscribe for ' + entry.name + '...');
356
+ logger.debug('[realtime] Discontinuity recovery: fetching historyBeforeSubscribe for ' + entry.name + '...');
357
357
  var page = await entry.sub.historyBeforeSubscribe({ limit: 100 });
358
358
  var recovered = 0;
359
359
  while (page) {
@@ -363,7 +363,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
363
363
  recovered++;
364
364
  try {
365
365
  if (entry.handler) {
366
- logger.log('[realtime] Replaying recovered ' + entry.name + ' message (requestId=' + (page.items[j].data && page.items[j].data.requestId || 'none') + ')');
366
+ logger.debug('[realtime] Replaying recovered ' + entry.name + ' message (requestId=' + (page.items[j].data && page.items[j].data.requestId || 'none') + ')');
367
367
  entry.handler(page.items[j]);
368
368
  }
369
369
  } catch (replayErr) {
@@ -373,7 +373,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
373
373
  page = page.hasNext() ? await page.next() : null;
374
374
  }
375
375
  totalRecovered += recovered;
376
- logger.log('[realtime] Discontinuity recovery: replayed ' + recovered + ' ' + entry.name + ' message(s) from gap');
376
+ logger.debug('[realtime] Discontinuity recovery: replayed ' + recovered + ' ' + entry.name + ' message(s) from gap');
377
377
  } catch (err) {
378
378
  logger.error('[realtime] Discontinuity recovery failed for ' + entry.name + ': ' + (err.message || err));
379
379
  }
@@ -381,7 +381,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
381
381
  if (totalRecovered > 0) {
382
382
  logger.warn('[realtime] Recovered and replayed ' + totalRecovered + ' message(s) that were missed during connection interruption');
383
383
  } else {
384
- logger.log('[realtime] Discontinuity recovery: no missed messages found');
384
+ logger.debug('[realtime] Discontinuity recovery: no missed messages found');
385
385
  }
386
386
  }
387
387
 
@@ -1019,7 +1019,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
1019
1019
  }
1020
1020
 
1021
1021
  return channel.publish(eventName, message).then(function () {
1022
- logger.log(`[realtime] Published: channel=${channel.name.split(':').pop()}, event=${eventName}, type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
1022
+ logger.debug(`[realtime] Published: channel=${channel.name.split(':').pop()}, event=${eventName}, type=${message.type || 'unknown'} (requestId=${message.requestId || 'none'})`);
1023
1023
  });
1024
1024
  }
1025
1025
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "7.8.0-test.53",
3
+ "version": "7.8.0-test.54",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "sdk.js",
6
6
  "types": "sdk.d.ts",