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,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
6
|
+
import net from 'node:net';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const BRIDGE_TOKEN = 'auth-session-smoke-token';
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const bridgeRoot = path.resolve(__dirname, '..');
|
|
14
|
+
|
|
15
|
+
function wait(ms) {
|
|
16
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function findFreePort() {
|
|
20
|
+
return await new Promise((resolve, reject) => {
|
|
21
|
+
const server = net.createServer();
|
|
22
|
+
server.unref();
|
|
23
|
+
server.once('error', reject);
|
|
24
|
+
server.listen(0, '127.0.0.1', () => {
|
|
25
|
+
const address = server.address();
|
|
26
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
27
|
+
server.close(() => resolve(port));
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function fetchJson(url, options = {}) {
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
...options,
|
|
35
|
+
headers: {
|
|
36
|
+
...(options.body ? { 'Content-Type': 'application/json' } : {}),
|
|
37
|
+
...(options.token ? { 'X-Bridge-Token': options.token } : {}),
|
|
38
|
+
...(options.headers || {})
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let payload = null;
|
|
43
|
+
try {
|
|
44
|
+
payload = await response.json();
|
|
45
|
+
} catch {
|
|
46
|
+
// Ignore non-JSON responses.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
status: response.status,
|
|
51
|
+
ok: response.ok,
|
|
52
|
+
payload
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function spawnBridge({ bridgePort, workspacePath, authDataRoot }) {
|
|
57
|
+
const child = spawn(process.execPath, ['server.js'], {
|
|
58
|
+
cwd: bridgeRoot,
|
|
59
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
60
|
+
windowsHide: true,
|
|
61
|
+
env: {
|
|
62
|
+
...process.env,
|
|
63
|
+
BRIDGE_PORT: String(bridgePort),
|
|
64
|
+
BRIDGE_TOKEN,
|
|
65
|
+
BRIDGE_REQUIRE_TOKEN: '1',
|
|
66
|
+
WORKSPACE_PATH: workspacePath,
|
|
67
|
+
MINDEXEC_AUTH_DATA_ROOT: authDataRoot,
|
|
68
|
+
MINDEXEC_REMOTE_HUB: '0',
|
|
69
|
+
MINDEXEC_REMOTE_REGISTRY_FOLLOWER: '0',
|
|
70
|
+
NO_COLOR: '1'
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
let stdout = '';
|
|
75
|
+
let stderr = '';
|
|
76
|
+
child.stdout.on('data', chunk => {
|
|
77
|
+
stdout += chunk.toString();
|
|
78
|
+
});
|
|
79
|
+
child.stderr.on('data', chunk => {
|
|
80
|
+
stderr += chunk.toString();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const details = () => `stdout=${stdout}\nstderr=${stderr}`;
|
|
84
|
+
const stop = async () => {
|
|
85
|
+
if (!child.killed) {
|
|
86
|
+
child.kill();
|
|
87
|
+
}
|
|
88
|
+
await Promise.race([
|
|
89
|
+
new Promise(resolve => child.once('exit', resolve)),
|
|
90
|
+
wait(3000)
|
|
91
|
+
]);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
child,
|
|
96
|
+
details,
|
|
97
|
+
stop
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function waitForBridge(baseUrl, details) {
|
|
102
|
+
const startedAt = Date.now();
|
|
103
|
+
while (Date.now() - startedAt < 30000) {
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetchJson(`${baseUrl}/api/status`);
|
|
106
|
+
if (response.ok && response.payload?.status) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
// Bridge is still starting.
|
|
111
|
+
}
|
|
112
|
+
await wait(100);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
throw new Error(`Timed out waiting for LocalBridge.\n${details()}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function withBridge({ workspacePath, authDataRoot }, action) {
|
|
119
|
+
const bridgePort = await findFreePort();
|
|
120
|
+
const bridge = spawnBridge({ bridgePort, workspacePath, authDataRoot });
|
|
121
|
+
const baseUrl = `http://127.0.0.1:${bridgePort}`;
|
|
122
|
+
try {
|
|
123
|
+
await waitForBridge(baseUrl, bridge.details);
|
|
124
|
+
await action(baseUrl);
|
|
125
|
+
} finally {
|
|
126
|
+
await bridge.stop();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'mindexec-auth-session-smoke-'));
|
|
131
|
+
try {
|
|
132
|
+
const authDataRoot = path.join(tempRoot, 'stable-auth');
|
|
133
|
+
const workspaceA = path.join(tempRoot, 'workspace-a');
|
|
134
|
+
const workspaceB = path.join(tempRoot, 'workspace-b');
|
|
135
|
+
await mkdir(workspaceA, { recursive: true });
|
|
136
|
+
await mkdir(workspaceB, { recursive: true });
|
|
137
|
+
|
|
138
|
+
const sessionPayload = JSON.stringify({
|
|
139
|
+
access_token: 'access-token-a',
|
|
140
|
+
refresh_token: 'refresh-token-a',
|
|
141
|
+
expires_at: Math.floor(Date.now() / 1000) + 600,
|
|
142
|
+
user: {
|
|
143
|
+
id: 'user-a',
|
|
144
|
+
email: 'auth-smoke@example.com'
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
let expectedStablePayload = sessionPayload;
|
|
148
|
+
|
|
149
|
+
function makeTimedSessionPayload(accessToken, refreshToken, expiresInSeconds) {
|
|
150
|
+
return JSON.stringify({
|
|
151
|
+
access_token: accessToken,
|
|
152
|
+
refresh_token: refreshToken,
|
|
153
|
+
expires_at: Math.floor(Date.now() / 1000) + expiresInSeconds,
|
|
154
|
+
user: {
|
|
155
|
+
id: 'user-a',
|
|
156
|
+
email: 'auth-smoke@example.com'
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await withBridge({ workspacePath: workspaceA, authDataRoot }, async (baseUrl) => {
|
|
162
|
+
const unauthorized = await fetchJson(`${baseUrl}/api/auth/session`);
|
|
163
|
+
assert.equal(unauthorized.status, 401);
|
|
164
|
+
|
|
165
|
+
const missing = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
166
|
+
assert.equal(missing.status, 404);
|
|
167
|
+
|
|
168
|
+
const invalid = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
token: BRIDGE_TOKEN,
|
|
171
|
+
body: JSON.stringify({ content: 'not-json' })
|
|
172
|
+
});
|
|
173
|
+
assert.equal(invalid.status, 400);
|
|
174
|
+
|
|
175
|
+
const saved = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
token: BRIDGE_TOKEN,
|
|
178
|
+
body: JSON.stringify({ content: sessionPayload })
|
|
179
|
+
});
|
|
180
|
+
assert.equal(saved.status, 200);
|
|
181
|
+
assert.equal(saved.payload?.success, true);
|
|
182
|
+
|
|
183
|
+
const loaded = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
184
|
+
assert.equal(loaded.status, 200);
|
|
185
|
+
assert.equal(loaded.payload?.content, sessionPayload);
|
|
186
|
+
assert.equal(loaded.payload?.source, 'stable');
|
|
187
|
+
|
|
188
|
+
const newerPayload = makeTimedSessionPayload('access-token-newer', 'refresh-token-newer', 3600);
|
|
189
|
+
const newerSaved = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
token: BRIDGE_TOKEN,
|
|
192
|
+
body: JSON.stringify({ content: newerPayload })
|
|
193
|
+
});
|
|
194
|
+
assert.equal(newerSaved.status, 200);
|
|
195
|
+
|
|
196
|
+
const staleBrowserPayload = makeTimedSessionPayload('access-token-stale-browser', 'refresh-token-stale-browser', 120);
|
|
197
|
+
const staleSaved = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
198
|
+
method: 'POST',
|
|
199
|
+
token: BRIDGE_TOKEN,
|
|
200
|
+
body: JSON.stringify({ content: staleBrowserPayload })
|
|
201
|
+
});
|
|
202
|
+
assert.equal(staleSaved.status, 200);
|
|
203
|
+
|
|
204
|
+
const afterStale = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
205
|
+
assert.equal(afterStale.status, 200);
|
|
206
|
+
assert.equal(JSON.parse(afterStale.payload?.content || '{}').access_token, 'access-token-newer');
|
|
207
|
+
|
|
208
|
+
const newestPayload = makeTimedSessionPayload('access-token-newest', 'refresh-token-newest', 7200);
|
|
209
|
+
const newestSaved = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
210
|
+
method: 'POST',
|
|
211
|
+
token: BRIDGE_TOKEN,
|
|
212
|
+
body: JSON.stringify({ content: newestPayload })
|
|
213
|
+
});
|
|
214
|
+
assert.equal(newestSaved.status, 200);
|
|
215
|
+
expectedStablePayload = newestPayload;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await withBridge({ workspacePath: workspaceB, authDataRoot }, async (baseUrl) => {
|
|
219
|
+
const loaded = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
220
|
+
assert.equal(loaded.status, 200);
|
|
221
|
+
assert.equal(loaded.payload?.content, expectedStablePayload);
|
|
222
|
+
assert.equal(loaded.payload?.source, 'stable');
|
|
223
|
+
|
|
224
|
+
const deleted = await fetchJson(`${baseUrl}/api/auth/session`, {
|
|
225
|
+
method: 'DELETE',
|
|
226
|
+
token: BRIDGE_TOKEN
|
|
227
|
+
});
|
|
228
|
+
assert.equal(deleted.status, 200);
|
|
229
|
+
assert.equal(deleted.payload?.success, true);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const legacyPayload = JSON.stringify({
|
|
233
|
+
access_token: 'legacy-access-token',
|
|
234
|
+
refresh_token: 'legacy-refresh-token',
|
|
235
|
+
user: {
|
|
236
|
+
id: 'legacy-user',
|
|
237
|
+
email: 'legacy-auth-smoke@example.com'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const legacyPath = path.join(workspaceB, '.mindexec', 'auth', 'supabase-session.json');
|
|
241
|
+
await mkdir(path.dirname(legacyPath), { recursive: true });
|
|
242
|
+
await writeFile(legacyPath, legacyPayload, 'utf8');
|
|
243
|
+
|
|
244
|
+
await withBridge({ workspacePath: workspaceB, authDataRoot }, async (baseUrl) => {
|
|
245
|
+
const migrated = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
246
|
+
assert.equal(migrated.status, 200);
|
|
247
|
+
assert.equal(migrated.payload?.content, legacyPayload);
|
|
248
|
+
assert.equal(migrated.payload?.source, 'legacy-workspace');
|
|
249
|
+
assert.equal(migrated.payload?.migrated, true);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
await withBridge({ workspacePath: workspaceA, authDataRoot }, async (baseUrl) => {
|
|
253
|
+
const loaded = await fetchJson(`${baseUrl}/api/auth/session`, { token: BRIDGE_TOKEN });
|
|
254
|
+
assert.equal(loaded.status, 200);
|
|
255
|
+
assert.equal(loaded.payload?.content, legacyPayload);
|
|
256
|
+
assert.equal(loaded.payload?.source, 'stable');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
console.log('Auth session persistence smoke OK');
|
|
260
|
+
} finally {
|
|
261
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
262
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
6
|
+
import net from 'node:net';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const BRIDGE_TOKEN = 'remote-agent-managed-smoke-token';
|
|
12
|
+
const PAIR_TOKEN = 'remote-agent-managed-pair-token';
|
|
13
|
+
const LEASE_ID = 'remote-agent-managed-smoke-lease';
|
|
14
|
+
const LOCAL_BRIDGE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
15
|
+
|
|
16
|
+
function wait(ms) {
|
|
17
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function findFreePort() {
|
|
21
|
+
return await new Promise((resolve, reject) => {
|
|
22
|
+
const server = net.createServer();
|
|
23
|
+
server.unref();
|
|
24
|
+
server.once('error', reject);
|
|
25
|
+
server.listen(0, '127.0.0.1', () => {
|
|
26
|
+
const address = server.address();
|
|
27
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
28
|
+
server.close(() => resolve(port));
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function fetchJson(url, options = {}) {
|
|
34
|
+
const response = await fetch(url, {
|
|
35
|
+
...options,
|
|
36
|
+
headers: {
|
|
37
|
+
...(options.body ? { 'Content-Type': 'application/json' } : {}),
|
|
38
|
+
'X-Bridge-Token': options.token || BRIDGE_TOKEN,
|
|
39
|
+
...(options.headers || {})
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
let payload = null;
|
|
44
|
+
try {
|
|
45
|
+
payload = await response.json();
|
|
46
|
+
} catch {
|
|
47
|
+
// Some failure responses may be empty.
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
status: response.status,
|
|
52
|
+
ok: response.ok,
|
|
53
|
+
payload
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function waitFor(predicate, timeoutMs = 30000, label = 'condition') {
|
|
58
|
+
const startedAt = Date.now();
|
|
59
|
+
let lastError = null;
|
|
60
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
61
|
+
try {
|
|
62
|
+
const value = await predicate();
|
|
63
|
+
if (value) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
lastError = err;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await wait(100);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
throw new Error(`Timed out waiting for ${label}${lastError ? `: ${lastError.message}` : ''}.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function spawnBridge({ bridgePort, remoteHubPort, workspacePath, label }) {
|
|
77
|
+
const child = spawn(process.execPath, ['server.js'], {
|
|
78
|
+
cwd: LOCAL_BRIDGE_DIR,
|
|
79
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
+
windowsHide: true,
|
|
81
|
+
env: {
|
|
82
|
+
...process.env,
|
|
83
|
+
BRIDGE_PORT: String(bridgePort),
|
|
84
|
+
BRIDGE_TOKEN,
|
|
85
|
+
BRIDGE_REQUIRE_TOKEN: '1',
|
|
86
|
+
MINDEXEC_REMOTE_HUB: '1',
|
|
87
|
+
REMOTE_HUB_HOST: '127.0.0.1',
|
|
88
|
+
REMOTE_HUB_PORT: String(remoteHubPort),
|
|
89
|
+
REMOTE_HUB_PAIR_TOKEN: PAIR_TOKEN,
|
|
90
|
+
WORKSPACE_PATH: workspacePath,
|
|
91
|
+
NO_COLOR: '1'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
let stdout = '';
|
|
96
|
+
let stderr = '';
|
|
97
|
+
child.stdout.on('data', chunk => {
|
|
98
|
+
stdout += chunk.toString();
|
|
99
|
+
});
|
|
100
|
+
child.stderr.on('data', chunk => {
|
|
101
|
+
stderr += chunk.toString();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const exitPromise = new Promise(resolve => child.once('exit', resolve));
|
|
105
|
+
const details = () => `${label} stdout=${stdout}\n${label} stderr=${stderr}`;
|
|
106
|
+
const stop = async () => {
|
|
107
|
+
if (child.exitCode === null && !child.killed) {
|
|
108
|
+
child.kill('SIGTERM');
|
|
109
|
+
await Promise.race([
|
|
110
|
+
exitPromise,
|
|
111
|
+
wait(5000)
|
|
112
|
+
]);
|
|
113
|
+
if (child.exitCode === null && !child.killed) {
|
|
114
|
+
child.kill('SIGKILL');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
baseUrl: `http://127.0.0.1:${bridgePort}`,
|
|
121
|
+
child,
|
|
122
|
+
details,
|
|
123
|
+
stop
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function startHangingRemoteManager(port) {
|
|
128
|
+
const sockets = new Set();
|
|
129
|
+
const server = net.createServer(socket => {
|
|
130
|
+
sockets.add(socket);
|
|
131
|
+
socket.on('close', () => sockets.delete(socket));
|
|
132
|
+
socket.on('error', () => sockets.delete(socket));
|
|
133
|
+
});
|
|
134
|
+
server.unref();
|
|
135
|
+
await new Promise((resolve, reject) => {
|
|
136
|
+
server.once('error', reject);
|
|
137
|
+
server.listen(port, '127.0.0.1', resolve);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
endpoint: `127.0.0.1:${port}`,
|
|
142
|
+
async stop() {
|
|
143
|
+
for (const socket of sockets) {
|
|
144
|
+
socket.destroy();
|
|
145
|
+
}
|
|
146
|
+
await new Promise(resolve => server.close(resolve));
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function waitForBridge(bridge) {
|
|
152
|
+
return await waitFor(async () => {
|
|
153
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/status`);
|
|
154
|
+
return result.ok && result.payload?.status === 'ok' ? result.payload : null;
|
|
155
|
+
}, 30000, `bridge startup\n${bridge.details()}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function connectManagedAgent(clientBridge, managerEndpoint, staleEndpoint) {
|
|
159
|
+
const result = await fetchJson(`${clientBridge.baseUrl}/api/remote/agent/connect`, {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
body: JSON.stringify({
|
|
162
|
+
managerCandidates: [staleEndpoint, managerEndpoint],
|
|
163
|
+
pairToken: PAIR_TOKEN,
|
|
164
|
+
leaseId: LEASE_ID,
|
|
165
|
+
nodeId: 'remote-agent-managed-smoke-node',
|
|
166
|
+
engine: 'auto',
|
|
167
|
+
source: 'local-bridge-registry'
|
|
168
|
+
})
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
assert.equal(result.ok, true, JSON.stringify(result.payload));
|
|
172
|
+
assert.equal(result.payload?.ok, true, JSON.stringify(result.payload));
|
|
173
|
+
return result.payload.agent;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function main() {
|
|
177
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'mindexec-remote-managed-smoke-'));
|
|
178
|
+
const hostWorkspace = path.join(tempRoot, 'host');
|
|
179
|
+
const clientWorkspace = path.join(tempRoot, 'client');
|
|
180
|
+
const hostBridgePort = await findFreePort();
|
|
181
|
+
const hostRemotePort = await findFreePort();
|
|
182
|
+
const clientBridgePort = await findFreePort();
|
|
183
|
+
const clientRemotePort = await findFreePort();
|
|
184
|
+
const stalePort = await findFreePort();
|
|
185
|
+
const managerEndpoint = `127.0.0.1:${hostRemotePort}`;
|
|
186
|
+
let hangingManager = null;
|
|
187
|
+
const staleEndpoint = `127.0.0.1:${stalePort}`;
|
|
188
|
+
|
|
189
|
+
let hostBridge = null;
|
|
190
|
+
let clientBridge = null;
|
|
191
|
+
try {
|
|
192
|
+
hangingManager = await startHangingRemoteManager(stalePort);
|
|
193
|
+
hostBridge = spawnBridge({
|
|
194
|
+
bridgePort: hostBridgePort,
|
|
195
|
+
remoteHubPort: hostRemotePort,
|
|
196
|
+
workspacePath: hostWorkspace,
|
|
197
|
+
label: 'host'
|
|
198
|
+
});
|
|
199
|
+
await waitForBridge(hostBridge);
|
|
200
|
+
|
|
201
|
+
clientBridge = spawnBridge({
|
|
202
|
+
bridgePort: clientBridgePort,
|
|
203
|
+
remoteHubPort: clientRemotePort,
|
|
204
|
+
workspacePath: clientWorkspace,
|
|
205
|
+
label: 'client-1'
|
|
206
|
+
});
|
|
207
|
+
await waitForBridge(clientBridge);
|
|
208
|
+
|
|
209
|
+
const firstConnectStartedAt = Date.now();
|
|
210
|
+
const firstAgent = await connectManagedAgent(clientBridge, managerEndpoint, staleEndpoint);
|
|
211
|
+
const firstConnectMs = Date.now() - firstConnectStartedAt;
|
|
212
|
+
assert.equal(firstAgent.running, true, JSON.stringify(firstAgent));
|
|
213
|
+
assert.equal(firstAgent.ready, true, JSON.stringify(firstAgent));
|
|
214
|
+
assert.equal(firstAgent.usingNpx, false, JSON.stringify(firstAgent));
|
|
215
|
+
assert.match(String(firstAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
216
|
+
assert.ok(
|
|
217
|
+
firstConnectMs < 4500,
|
|
218
|
+
`managed RemoteAgent must race slow endpoint candidates instead of waiting sequentially, got ${firstConnectMs}ms`);
|
|
219
|
+
|
|
220
|
+
const connectedDevice = await waitFor(async () => {
|
|
221
|
+
const result = await fetchJson(`${hostBridge.baseUrl}/api/remote/devices`);
|
|
222
|
+
return result.payload?.devices?.find(device => device.connected === true) || null;
|
|
223
|
+
}, 10000, `host device registration\n${hostBridge.details()}\n${clientBridge.details()}`);
|
|
224
|
+
assert.equal(connectedDevice.capabilities?.binaryFrames, true);
|
|
225
|
+
|
|
226
|
+
await clientBridge.stop();
|
|
227
|
+
clientBridge = null;
|
|
228
|
+
|
|
229
|
+
const cachePath = path.join(clientWorkspace, '.mindexec', 'cache', 'remote-agent-recent-managers.json');
|
|
230
|
+
const cache = JSON.parse(await readFile(cachePath, 'utf8'));
|
|
231
|
+
assert.equal(cache.version, 1);
|
|
232
|
+
assert.equal(cache.entries?.[0]?.endpoint, managerEndpoint, JSON.stringify(cache));
|
|
233
|
+
|
|
234
|
+
clientBridge = spawnBridge({
|
|
235
|
+
bridgePort: clientBridgePort,
|
|
236
|
+
remoteHubPort: clientRemotePort,
|
|
237
|
+
workspacePath: clientWorkspace,
|
|
238
|
+
label: 'client-2'
|
|
239
|
+
});
|
|
240
|
+
await waitForBridge(clientBridge);
|
|
241
|
+
|
|
242
|
+
const secondAgent = await connectManagedAgent(clientBridge, managerEndpoint, staleEndpoint);
|
|
243
|
+
assert.equal(secondAgent.running, true, JSON.stringify(secondAgent));
|
|
244
|
+
assert.equal(secondAgent.ready, true, JSON.stringify(secondAgent));
|
|
245
|
+
assert.equal(secondAgent.usingNpx, false, JSON.stringify(secondAgent));
|
|
246
|
+
assert.match(String(secondAgent.launcher || ''), /mindexec-remote-fast/i);
|
|
247
|
+
assert.equal(secondAgent.managerCandidates?.[0], managerEndpoint, JSON.stringify(secondAgent.managerCandidates));
|
|
248
|
+
assert.equal(secondAgent.managerCandidates?.[1], staleEndpoint, JSON.stringify(secondAgent.managerCandidates));
|
|
249
|
+
|
|
250
|
+
const staleReport = await fetchJson(`${clientBridge.baseUrl}/api/remote/agent/sync-report`, {
|
|
251
|
+
method: 'POST',
|
|
252
|
+
body: JSON.stringify({
|
|
253
|
+
ok: false,
|
|
254
|
+
attempted: true,
|
|
255
|
+
disconnected: true,
|
|
256
|
+
authenticated: true,
|
|
257
|
+
reason: 'agent-disconnected',
|
|
258
|
+
targetActive: true,
|
|
259
|
+
targetEndpoint: managerEndpoint,
|
|
260
|
+
targetEndpointCandidates: [managerEndpoint, staleEndpoint],
|
|
261
|
+
targetLeaseId: LEASE_ID,
|
|
262
|
+
targetNodeId: 'remote-agent-managed-smoke-node'
|
|
263
|
+
})
|
|
264
|
+
});
|
|
265
|
+
assert.equal(staleReport.ok, true, JSON.stringify(staleReport.payload));
|
|
266
|
+
|
|
267
|
+
const staleState = await fetchJson(`${clientBridge.baseUrl}/api/remote/agent/status`);
|
|
268
|
+
assert.equal(staleState.payload?.needsReconnect, true, JSON.stringify(staleState.payload));
|
|
269
|
+
|
|
270
|
+
const thirdAgent = await connectManagedAgent(clientBridge, managerEndpoint, staleEndpoint);
|
|
271
|
+
assert.equal(thirdAgent.running, true, JSON.stringify(thirdAgent));
|
|
272
|
+
assert.equal(thirdAgent.ready, true, JSON.stringify(thirdAgent));
|
|
273
|
+
assert.equal(thirdAgent.needsReconnect, false, JSON.stringify(thirdAgent));
|
|
274
|
+
assert.notEqual(thirdAgent.pid, secondAgent.pid, `stale registry-owned RemoteAgent should be restarted, second=${secondAgent.pid}, third=${thirdAgent.pid}`);
|
|
275
|
+
|
|
276
|
+
console.log('RemoteAgent managed supervisor smoke OK');
|
|
277
|
+
} finally {
|
|
278
|
+
if (hangingManager) {
|
|
279
|
+
await hangingManager.stop();
|
|
280
|
+
}
|
|
281
|
+
if (clientBridge) {
|
|
282
|
+
await clientBridge.stop();
|
|
283
|
+
}
|
|
284
|
+
if (hostBridge) {
|
|
285
|
+
await hostBridge.stop();
|
|
286
|
+
}
|
|
287
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
await main();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { execFile } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
|
|
9
|
+
const REQUIRED_REMOTE_FAST_FILES = [
|
|
10
|
+
'remote-fast/win-x64/mindexec-remote-fast.exe',
|
|
11
|
+
'remote-fast/win-x64/mindexec-remote-fast.dll',
|
|
12
|
+
'remote-fast/win-x64/mindexec-remote-fast.runtimeconfig.json',
|
|
13
|
+
'remote-fast/osx-arm64/mindexec-remote-fast',
|
|
14
|
+
'remote-fast/osx-arm64/mindexec-remote-fast.dll',
|
|
15
|
+
'remote-fast/osx-arm64/mindexec-remote-fast.runtimeconfig.json',
|
|
16
|
+
'remote-fast/osx-x64/mindexec-remote-fast',
|
|
17
|
+
'remote-fast/osx-x64/mindexec-remote-fast.dll',
|
|
18
|
+
'remote-fast/osx-x64/mindexec-remote-fast.runtimeconfig.json'
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
function parsePackJson(stdout) {
|
|
22
|
+
const text = String(stdout || '').trim();
|
|
23
|
+
assert.ok(text, 'npm pack --dry-run should produce JSON output');
|
|
24
|
+
const payload = JSON.parse(text);
|
|
25
|
+
assert.ok(Array.isArray(payload) && payload.length > 0, 'npm pack dry-run JSON should contain one package entry');
|
|
26
|
+
return payload[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolveNpmPackCommand() {
|
|
30
|
+
const npmExecPath = String(process.env.npm_execpath || '').trim();
|
|
31
|
+
if (npmExecPath && /\.js$/i.test(npmExecPath)) {
|
|
32
|
+
return {
|
|
33
|
+
command: process.execPath,
|
|
34
|
+
argsPrefix: [npmExecPath]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
command: process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
40
|
+
argsPrefix: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function main() {
|
|
45
|
+
const npm = resolveNpmPackCommand();
|
|
46
|
+
const { stdout } = await execFileAsync(npm.command, [...npm.argsPrefix, 'pack', '--dry-run', '--json'], {
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
maxBuffer: 16 * 1024 * 1024
|
|
49
|
+
});
|
|
50
|
+
const pack = parsePackJson(stdout);
|
|
51
|
+
const files = new Set((pack.files || []).map(file => String(file.path || '').replace(/\\/g, '/')));
|
|
52
|
+
|
|
53
|
+
for (const required of REQUIRED_REMOTE_FAST_FILES) {
|
|
54
|
+
assert.ok(files.has(required), `packaged mindexec-ai is missing ${required}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const npxFallbackOnly = [...files].some(file => file.endsWith('server.js'))
|
|
58
|
+
&& ![...files].some(file => file.startsWith('remote-fast/'));
|
|
59
|
+
assert.equal(npxFallbackOnly, false, 'packaged CLI must include bundled RemoteFast, not only npx fallback code');
|
|
60
|
+
|
|
61
|
+
console.log('RemoteAgent package smoke OK');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await main();
|