@testdriverai/runner 7.9.59-canary → 7.9.60-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.
- package/lib/ably-service.js +45 -0
- package/package.json +1 -1
package/lib/ably-service.js
CHANGED
|
@@ -136,6 +136,41 @@ async function httpPost(apiRoot, path, body, extraHeaders = {}) {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// ─── EC2 Metadata Helpers ────────────────────────────────────────────────────
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Fetch the public IPv4 address from the EC2 Instance Metadata Service (IMDSv1).
|
|
143
|
+
* Returns null if not running on EC2, instance has no public IP, or request times out.
|
|
144
|
+
* Non-blocking: uses a 2-second timeout so it never delays runner startup.
|
|
145
|
+
*
|
|
146
|
+
* @returns {Promise<string|null>}
|
|
147
|
+
*/
|
|
148
|
+
function getEc2PublicIp() {
|
|
149
|
+
return new Promise((resolve) => {
|
|
150
|
+
const req = http.request(
|
|
151
|
+
{
|
|
152
|
+
hostname: '169.254.169.254',
|
|
153
|
+
port: 80,
|
|
154
|
+
path: '/latest/meta-data/public-ipv4',
|
|
155
|
+
method: 'GET',
|
|
156
|
+
timeout: 2000,
|
|
157
|
+
},
|
|
158
|
+
(res) => {
|
|
159
|
+
if (res.statusCode !== 200) {
|
|
160
|
+
resolve(null);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let data = '';
|
|
164
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
165
|
+
res.on('end', () => resolve(data.trim() || null));
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
req.on('error', () => resolve(null));
|
|
169
|
+
req.on('timeout', () => { req.destroy(); resolve(null); });
|
|
170
|
+
req.end();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
139
174
|
// ─── Ably Service Class ──────────────────────────────────────────────────────
|
|
140
175
|
|
|
141
176
|
class AblyService extends EventEmitter {
|
|
@@ -481,12 +516,22 @@ class AblyService extends EventEmitter {
|
|
|
481
516
|
this.emit('log', 'Listening for commands on Ably');
|
|
482
517
|
|
|
483
518
|
// Signal readiness to SDK — commands sent before this would be lost
|
|
519
|
+
|
|
520
|
+
// Best-effort: fetch the public IP from EC2 instance metadata so the SDK can
|
|
521
|
+
// construct the VNC preview URL without relying solely on API-side IP lookup.
|
|
522
|
+
// Times out after 2s and resolves null if not on EC2 or instance has no public IP.
|
|
523
|
+
const ec2PublicIp = await getEc2PublicIp();
|
|
524
|
+
if (ec2PublicIp) {
|
|
525
|
+
this.emit('log', `EC2 public IP: ${ec2PublicIp}`);
|
|
526
|
+
}
|
|
527
|
+
|
|
484
528
|
const readyPayload = {
|
|
485
529
|
type: 'runner.ready',
|
|
486
530
|
os: process.platform === 'win32' ? 'windows' : 'linux',
|
|
487
531
|
sandboxId: this._sandboxId,
|
|
488
532
|
runnerVersion: getLocalVersion() || 'unknown',
|
|
489
533
|
timestamp: Date.now(),
|
|
534
|
+
ip: ec2PublicIp || undefined,
|
|
490
535
|
};
|
|
491
536
|
if (this._updateInfo) {
|
|
492
537
|
readyPayload.update = {
|