testdriverai 7.2.92 → 7.3.2

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.
package/agent/index.js CHANGED
@@ -437,10 +437,13 @@ class TestDriverAgent extends EventEmitter2 {
437
437
  this.emitter.emit(events.log.narration, theme.dim("checking..."));
438
438
 
439
439
  // check asks the ai if the task is complete
440
- let thisScreenshot = await this.system.captureScreenBase64(1, false, true);
440
+ // Parallelize system calls for better performance
441
+ const [thisScreenshot, mousePosition, activeWindow] = await Promise.all([
442
+ this.system.captureScreenBase64(1, false, true),
443
+ this.system.getMousePosition(),
444
+ this.system.activeWin(),
445
+ ]);
441
446
  let images = [this.lastScreenshot, thisScreenshot];
442
- let mousePosition = await this.system.getMousePosition();
443
- let activeWindow = await this.system.activeWin();
444
447
 
445
448
  let response = await this.sdk.req("check", {
446
449
  tasks: this.tasks,
@@ -902,12 +905,18 @@ commands:
902
905
 
903
906
  this.emitter.emit(events.log.narration, theme.dim("thinking..."), true);
904
907
 
905
- this.lastScreenshot = await this.system.captureScreenBase64();
908
+ // Parallelize system calls for better performance
909
+ const [screenshot, mousePosition, activeWindow] = await Promise.all([
910
+ this.system.captureScreenBase64(),
911
+ this.system.getMousePosition(),
912
+ this.system.activeWin(),
913
+ ]);
914
+ this.lastScreenshot = screenshot;
906
915
 
907
916
  let message = await this.sdk.req("input", {
908
917
  input: currentTask,
909
- mousePosition: await this.system.getMousePosition(),
910
- activeWindow: await this.system.activeWin(),
918
+ mousePosition,
919
+ activeWindow,
911
920
  image: this.lastScreenshot,
912
921
  });
913
922
 
@@ -938,13 +947,15 @@ commands:
938
947
 
939
948
  this.emitter.emit(events.log.narration, theme.dim("thinking..."), true);
940
949
 
941
- let image = await this.system.captureScreenBase64();
942
-
943
950
  const streamId = `generate-${Date.now()}`;
944
951
  this.emitter.emit(events.log.markdown.start, streamId);
945
952
 
946
- let mouse = await this.system.getMousePosition();
947
- let activeWindow = await this.system.activeWin();
953
+ // Parallelize system calls for better performance
954
+ const [image, mouse, activeWindow] = await Promise.all([
955
+ this.system.captureScreenBase64(),
956
+ this.system.getMousePosition(),
957
+ this.system.activeWin(),
958
+ ]);
948
959
 
949
960
  let message = await this.sdk.req(
950
961
  "generate",
@@ -2035,12 +2046,13 @@ ${regression}
2035
2046
  // Use the debugger URL instead of the VNC URL
2036
2047
  const urlToOpen = `${this.debuggerUrl}?data=${encodedData}`;
2037
2048
 
2038
- // Check preview mode from config
2039
- const previewMode = this.config.TD_PREVIEW || "browser";
2049
+ // Check preview mode from CLI options (SDK passes it directly)
2050
+ const previewMode = (this.cliArgs.options && this.cliArgs.options.preview) || this.config.TD_PREVIEW || "browser";
2051
+ console.log("[DEBUG renderSandbox] preview:", previewMode);
2040
2052
 
2041
2053
  if (previewMode === "ide") {
2042
2054
  // Send session to VS Code extension via HTTP
2043
- this.sendIdeSessionNotification(urlToOpen, data);
2055
+ this.writeIdeSessionFile(urlToOpen, data);
2044
2056
  } else if (previewMode !== "none") {
2045
2057
  // Open in browser (default behavior)
2046
2058
  this.emitter.emit(events.showWindow, urlToOpen);
@@ -2049,6 +2061,34 @@ ${regression}
2049
2061
  }
2050
2062
  }
2051
2063
 
2064
+ // Write session file for IDE preview (VSCode extension watches for these)
2065
+ writeIdeSessionFile(debuggerUrl, data) {
2066
+ const fs = require("fs");
2067
+ const path = require("path");
2068
+
2069
+ const sessionId = `${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
2070
+ const previewsDir = path.join(process.cwd(), ".testdriver", ".previews");
2071
+
2072
+ // Create the previews directory if it doesn't exist
2073
+ if (!fs.existsSync(previewsDir)) {
2074
+ fs.mkdirSync(previewsDir, { recursive: true });
2075
+ }
2076
+
2077
+ const sessionData = {
2078
+ sessionId,
2079
+ debuggerUrl,
2080
+ resolution: Array.isArray(data.resolution) ? data.resolution : (data.resolution ? data.resolution.split("x").map(Number) : [1920, 1080]),
2081
+ testFile: data.testFile || this.testFile || null,
2082
+ os: data.os || this.sandboxOs || "linux",
2083
+ timestamp: Date.now(),
2084
+ };
2085
+
2086
+ const filePath = path.join(previewsDir, `${sessionId}.json`);
2087
+ fs.writeFileSync(filePath, JSON.stringify(sessionData, null, 2));
2088
+
2089
+ logger.log(`IDE preview session written to ${filePath}`);
2090
+ }
2091
+
2052
2092
  // Find the VS Code instance that contains the test file
2053
2093
  findTargetIdeInstance(testFilePath) {
2054
2094
  const fs = require("fs");
@@ -10,7 +10,10 @@ const createAnalytics = (emitter, config, sessionInstance) => {
10
10
  return;
11
11
  }
12
12
  if (Math.random() <= 0.01) {
13
- await sdk.req("analytics", { event, data });
13
+ // Fire-and-forget: don't await analytics calls
14
+ sdk.req("analytics", { event, data }).catch((err) => {
15
+ console.warn("Analytics track failed:", err.message);
16
+ });
14
17
  }
15
18
  },
16
19
  };