@testdriverai/runner 7.9.103-test → 7.9.104-test

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.
Files changed (2) hide show
  1. package/lib/automation.js +26 -1
  2. package/package.json +1 -1
package/lib/automation.js CHANGED
@@ -52,6 +52,26 @@ const PY_IMPORT = IS_LINUX
52
52
  ? "import os; os.environ.setdefault('DISPLAY', ':0'); import pyautogui, sys; pyautogui.FAILSAFE = False; "
53
53
  : 'import pyautogui, sys; pyautogui.FAILSAFE = False; ';
54
54
 
55
+ /**
56
+ * Read width/height from a PNG buffer's IHDR chunk without decoding the image.
57
+ * PNG layout: 8-byte signature, then the IHDR chunk whose 4-byte width and
58
+ * height live at byte offsets 16 and 20 (big-endian). Returns {} if the buffer
59
+ * doesn't look like a PNG so callers degrade to the resize fallback.
60
+ * @param {Buffer} buffer
61
+ * @returns {{ width?: number, height?: number }}
62
+ */
63
+ function readPngDimensions(buffer) {
64
+ const PNG_SIGNATURE = '89504e470d0a1a0a';
65
+ if (!buffer || buffer.length < 24 ||
66
+ buffer.slice(0, 8).toString('hex') !== PNG_SIGNATURE) {
67
+ return {};
68
+ }
69
+ return {
70
+ width: buffer.readUInt32BE(16),
71
+ height: buffer.readUInt32BE(20),
72
+ };
73
+ }
74
+
55
75
  /**
56
76
  * Run a pyautogui Python script via subprocess.
57
77
  * @param {string} script — Python code (pyautogui + sys are already imported via PY_IMPORT prefix)
@@ -600,12 +620,17 @@ class Automation extends EventEmitter {
600
620
  const buffer = await this._captureScreenshotBuffer();
601
621
  console.log(`[automation] Step 2: Screenshot captured, size: ${buffer.length} bytes`);
602
622
 
623
+ // Read the PNG dimensions from the IHDR header (bytes 16–24) without
624
+ // decoding. The SDK uses these to decide whether it can pass the s3Key
625
+ // straight to the API (no resize needed) or must download + resize.
626
+ const dimensions = readPngDimensions(buffer);
627
+
603
628
  // Upload screenshot to S3 and return key
604
629
  console.log('[automation] Step 3: Uploading to S3...');
605
630
  const s3Key = await this._uploadToS3(buffer, this._sandboxId, 'image/png');
606
631
  console.log(`[automation] Step 4: Upload complete, s3Key: ${s3Key}`);
607
632
 
608
- return { s3Key };
633
+ return { s3Key, ...dimensions };
609
634
  }
610
635
 
611
636
  case 'ping':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testdriverai/runner",
3
- "version": "7.9.103-test",
3
+ "version": "7.9.104-test",
4
4
  "description": "TestDriver Runner - Ably-based remote automation agent with Node.js automation",
5
5
  "main": "index.js",
6
6
  "bin": {