testdriverai 7.9.0-test.39 → 7.9.0-test.40
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/lib/sandbox.js +36 -5
- package/package.json +1 -1
package/agent/lib/sandbox.js
CHANGED
|
@@ -12,6 +12,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
12
12
|
this._ably = null;
|
|
13
13
|
this._sessionChannel = null;
|
|
14
14
|
this._channelName = null;
|
|
15
|
+
this._membersChannelName = null;
|
|
15
16
|
this.ps = {};
|
|
16
17
|
this._execBuffers = {}; // accumulate streamed exec.output chunks per requestId
|
|
17
18
|
this.heartbeat = null;
|
|
@@ -53,7 +54,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
53
54
|
return this._publishCount;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
async _initAbly(ablyToken, channelName) {
|
|
57
|
+
async _initAbly(ablyToken, channelName, membersChannelName) {
|
|
57
58
|
if (this._ably) {
|
|
58
59
|
try {
|
|
59
60
|
this._ably.close();
|
|
@@ -62,6 +63,19 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
this._channelName = channelName;
|
|
66
|
+
|
|
67
|
+
// Derive the members channel from the session channel if not supplied.
|
|
68
|
+
// Format: testdriver:{env}:{teamId}:{sandboxId} → testdriver:{env}:{teamId}:members
|
|
69
|
+
if (!membersChannelName) {
|
|
70
|
+
const parts = channelName.split(":");
|
|
71
|
+
if (parts.length >= 3) {
|
|
72
|
+
membersChannelName = parts.slice(0, 3).join(":") + ":members";
|
|
73
|
+
} else {
|
|
74
|
+
logger.warn("[ably] Channel name format unexpected (" + channelName + "), cannot derive members channel");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
this._membersChannelName = membersChannelName;
|
|
78
|
+
|
|
65
79
|
var self = this;
|
|
66
80
|
|
|
67
81
|
this._ably = new Ably.Realtime({
|
|
@@ -105,7 +119,24 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
105
119
|
|
|
106
120
|
logger.debug(`[realtime] Channel initialized: ${channelName}`);
|
|
107
121
|
|
|
108
|
-
// Enter presence on the
|
|
122
|
+
// Enter presence on the team members channel so the API can count
|
|
123
|
+
// connected SDK clients with a single direct lookup per team.
|
|
124
|
+
if (membersChannelName) {
|
|
125
|
+
try {
|
|
126
|
+
var membersChannel = this._ably.channels.get(membersChannelName);
|
|
127
|
+
await membersChannel.presence.enter({
|
|
128
|
+
sandboxId: this._sandboxId,
|
|
129
|
+
connectedAt: Date.now(),
|
|
130
|
+
});
|
|
131
|
+
logger.debug(`[realtime] Entered presence on members channel (sandbox=${this._sandboxId})`);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
// Non-fatal — presence is used for concurrency counting, not critical path
|
|
134
|
+
logger.warn("Failed to enter presence on members channel: " + (e.message || e));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Enter presence on the session channel so the API's session monitor can
|
|
139
|
+
// detect SDK connect/disconnect events for this sandbox.
|
|
109
140
|
try {
|
|
110
141
|
await this._sessionChannel.presence.enter({
|
|
111
142
|
sandboxId: this._sandboxId,
|
|
@@ -113,7 +144,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
113
144
|
});
|
|
114
145
|
logger.debug(`[realtime] Entered presence on session channel (sandbox=${this._sandboxId})`);
|
|
115
146
|
} catch (e) {
|
|
116
|
-
// Non-fatal — presence is used for
|
|
147
|
+
// Non-fatal — presence is used for disconnect detection, not critical path
|
|
117
148
|
logger.warn("Failed to enter presence on session channel: " + (e.message || e));
|
|
118
149
|
}
|
|
119
150
|
|
|
@@ -522,7 +553,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
522
553
|
this._teamId = reply.teamId;
|
|
523
554
|
|
|
524
555
|
if (reply.ably && reply.ably.token) {
|
|
525
|
-
await this._initAbly(reply.ably.token, reply.ably.channel);
|
|
556
|
+
await this._initAbly(reply.ably.token, reply.ably.channel, reply.ably.membersChannel);
|
|
526
557
|
this.instanceSocketConnected = true;
|
|
527
558
|
|
|
528
559
|
// Tell the runner to enable debug log forwarding if debug mode is on
|
|
@@ -648,7 +679,7 @@ const createSandbox = function (emitter, analytics, sessionInstance) {
|
|
|
648
679
|
if (reply.status === 'pending' && reply.ably && reply.ably.token) {
|
|
649
680
|
this._sandboxId = reply.sandboxId;
|
|
650
681
|
this._teamId = reply.teamId;
|
|
651
|
-
await this._initAbly(reply.ably.token, reply.ably.channel);
|
|
682
|
+
await this._initAbly(reply.ably.token, reply.ably.channel, reply.ably.membersChannel);
|
|
652
683
|
this.instanceSocketConnected = true;
|
|
653
684
|
}
|
|
654
685
|
|