mindexec-ai 0.2.385
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/README.md +354 -0
- package/codex-runtime.js +1339 -0
- package/launch-bridge.cjs +236 -0
- package/package.json +77 -0
- package/port-guard.cjs +232 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast +0 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.runtimeconfig.json +13 -0
- package/remote-fast/osx-x64/mindexec-remote-fast +0 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.runtimeconfig.json +13 -0
- package/remote-fast/win-x64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/win-x64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/win-x64/mindexec-remote-fast.exe +0 -0
- package/remote-fast/win-x64/mindexec-remote-fast.runtimeconfig.json +20 -0
- package/remote-hub.js +3106 -0
- package/scripts/auth-session-smoke.mjs +262 -0
- package/scripts/remote-agent-managed-smoke.mjs +291 -0
- package/scripts/remote-agent-package-smoke.mjs +64 -0
- package/scripts/remote-agent-ws-smoke.mjs +202 -0
- package/scripts/remote-fast-live-rate-smoke.mjs +355 -0
- package/scripts/remote-fast-mdm-browser-smoke.mjs +476 -0
- package/scripts/remote-fleet-render-smoke.mjs +1491 -0
- package/scripts/remote-frame-ws-smoke.mjs +234 -0
- package/scripts/remote-http-smoke.mjs +592 -0
- package/scripts/remote-hub-identity-smoke.mjs +146 -0
- package/scripts/remote-hub-scale-smoke.mjs +124 -0
- package/scripts/remote-hub-smoke.mjs +631 -0
- package/scripts/remote-input-ws-smoke.mjs +263 -0
- package/scripts/remote-registry-follower-smoke.mjs +752 -0
- package/scripts/setup-tree-sitter-grammars.mjs +80 -0
- package/server.js +15709 -0
- package/start-bridge.bat +32 -0
- package/start-bridge.sh +81 -0
- package/tree-sitter-grammars/README.md +18 -0
- package/tree-sitter-grammars/tree-sitter-c_sharp.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-go.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-java.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-python.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-rust.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-tsx.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-typescript.wasm +0 -0
- package/wwwroot/_headers +73 -0
- package/wwwroot/_redirects +1 -0
- package/wwwroot/appsettings.json +83 -0
- package/wwwroot/assets/AdminDashboardPage-B2vz2Px9.css +1 -0
- package/wwwroot/assets/AdminDashboardPage-DnuCHywn.js +1 -0
- package/wwwroot/assets/AppSidebar-DU2OgSiv.js +2 -0
- package/wwwroot/assets/AuthPages-BrH6kRcv.css +1 -0
- package/wwwroot/assets/AuthPages-Dgezl7Vj.js +1 -0
- package/wwwroot/assets/CodePage-7kgZlB3O.js +87 -0
- package/wwwroot/assets/CodePage-Bncc352E.css +1 -0
- package/wwwroot/assets/CompanyCorePage-ChBnq1ve.css +1 -0
- package/wwwroot/assets/CompanyCorePage-CzIZIIU_.js +13 -0
- package/wwwroot/assets/ExecutionModePage-B-etp_mc.js +18 -0
- package/wwwroot/assets/ExecutionModePage-TLuld9l3.css +1 -0
- package/wwwroot/assets/LaunchLeadCapture-Bx9LM0IX.js +1 -0
- package/wwwroot/assets/LaunchLeadCapture-CiRI1shz.css +1 -0
- package/wwwroot/assets/MarketingHome-BsyerRpe.js +1 -0
- package/wwwroot/assets/MarketingHome-DPzaYzA_.css +1 -0
- package/wwwroot/assets/MindCanvas-DtqOZnoW.css +1 -0
- package/wwwroot/assets/MindCanvas-zEDXzaxW.js +49 -0
- package/wwwroot/assets/PlanMasterPage-CJ36rep-.css +1 -0
- package/wwwroot/assets/PlanMasterPage-NZ_mPvaE.js +4 -0
- package/wwwroot/assets/PricingPage-Cg_0i_ZR.css +1 -0
- package/wwwroot/assets/PricingPage-Ylrn8l2g.js +1 -0
- package/wwwroot/assets/ToolPages-3M2KqA9k.js +28 -0
- package/wwwroot/assets/ToolPages-DIB187pZ.css +1 -0
- package/wwwroot/assets/YouTubeSearchPage-COv1oAA7.js +4 -0
- package/wwwroot/assets/YouTubeSearchPage-IPPa_BIH.css +1 -0
- package/wwwroot/assets/app-runtime-xD2Z3NdN.js +1 -0
- package/wwwroot/assets/canvas-runtime-BbicBcOj.js +44 -0
- package/wwwroot/assets/code-agent-runtime-B5PPZd1t.js +74 -0
- package/wwwroot/assets/executionModeSettings-NJqurj-o.js +1 -0
- package/wwwroot/assets/index-CQMKCp-t.js +2 -0
- package/wwwroot/assets/index-yNpEK-gp.css +1 -0
- package/wwwroot/assets/marketingTools-DN_rnHeB.js +4 -0
- package/wwwroot/assets/mindCanvasSearchWorker-BzPMsHOB.js +1 -0
- package/wwwroot/assets/mindexecution-mindcanvas.png +0 -0
- package/wwwroot/assets/mindexecution-prod-home-current.png +0 -0
- package/wwwroot/assets/mindexecution-prod-pricing-current.png +0 -0
- package/wwwroot/assets/pricingCheckoutShell-O-DnwmbU.js +1 -0
- package/wwwroot/assets/productionAdapterConfig-C5jfk6oG.js +1 -0
- package/wwwroot/assets/runtimeSettingsPersistenceProjection-BoNWmYjU.js +1 -0
- package/wwwroot/assets/storage-TM3YrWaj.js +1 -0
- package/wwwroot/assets/supabaseAuthAdapter-DA43DeSY.js +44 -0
- package/wwwroot/assets/toolHandoff-D5e5f7t5.js +4 -0
- package/wwwroot/assets/vendor-icons-DE3gIReG.js +681 -0
- package/wwwroot/assets/vendor-msgpack-BE8aAsr3.js +1 -0
- package/wwwroot/assets/vendor-react-BXzpOyCS.js +40 -0
- package/wwwroot/favicon.svg +7 -0
- package/wwwroot/index.html +22 -0
- package/wwwroot/manifest.webmanifest +19 -0
- package/wwwroot/robots.txt +4 -0
- package/wwwroot/service-worker.js +7 -0
- package/wwwroot/sitemap.xml +39 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { createServer } from 'node:http';
|
|
7
|
+
import net from 'node:net';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { WebSocketServer } from 'ws';
|
|
12
|
+
|
|
13
|
+
const BRIDGE_TOKEN = 'remote-registry-follower-smoke-token';
|
|
14
|
+
const PAIR_TOKEN = 'remote-registry-follower-pair-token';
|
|
15
|
+
const USER_ID = '11111111-2222-4333-8444-555555555555';
|
|
16
|
+
const SUPABASE_KEY = 'remote-registry-follower-key';
|
|
17
|
+
const ACCESS_TOKEN = 'remote-registry-follower-access-token';
|
|
18
|
+
const EXPIRED_ACCESS_TOKEN = 'remote-registry-follower-expired-access-token';
|
|
19
|
+
const REFRESHED_ACCESS_TOKEN = 'remote-registry-follower-refreshed-access-token';
|
|
20
|
+
const REFRESH_TOKEN = 'remote-registry-follower-refresh-token';
|
|
21
|
+
const LOCAL_BRIDGE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
22
|
+
|
|
23
|
+
function wait(ms) {
|
|
24
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function findFreePort() {
|
|
28
|
+
return await new Promise((resolve, reject) => {
|
|
29
|
+
const server = net.createServer();
|
|
30
|
+
server.unref();
|
|
31
|
+
server.once('error', reject);
|
|
32
|
+
server.listen(0, '127.0.0.1', () => {
|
|
33
|
+
const address = server.address();
|
|
34
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
35
|
+
server.close(() => resolve(port));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function fetchJson(url, options = {}) {
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
...options,
|
|
43
|
+
headers: {
|
|
44
|
+
...(options.body ? { 'Content-Type': 'application/json' } : {}),
|
|
45
|
+
'X-Bridge-Token': options.token || BRIDGE_TOKEN,
|
|
46
|
+
...(options.headers || {})
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
let payload = null;
|
|
50
|
+
try {
|
|
51
|
+
payload = await response.json();
|
|
52
|
+
} catch {
|
|
53
|
+
// Empty responses are allowed in failure diagnostics.
|
|
54
|
+
}
|
|
55
|
+
return { ok: response.ok, status: response.status, payload };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function waitFor(predicate, timeoutMs, label) {
|
|
59
|
+
const startedAt = Date.now();
|
|
60
|
+
let lastError = null;
|
|
61
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
62
|
+
try {
|
|
63
|
+
const value = await predicate();
|
|
64
|
+
if (value) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
lastError = error;
|
|
69
|
+
}
|
|
70
|
+
await wait(100);
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`Timed out waiting for ${label}${lastError ? `: ${lastError.message}` : ''}.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createRegistryTarget({ endpoint, endpointCandidates, leaseId, active = true, pairToken = PAIR_TOKEN }) {
|
|
76
|
+
return {
|
|
77
|
+
user_id: USER_ID,
|
|
78
|
+
active,
|
|
79
|
+
endpoint,
|
|
80
|
+
endpoint_candidates: endpointCandidates,
|
|
81
|
+
pair_token: pairToken,
|
|
82
|
+
lease_id: leaseId,
|
|
83
|
+
node_id: 'remote-registry-follower-node',
|
|
84
|
+
host_instance_id: `host-${leaseId}`,
|
|
85
|
+
expires_at: new Date(Date.now() + 60_000).toISOString()
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function startFakeSupabase(getTarget, setTarget = null) {
|
|
90
|
+
const requests = [];
|
|
91
|
+
const realtimeClients = new Set();
|
|
92
|
+
const validAccessTokens = new Set([ACCESS_TOKEN]);
|
|
93
|
+
const assertRegistryAuth = req => {
|
|
94
|
+
assert.equal(String(req.headers.apikey || ''), SUPABASE_KEY);
|
|
95
|
+
const authorization = String(req.headers.authorization || '');
|
|
96
|
+
assert.ok(
|
|
97
|
+
validAccessTokens.has(authorization.replace(/^Bearer\s+/i, '')),
|
|
98
|
+
`unexpected registry authorization: ${authorization}`);
|
|
99
|
+
};
|
|
100
|
+
const server = createServer(async (req, res) => {
|
|
101
|
+
const readBody = () => new Promise(resolve => {
|
|
102
|
+
let body = '';
|
|
103
|
+
req.on('data', chunk => {
|
|
104
|
+
body += chunk.toString();
|
|
105
|
+
});
|
|
106
|
+
req.on('end', () => resolve(body));
|
|
107
|
+
});
|
|
108
|
+
const parsed = new URL(req.url || '/', 'http://127.0.0.1');
|
|
109
|
+
requests.push({
|
|
110
|
+
method: req.method,
|
|
111
|
+
pathname: parsed.pathname,
|
|
112
|
+
authorization: req.headers.authorization || '',
|
|
113
|
+
apikey: req.headers.apikey || ''
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (req.method === 'GET' && parsed.pathname === '/rest/v1/remote_host_targets') {
|
|
117
|
+
assertRegistryAuth(req);
|
|
118
|
+
res.writeHead(200, {
|
|
119
|
+
'Content-Type': 'application/json',
|
|
120
|
+
'Cache-Control': 'no-store'
|
|
121
|
+
});
|
|
122
|
+
const target = getTarget();
|
|
123
|
+
res.end(JSON.stringify(target ? [target] : []));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (req.method === 'POST' && parsed.pathname === '/rest/v1/rpc/set_remote_host_target') {
|
|
128
|
+
assertRegistryAuth(req);
|
|
129
|
+
const body = JSON.parse(await readBody() || '{}');
|
|
130
|
+
const now = Date.now();
|
|
131
|
+
const existing = getTarget();
|
|
132
|
+
const sameLease = existing
|
|
133
|
+
&& String(existing.lease_id || '') === String(body.p_lease_id || '')
|
|
134
|
+
&& String(existing.host_instance_id || '') === String(body.p_host_instance_id || '');
|
|
135
|
+
const expired = !existing?.expires_at || Date.parse(existing.expires_at) <= now;
|
|
136
|
+
if (existing?.active === true && !sameLease && !expired && body.p_takeover !== true) {
|
|
137
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
138
|
+
res.end(JSON.stringify([{ ok: false, reason: 'host-target-taken' }]));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setTarget?.({
|
|
143
|
+
user_id: USER_ID,
|
|
144
|
+
active: true,
|
|
145
|
+
endpoint: String(body.p_endpoint || ''),
|
|
146
|
+
endpoint_candidates: Array.isArray(body.p_endpoint_candidates)
|
|
147
|
+
? body.p_endpoint_candidates
|
|
148
|
+
: [String(body.p_endpoint || '')].filter(Boolean),
|
|
149
|
+
pair_token: String(body.p_pair_token || ''),
|
|
150
|
+
lease_id: String(body.p_lease_id || ''),
|
|
151
|
+
node_id: String(body.p_node_id || ''),
|
|
152
|
+
host_instance_id: String(body.p_host_instance_id || ''),
|
|
153
|
+
expires_at: String(body.p_expires_at || new Date(Date.now() + 60_000).toISOString())
|
|
154
|
+
});
|
|
155
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
156
|
+
res.end(JSON.stringify([{ ok: true, reason: 'ok' }]));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (req.method === 'POST' && parsed.pathname === '/auth/v1/token') {
|
|
161
|
+
assert.equal(parsed.searchParams.get('grant_type'), 'refresh_token');
|
|
162
|
+
assert.equal(String(req.headers.apikey || ''), SUPABASE_KEY);
|
|
163
|
+
assert.equal(String(req.headers.authorization || ''), `Bearer ${SUPABASE_KEY}`);
|
|
164
|
+
const body = JSON.parse(await readBody() || '{}');
|
|
165
|
+
assert.equal(body.refresh_token, REFRESH_TOKEN);
|
|
166
|
+
validAccessTokens.add(REFRESHED_ACCESS_TOKEN);
|
|
167
|
+
res.writeHead(200, {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
'Cache-Control': 'no-store'
|
|
170
|
+
});
|
|
171
|
+
res.end(JSON.stringify({
|
|
172
|
+
access_token: REFRESHED_ACCESS_TOKEN,
|
|
173
|
+
refresh_token: REFRESH_TOKEN,
|
|
174
|
+
token_type: 'bearer',
|
|
175
|
+
expires_in: 3600,
|
|
176
|
+
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
|
177
|
+
user: {
|
|
178
|
+
id: USER_ID,
|
|
179
|
+
email: 'remote-registry-follower@example.test'
|
|
180
|
+
}
|
|
181
|
+
}));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
186
|
+
res.end(JSON.stringify({ error: 'not-found' }));
|
|
187
|
+
});
|
|
188
|
+
const realtime = new WebSocketServer({ noServer: true });
|
|
189
|
+
|
|
190
|
+
realtime.on('connection', (ws, req) => {
|
|
191
|
+
realtimeClients.add(ws);
|
|
192
|
+
ws.on('message', data => {
|
|
193
|
+
const text = data.toString();
|
|
194
|
+
let message = null;
|
|
195
|
+
try {
|
|
196
|
+
message = JSON.parse(text);
|
|
197
|
+
} catch {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (message.event === 'phx_join') {
|
|
202
|
+
assert.equal(String(req.headers.apikey || ''), SUPABASE_KEY);
|
|
203
|
+
assert.ok(validAccessTokens.has(String(req.headers.authorization || '').replace(/^Bearer\s+/i, '')));
|
|
204
|
+
assert.ok(validAccessTokens.has(String(message.payload?.access_token || '')));
|
|
205
|
+
assert.deepEqual(
|
|
206
|
+
message.payload?.config?.postgres_changes?.[0],
|
|
207
|
+
{
|
|
208
|
+
event: '*',
|
|
209
|
+
schema: 'public',
|
|
210
|
+
table: 'remote_host_targets',
|
|
211
|
+
filter: `user_id=eq.${USER_ID}`
|
|
212
|
+
});
|
|
213
|
+
ws.remoteRegistryTopic = message.topic;
|
|
214
|
+
ws.send(JSON.stringify({
|
|
215
|
+
topic: message.topic,
|
|
216
|
+
event: 'phx_reply',
|
|
217
|
+
payload: {
|
|
218
|
+
status: 'ok',
|
|
219
|
+
response: {
|
|
220
|
+
postgres_changes: [
|
|
221
|
+
{
|
|
222
|
+
id: 1,
|
|
223
|
+
event: '*',
|
|
224
|
+
schema: 'public',
|
|
225
|
+
table: 'remote_host_targets'
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
ref: message.ref,
|
|
231
|
+
join_ref: message.join_ref
|
|
232
|
+
}));
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (message.event === 'heartbeat') {
|
|
237
|
+
ws.send(JSON.stringify({
|
|
238
|
+
topic: message.topic,
|
|
239
|
+
event: 'phx_reply',
|
|
240
|
+
payload: { status: 'ok', response: {} },
|
|
241
|
+
ref: message.ref
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
ws.on('close', () => realtimeClients.delete(ws));
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
server.on('upgrade', (req, socket, head) => {
|
|
249
|
+
const parsed = new URL(req.url || '/', 'http://127.0.0.1');
|
|
250
|
+
if (parsed.pathname !== '/realtime/v1/websocket') {
|
|
251
|
+
socket.destroy();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
realtime.handleUpgrade(req, socket, head, ws => {
|
|
256
|
+
realtime.emit('connection', ws, req);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
server.once('error', reject);
|
|
262
|
+
server.listen(0, '127.0.0.1', () => {
|
|
263
|
+
const address = server.address();
|
|
264
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
265
|
+
resolve({
|
|
266
|
+
url: `http://127.0.0.1:${port}`,
|
|
267
|
+
requests,
|
|
268
|
+
realtimeClients,
|
|
269
|
+
broadcastChange: (type = 'UPDATE') => {
|
|
270
|
+
for (const client of realtimeClients) {
|
|
271
|
+
if (client.readyState !== 1 || !client.remoteRegistryTopic) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
client.send(JSON.stringify({
|
|
276
|
+
topic: client.remoteRegistryTopic,
|
|
277
|
+
event: 'postgres_changes',
|
|
278
|
+
payload: {
|
|
279
|
+
ids: [1],
|
|
280
|
+
data: {
|
|
281
|
+
schema: 'public',
|
|
282
|
+
table: 'remote_host_targets',
|
|
283
|
+
commit_timestamp: new Date().toISOString(),
|
|
284
|
+
type,
|
|
285
|
+
record: getTarget(),
|
|
286
|
+
old_record: null
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
ref: null
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
stop: () => new Promise(done => {
|
|
294
|
+
for (const client of realtimeClients) {
|
|
295
|
+
try {
|
|
296
|
+
client.close();
|
|
297
|
+
} catch {
|
|
298
|
+
// best effort only
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
realtime.close(() => server.close(done));
|
|
302
|
+
})
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function spawnBridge({ bridgePort, remoteHubPort, workspacePath, authRoot, label, supabaseUrl = '', follower = false, publicHost = '' }) {
|
|
309
|
+
const child = spawn(process.execPath, ['server.js'], {
|
|
310
|
+
cwd: LOCAL_BRIDGE_DIR,
|
|
311
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
312
|
+
windowsHide: true,
|
|
313
|
+
env: {
|
|
314
|
+
...process.env,
|
|
315
|
+
BRIDGE_PORT: String(bridgePort),
|
|
316
|
+
BRIDGE_TOKEN,
|
|
317
|
+
BRIDGE_REQUIRE_TOKEN: '1',
|
|
318
|
+
MINDEXEC_REMOTE_HUB: '1',
|
|
319
|
+
REMOTE_HUB_HOST: '127.0.0.1',
|
|
320
|
+
REMOTE_HUB_PORT: String(remoteHubPort),
|
|
321
|
+
REMOTE_HUB_PUBLIC_HOST: publicHost,
|
|
322
|
+
REMOTE_HUB_PAIR_TOKEN: PAIR_TOKEN,
|
|
323
|
+
WORKSPACE_PATH: workspacePath,
|
|
324
|
+
MINDEXEC_AUTH_DATA_ROOT: authRoot,
|
|
325
|
+
MINDEXEC_REMOTE_REGISTRY_FOLLOWER: follower ? '1' : '0',
|
|
326
|
+
MINDEXEC_REMOTE_REGISTRY_POLL_MS: '10000',
|
|
327
|
+
MINDEXEC_REMOTE_REGISTRY_FAST_RETRY_MS: '250',
|
|
328
|
+
MINDEXEC_REMOTE_REGISTRY_INACTIVE_STOP_COUNT: '2',
|
|
329
|
+
MINDEXEC_REMOTE_REGISTRY_INACTIVE_GRACE_MS: '500',
|
|
330
|
+
MINDEXEC_REMOTE_REGISTRY_REALTIME_RECONNECT_MS: '250',
|
|
331
|
+
MINDEXEC_REMOTE_REGISTRY_REALTIME_DEBOUNCE_MS: '100',
|
|
332
|
+
MINDEXEC_REMOTE_HOST_TARGET_RENEW_MS: '5000',
|
|
333
|
+
SUPABASE_URL: supabaseUrl,
|
|
334
|
+
SUPABASE_KEY,
|
|
335
|
+
NO_COLOR: '1'
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
let stdout = '';
|
|
340
|
+
let stderr = '';
|
|
341
|
+
child.stdout.on('data', chunk => {
|
|
342
|
+
stdout += chunk.toString();
|
|
343
|
+
});
|
|
344
|
+
child.stderr.on('data', chunk => {
|
|
345
|
+
stderr += chunk.toString();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const exitPromise = new Promise(resolve => child.once('exit', resolve));
|
|
349
|
+
const details = () => `${label} stdout=${stdout}\n${label} stderr=${stderr}`;
|
|
350
|
+
const stop = async () => {
|
|
351
|
+
if (child.exitCode === null && !child.killed) {
|
|
352
|
+
child.kill('SIGTERM');
|
|
353
|
+
await Promise.race([exitPromise, wait(5000)]);
|
|
354
|
+
if (child.exitCode === null && !child.killed) {
|
|
355
|
+
child.kill('SIGKILL');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
baseUrl: `http://127.0.0.1:${bridgePort}`,
|
|
362
|
+
child,
|
|
363
|
+
details,
|
|
364
|
+
stop
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async function waitForBridge(bridge) {
|
|
369
|
+
return await waitFor(async () => {
|
|
370
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/status`);
|
|
371
|
+
return result.ok && result.payload?.status === 'ok' ? result.payload : null;
|
|
372
|
+
}, 30000, `bridge startup\n${bridge.details()}`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function createSessionPayload(options = {}) {
|
|
376
|
+
const accessToken = options.accessToken || ACCESS_TOKEN;
|
|
377
|
+
const refreshToken = options.refreshToken || REFRESH_TOKEN;
|
|
378
|
+
const expiresAt = options.expiresAt ?? Math.floor(Date.now() / 1000) + 3600;
|
|
379
|
+
return JSON.stringify({
|
|
380
|
+
access_token: accessToken,
|
|
381
|
+
refresh_token: refreshToken,
|
|
382
|
+
expires_at: expiresAt,
|
|
383
|
+
user: {
|
|
384
|
+
id: USER_ID,
|
|
385
|
+
email: 'remote-registry-follower@example.test'
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
async function writeSession(authRoot, options = {}) {
|
|
391
|
+
await mkdir(authRoot, { recursive: true });
|
|
392
|
+
await writeFile(path.join(authRoot, 'supabase-session.json'), createSessionPayload(options), 'utf8');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function waitForManagedAgent(bridge, managerEndpoint, label, timeoutMs = 20000) {
|
|
396
|
+
return await waitFor(async () => {
|
|
397
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/remote/agent/status`);
|
|
398
|
+
const agent = result.payload;
|
|
399
|
+
return agent?.running === true
|
|
400
|
+
&& agent?.ready === true
|
|
401
|
+
&& String(agent.manager || '') === managerEndpoint
|
|
402
|
+
? agent
|
|
403
|
+
: null;
|
|
404
|
+
}, timeoutMs, `${label} managed agent\n${bridge.details()}`);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function waitForManagedAgentRestart(bridge, managerEndpoint, previousPid, label, timeoutMs = 20000) {
|
|
408
|
+
return await waitFor(async () => {
|
|
409
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/remote/agent/status`);
|
|
410
|
+
const agent = result.payload;
|
|
411
|
+
return agent?.running === true
|
|
412
|
+
&& agent?.ready === true
|
|
413
|
+
&& String(agent.manager || '') === managerEndpoint
|
|
414
|
+
&& Number(agent.pid || 0) > 0
|
|
415
|
+
&& Number(agent.pid || 0) !== Number(previousPid || 0)
|
|
416
|
+
? agent
|
|
417
|
+
: null;
|
|
418
|
+
}, timeoutMs, `${label} managed agent restart\n${bridge.details()}`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function waitForConnectedDevice(bridge, label) {
|
|
422
|
+
return await waitFor(async () => {
|
|
423
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/remote/devices`);
|
|
424
|
+
return result.payload?.devices?.find(device => device.connected === true) || null;
|
|
425
|
+
}, 12000, `${label} connected device\n${bridge.details()}`);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function killProcess(pid) {
|
|
429
|
+
const value = Number(pid || 0);
|
|
430
|
+
assert.ok(value > 0, `expected positive pid, got ${pid}`);
|
|
431
|
+
try {
|
|
432
|
+
process.kill(value, 'SIGTERM');
|
|
433
|
+
} catch (error) {
|
|
434
|
+
if (error?.code !== 'ESRCH') {
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
async function main() {
|
|
441
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'mindexec-remote-registry-smoke-'));
|
|
442
|
+
let fakeSupabase = null;
|
|
443
|
+
let renewHost = null;
|
|
444
|
+
let hostA = null;
|
|
445
|
+
let hostB = null;
|
|
446
|
+
let client = null;
|
|
447
|
+
|
|
448
|
+
const renewHostBridgePort = await findFreePort();
|
|
449
|
+
const renewHostRemotePort = await findFreePort();
|
|
450
|
+
const hostABridgePort = await findFreePort();
|
|
451
|
+
const hostARemotePort = await findFreePort();
|
|
452
|
+
const hostBBridgePort = await findFreePort();
|
|
453
|
+
const hostBRemotePort = await findFreePort();
|
|
454
|
+
const clientBridgePort = await findFreePort();
|
|
455
|
+
const clientRemotePort = await findFreePort();
|
|
456
|
+
const stalePort = await findFreePort();
|
|
457
|
+
const renewPublicHost = '192.0.2.10';
|
|
458
|
+
const renewPublicEndpoint = `${renewPublicHost}:${renewHostRemotePort}`;
|
|
459
|
+
const hostAEndpoint = `127.0.0.1:${hostARemotePort}`;
|
|
460
|
+
const hostBEndpoint = `127.0.0.1:${hostBRemotePort}`;
|
|
461
|
+
const staleEndpoint = `127.0.0.1:${stalePort}`;
|
|
462
|
+
let currentTarget = null;
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
fakeSupabase = await startFakeSupabase(
|
|
466
|
+
() => currentTarget,
|
|
467
|
+
target => {
|
|
468
|
+
currentTarget = target;
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const renewHostAuth = path.join(tempRoot, 'auth-renew-host');
|
|
472
|
+
const hostAAuth = path.join(tempRoot, 'auth-host-a');
|
|
473
|
+
const hostBAuth = path.join(tempRoot, 'auth-host-b');
|
|
474
|
+
const clientAuth = path.join(tempRoot, 'auth-client');
|
|
475
|
+
await writeSession(renewHostAuth);
|
|
476
|
+
await writeSession(clientAuth, {
|
|
477
|
+
accessToken: EXPIRED_ACCESS_TOKEN,
|
|
478
|
+
expiresAt: Math.floor(Date.now() / 1000) - 30
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
renewHost = spawnBridge({
|
|
482
|
+
bridgePort: renewHostBridgePort,
|
|
483
|
+
remoteHubPort: renewHostRemotePort,
|
|
484
|
+
workspacePath: path.join(tempRoot, 'renew-host'),
|
|
485
|
+
authRoot: renewHostAuth,
|
|
486
|
+
label: 'renew-host',
|
|
487
|
+
supabaseUrl: fakeSupabase.url,
|
|
488
|
+
follower: true,
|
|
489
|
+
publicHost: renewPublicHost
|
|
490
|
+
});
|
|
491
|
+
await waitForBridge(renewHost);
|
|
492
|
+
|
|
493
|
+
const renewSetHost = await fetchJson(`${renewHost.baseUrl}/api/remote/host-target`, {
|
|
494
|
+
method: 'POST',
|
|
495
|
+
token: BRIDGE_TOKEN,
|
|
496
|
+
body: JSON.stringify({
|
|
497
|
+
nodeId: 'remote-registry-renew-node',
|
|
498
|
+
enabled: true,
|
|
499
|
+
leaseMs: 60000
|
|
500
|
+
})
|
|
501
|
+
});
|
|
502
|
+
assert.equal(renewSetHost.ok, true, JSON.stringify(renewSetHost.payload));
|
|
503
|
+
assert.equal(renewSetHost.payload?.ok, true, JSON.stringify(renewSetHost.payload));
|
|
504
|
+
assert.equal(renewSetHost.payload?.active, true, JSON.stringify(renewSetHost.payload));
|
|
505
|
+
assert.equal(renewSetHost.payload?.hostTargetRenew?.status, 'active', JSON.stringify(renewSetHost.payload?.hostTargetRenew));
|
|
506
|
+
assert.equal(currentTarget?.endpoint, renewPublicEndpoint, JSON.stringify(currentTarget));
|
|
507
|
+
assert.equal(currentTarget?.node_id, 'remote-registry-renew-node', JSON.stringify(currentTarget));
|
|
508
|
+
await waitFor(() => {
|
|
509
|
+
const publishCount = fakeSupabase.requests.filter(request =>
|
|
510
|
+
request.method === 'POST'
|
|
511
|
+
&& request.pathname === '/rest/v1/rpc/set_remote_host_target').length;
|
|
512
|
+
return publishCount >= 2 ? publishCount : null;
|
|
513
|
+
}, 8000, `host-target auto renew publish\n${renewHost.details()}`);
|
|
514
|
+
const beforeResumePublishCount = fakeSupabase.requests.filter(request =>
|
|
515
|
+
request.method === 'POST'
|
|
516
|
+
&& request.pathname === '/rest/v1/rpc/set_remote_host_target').length;
|
|
517
|
+
const renewResume = await fetchJson(`${renewHost.baseUrl}/api/remote/system/resume`, {
|
|
518
|
+
method: 'POST',
|
|
519
|
+
token: BRIDGE_TOKEN,
|
|
520
|
+
body: JSON.stringify({
|
|
521
|
+
driftMs: 65000
|
|
522
|
+
})
|
|
523
|
+
});
|
|
524
|
+
assert.equal(renewResume.ok, true, JSON.stringify(renewResume.payload));
|
|
525
|
+
assert.equal(renewResume.payload?.ok, true, JSON.stringify(renewResume.payload));
|
|
526
|
+
assert.equal(renewResume.payload?.remoteSystemResume?.localHost, true, JSON.stringify(renewResume.payload?.remoteSystemResume));
|
|
527
|
+
await waitFor(() => {
|
|
528
|
+
const publishCount = fakeSupabase.requests.filter(request =>
|
|
529
|
+
request.method === 'POST'
|
|
530
|
+
&& request.pathname === '/rest/v1/rpc/set_remote_host_target').length;
|
|
531
|
+
return publishCount > beforeResumePublishCount ? publishCount : null;
|
|
532
|
+
}, 8000, `host-target resume republish\n${renewHost.details()}`);
|
|
533
|
+
const renewStatus = await fetchJson(`${renewHost.baseUrl}/api/status`);
|
|
534
|
+
assert.equal(renewStatus.payload?.remoteHostTargetRenew?.status, 'active', JSON.stringify(renewStatus.payload?.remoteHostTargetRenew));
|
|
535
|
+
assert.equal(renewStatus.payload?.remoteHostTargetRenew?.endpoint, renewPublicEndpoint, JSON.stringify(renewStatus.payload?.remoteHostTargetRenew));
|
|
536
|
+
|
|
537
|
+
const renewClear = await fetchJson(`${renewHost.baseUrl}/api/remote/host-target`, {
|
|
538
|
+
method: 'DELETE',
|
|
539
|
+
token: BRIDGE_TOKEN,
|
|
540
|
+
body: JSON.stringify({
|
|
541
|
+
nodeId: 'remote-registry-renew-node'
|
|
542
|
+
})
|
|
543
|
+
});
|
|
544
|
+
assert.equal(renewClear.ok, true, JSON.stringify(renewClear.payload));
|
|
545
|
+
assert.equal(renewClear.payload?.ok, true, JSON.stringify(renewClear.payload));
|
|
546
|
+
await renewHost.stop();
|
|
547
|
+
renewHost = null;
|
|
548
|
+
|
|
549
|
+
currentTarget = createRegistryTarget({
|
|
550
|
+
endpoint: hostAEndpoint,
|
|
551
|
+
endpointCandidates: [staleEndpoint, hostAEndpoint],
|
|
552
|
+
leaseId: 'lease-a'
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
hostA = spawnBridge({
|
|
556
|
+
bridgePort: hostABridgePort,
|
|
557
|
+
remoteHubPort: hostARemotePort,
|
|
558
|
+
workspacePath: path.join(tempRoot, 'host-a'),
|
|
559
|
+
authRoot: hostAAuth,
|
|
560
|
+
label: 'host-a'
|
|
561
|
+
});
|
|
562
|
+
hostB = spawnBridge({
|
|
563
|
+
bridgePort: hostBBridgePort,
|
|
564
|
+
remoteHubPort: hostBRemotePort,
|
|
565
|
+
workspacePath: path.join(tempRoot, 'host-b'),
|
|
566
|
+
authRoot: hostBAuth,
|
|
567
|
+
label: 'host-b'
|
|
568
|
+
});
|
|
569
|
+
await waitForBridge(hostA);
|
|
570
|
+
await waitForBridge(hostB);
|
|
571
|
+
|
|
572
|
+
client = spawnBridge({
|
|
573
|
+
bridgePort: clientBridgePort,
|
|
574
|
+
remoteHubPort: clientRemotePort,
|
|
575
|
+
workspacePath: path.join(tempRoot, 'client'),
|
|
576
|
+
authRoot: clientAuth,
|
|
577
|
+
label: 'client',
|
|
578
|
+
supabaseUrl: fakeSupabase.url,
|
|
579
|
+
follower: true
|
|
580
|
+
});
|
|
581
|
+
await waitForBridge(client);
|
|
582
|
+
|
|
583
|
+
const firstAgent = await waitForManagedAgent(client, hostAEndpoint, 'host-a');
|
|
584
|
+
assert.equal(firstAgent.usingNpx, false, JSON.stringify(firstAgent));
|
|
585
|
+
assert.match(String(firstAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
586
|
+
assert.equal(firstAgent.manager, hostAEndpoint);
|
|
587
|
+
assert.equal(firstAgent.managerCandidates?.[0], staleEndpoint, JSON.stringify(firstAgent.managerCandidates));
|
|
588
|
+
assert.ok(
|
|
589
|
+
fakeSupabase.requests.some(request =>
|
|
590
|
+
request.method === 'POST'
|
|
591
|
+
&& request.pathname === '/auth/v1/token'),
|
|
592
|
+
'expected LocalBridge to refresh expired persisted Supabase session without browser involvement');
|
|
593
|
+
assert.ok(
|
|
594
|
+
fakeSupabase.requests.some(request =>
|
|
595
|
+
request.method === 'GET'
|
|
596
|
+
&& request.pathname === '/rest/v1/remote_host_targets'
|
|
597
|
+
&& request.authorization === `Bearer ${REFRESHED_ACCESS_TOKEN}`),
|
|
598
|
+
'expected registry read to use refreshed access token');
|
|
599
|
+
await waitForConnectedDevice(hostA, 'host-a');
|
|
600
|
+
const firstStatus = await fetchJson(`${client.baseUrl}/api/status`);
|
|
601
|
+
assert.equal(firstStatus.payload?.remoteRegistryRealtime?.subscribed, true, JSON.stringify(firstStatus.payload?.remoteRegistryRealtime));
|
|
602
|
+
assert.ok(fakeSupabase.realtimeClients.size >= 1, 'expected LocalBridge realtime watcher to connect');
|
|
603
|
+
const firstPid = Number(firstAgent.pid || 0);
|
|
604
|
+
assert.ok(firstPid > 0, JSON.stringify(firstAgent));
|
|
605
|
+
|
|
606
|
+
const clientResume = await fetchJson(`${client.baseUrl}/api/remote/system/resume`, {
|
|
607
|
+
method: 'POST',
|
|
608
|
+
token: BRIDGE_TOKEN,
|
|
609
|
+
body: JSON.stringify({
|
|
610
|
+
driftMs: 65000
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
assert.equal(clientResume.ok, true, JSON.stringify(clientResume.payload));
|
|
614
|
+
assert.equal(clientResume.payload?.ok, true, JSON.stringify(clientResume.payload));
|
|
615
|
+
assert.equal(clientResume.payload?.remoteSystemResume?.registryAgentRestarted, true, JSON.stringify(clientResume.payload?.remoteSystemResume));
|
|
616
|
+
const resumedAgent = await waitForManagedAgentRestart(client, hostAEndpoint, firstPid, 'host-a after resume', 12000);
|
|
617
|
+
assert.equal(resumedAgent.usingNpx, false, JSON.stringify(resumedAgent));
|
|
618
|
+
assert.match(String(resumedAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
619
|
+
assert.equal(resumedAgent.leaseId, 'lease-a');
|
|
620
|
+
await waitForConnectedDevice(hostA, 'host-a after resume');
|
|
621
|
+
|
|
622
|
+
currentTarget = createRegistryTarget({
|
|
623
|
+
endpoint: hostBEndpoint,
|
|
624
|
+
endpointCandidates: [hostBEndpoint],
|
|
625
|
+
leaseId: 'lease-b'
|
|
626
|
+
});
|
|
627
|
+
fakeSupabase.broadcastChange('UPDATE');
|
|
628
|
+
|
|
629
|
+
const secondAgent = await waitForManagedAgent(client, hostBEndpoint, 'host-b', 9000);
|
|
630
|
+
assert.equal(secondAgent.usingNpx, false, JSON.stringify(secondAgent));
|
|
631
|
+
assert.match(String(secondAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
632
|
+
assert.equal(secondAgent.manager, hostBEndpoint);
|
|
633
|
+
assert.equal(secondAgent.leaseId, 'lease-b');
|
|
634
|
+
await waitForConnectedDevice(hostB, 'host-b');
|
|
635
|
+
|
|
636
|
+
await wait(250);
|
|
637
|
+
currentTarget = null;
|
|
638
|
+
fakeSupabase.broadcastChange('DELETE');
|
|
639
|
+
await waitFor(async () => {
|
|
640
|
+
const status = await fetchJson(`${client.baseUrl}/api/status`);
|
|
641
|
+
const agent = await fetchJson(`${client.baseUrl}/api/remote/agent/status`);
|
|
642
|
+
return status.payload?.remoteRegistryFollower?.reason === 'no-active-target-agent-kept'
|
|
643
|
+
&& agent.payload?.running === true
|
|
644
|
+
&& String(agent.payload?.manager || '') === hostBEndpoint
|
|
645
|
+
? { status: status.payload.remoteRegistryFollower, agent: agent.payload }
|
|
646
|
+
: null;
|
|
647
|
+
}, 4000, `transient no-active-target keeps managed agent\n${client.details()}`);
|
|
648
|
+
|
|
649
|
+
currentTarget = createRegistryTarget({
|
|
650
|
+
endpoint: hostBEndpoint,
|
|
651
|
+
endpointCandidates: [hostBEndpoint],
|
|
652
|
+
leaseId: 'lease-b'
|
|
653
|
+
});
|
|
654
|
+
fakeSupabase.broadcastChange('INSERT');
|
|
655
|
+
const restoredAgent = await waitForManagedAgent(client, hostBEndpoint, 'host-b after transient missing target', 9000);
|
|
656
|
+
assert.equal(Number(restoredAgent.pid || 0), Number(secondAgent.pid || 0), JSON.stringify(restoredAgent));
|
|
657
|
+
|
|
658
|
+
const missingAuthWake = await fetchJson(`${client.baseUrl}/api/auth/session`, {
|
|
659
|
+
method: 'DELETE',
|
|
660
|
+
token: BRIDGE_TOKEN
|
|
661
|
+
});
|
|
662
|
+
assert.equal(missingAuthWake.ok, true, JSON.stringify(missingAuthWake.payload));
|
|
663
|
+
await waitFor(async () => {
|
|
664
|
+
const status = await fetchJson(`${client.baseUrl}/api/status`);
|
|
665
|
+
const agent = await fetchJson(`${client.baseUrl}/api/remote/agent/status`);
|
|
666
|
+
return status.payload?.remoteRegistryFollower?.reason === 'registry-not-authenticated-agent-kept'
|
|
667
|
+
&& status.payload?.remoteRegistryFollower?.agentKept === true
|
|
668
|
+
&& agent.payload?.running === true
|
|
669
|
+
&& String(agent.payload?.manager || '') === hostBEndpoint
|
|
670
|
+
&& Number(agent.payload?.pid || 0) === Number(secondAgent.pid || 0)
|
|
671
|
+
? { status: status.payload.remoteRegistryFollower, agent: agent.payload }
|
|
672
|
+
: null;
|
|
673
|
+
}, 4000, `transient missing auth keeps managed agent\n${client.details()}`);
|
|
674
|
+
|
|
675
|
+
const restoredAuthWake = await fetchJson(`${client.baseUrl}/api/auth/session`, {
|
|
676
|
+
method: 'POST',
|
|
677
|
+
token: BRIDGE_TOKEN,
|
|
678
|
+
body: JSON.stringify({
|
|
679
|
+
content: createSessionPayload()
|
|
680
|
+
})
|
|
681
|
+
});
|
|
682
|
+
assert.equal(restoredAuthWake.ok, true, JSON.stringify(restoredAuthWake.payload));
|
|
683
|
+
const authRestoredAgent = await waitForManagedAgent(client, hostBEndpoint, 'host-b after transient missing auth', 9000);
|
|
684
|
+
assert.equal(Number(authRestoredAgent.pid || 0), Number(secondAgent.pid || 0), JSON.stringify(authRestoredAgent));
|
|
685
|
+
|
|
686
|
+
const secondPid = Number(secondAgent.pid || 0);
|
|
687
|
+
killProcess(secondPid);
|
|
688
|
+
const restartedAgent = await waitForManagedAgentRestart(client, hostBEndpoint, secondPid, 'host-b', 12000);
|
|
689
|
+
assert.equal(restartedAgent.usingNpx, false, JSON.stringify(restartedAgent));
|
|
690
|
+
assert.match(String(restartedAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
691
|
+
assert.equal(restartedAgent.leaseId, 'lease-b');
|
|
692
|
+
await waitForConnectedDevice(hostB, 'host-b after restart');
|
|
693
|
+
|
|
694
|
+
currentTarget = {
|
|
695
|
+
...currentTarget,
|
|
696
|
+
active: false,
|
|
697
|
+
expires_at: new Date(Date.now() - 1000).toISOString()
|
|
698
|
+
};
|
|
699
|
+
fakeSupabase.broadcastChange('UPDATE');
|
|
700
|
+
await wait(700);
|
|
701
|
+
fakeSupabase.broadcastChange('UPDATE');
|
|
702
|
+
|
|
703
|
+
await waitFor(async () => {
|
|
704
|
+
const status = await fetchJson(`${client.baseUrl}/api/status`);
|
|
705
|
+
const agent = await fetchJson(`${client.baseUrl}/api/remote/agent/status`);
|
|
706
|
+
return status.payload?.remoteRegistryFollower?.reason === 'registry-inactive-agent-kept'
|
|
707
|
+
&& status.payload?.remoteRegistryFollower?.agentKept === true
|
|
708
|
+
&& status.payload?.remoteRegistryFollower?.dataPlaneReady === true
|
|
709
|
+
&& agent.payload?.running === true
|
|
710
|
+
&& agent.payload?.ready === true
|
|
711
|
+
&& String(agent.payload?.manager || '') === hostBEndpoint
|
|
712
|
+
&& Number(agent.payload?.pid || 0) === Number(restartedAgent.pid || 0)
|
|
713
|
+
? { status: status.payload.remoteRegistryFollower, agent: agent.payload }
|
|
714
|
+
: null;
|
|
715
|
+
}, 9000, `registry inactive keeps ready data-plane agent\n${client.details()}`);
|
|
716
|
+
|
|
717
|
+
const inactivePid = Number(restartedAgent.pid || 0);
|
|
718
|
+
killProcess(inactivePid);
|
|
719
|
+
const recoveredInactiveAgent = await waitForManagedAgentRestart(
|
|
720
|
+
client,
|
|
721
|
+
hostBEndpoint,
|
|
722
|
+
inactivePid,
|
|
723
|
+
'host-b after inactive target recovery',
|
|
724
|
+
12000);
|
|
725
|
+
assert.equal(recoveredInactiveAgent.usingNpx, false, JSON.stringify(recoveredInactiveAgent));
|
|
726
|
+
assert.match(String(recoveredInactiveAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
727
|
+
assert.equal(recoveredInactiveAgent.leaseId, 'lease-b');
|
|
728
|
+
await waitForConnectedDevice(hostB, 'host-b after inactive target recovery');
|
|
729
|
+
await waitFor(async () => {
|
|
730
|
+
const status = await fetchJson(`${client.baseUrl}/api/status`);
|
|
731
|
+
return status.payload?.remoteRegistryFollower?.reason === 'registry-inactive-agent-recovered'
|
|
732
|
+
&& String(status.payload?.remoteRegistryFollower?.targetEndpoint || '') === hostBEndpoint
|
|
733
|
+
? status.payload.remoteRegistryFollower
|
|
734
|
+
: null;
|
|
735
|
+
}, 4000, `inactive target recovered managed agent\n${client.details()}`);
|
|
736
|
+
const finalStatus = await fetchJson(`${client.baseUrl}/api/status`);
|
|
737
|
+
assert.ok(finalStatus.payload?.remoteRegistryRealtime?.changes >= 2, JSON.stringify(finalStatus.payload?.remoteRegistryRealtime));
|
|
738
|
+
assert.ok(finalStatus.payload?.remoteRegistryRealtime?.wakeups >= 2, JSON.stringify(finalStatus.payload?.remoteRegistryRealtime));
|
|
739
|
+
|
|
740
|
+
assert.ok(fakeSupabase.requests.length >= 2, JSON.stringify(fakeSupabase.requests));
|
|
741
|
+
console.log('Remote registry follower smoke OK');
|
|
742
|
+
} finally {
|
|
743
|
+
if (client) await client.stop();
|
|
744
|
+
if (hostB) await hostB.stop();
|
|
745
|
+
if (hostA) await hostA.stop();
|
|
746
|
+
if (renewHost) await renewHost.stop();
|
|
747
|
+
if (fakeSupabase) await fakeSupabase.stop();
|
|
748
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
await main();
|