@mindexec/cli 0.2.477 → 0.2.478
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 +323 -323
- package/codex-model-catalog.js +202 -202
- package/codex-runtime.js +1608 -1608
- package/desktop-workspace-state.cjs +120 -120
- package/electron/main.cjs +517 -517
- package/electron/preload.cjs +17 -17
- package/electron/recurring-update-owner-smoke.mjs +55 -55
- package/electron/recurring-update-owner.cjs +97 -97
- package/electron/source-smoke.mjs +108 -108
- package/electron/update-feed-resolver.cjs +79 -79
- package/electron/update-feed.json +10 -10
- package/electron/update-manager-smoke.mjs +146 -146
- package/electron/update-manager.cjs +297 -297
- package/electron/windows-package-smoke.mjs +156 -156
- package/launch-bridge.cjs +236 -236
- package/lzo1x.js +110 -110
- package/mode4-atlas-worker.js +440 -440
- package/mode4-atlas.js +130 -130
- package/package.json +1 -1
- package/port-guard.cjs +285 -285
- package/remote-fast/osx-arm64/MacScreenCaptureKitH264.swift +339 -339
- package/remote-fast/osx-arm64/MacSystemAudioCapture.swift +214 -214
- package/remote-fast/osx-arm64/UnixRawCaptureHelper.mjs +80 -80
- package/remote-fast/osx-arm64/livedesk-raw-capture-resampler.mjs +73 -73
- package/remote-fast/osx-arm64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/osx-x64/MacScreenCaptureKitH264.swift +339 -339
- package/remote-fast/osx-x64/MacSystemAudioCapture.swift +214 -214
- package/remote-fast/osx-x64/UnixRawCaptureHelper.mjs +80 -80
- package/remote-fast/osx-x64/livedesk-raw-capture-resampler.mjs +73 -73
- package/remote-fast/osx-x64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/win-x64/mindexec-remote-fast.dll +0 -0
- package/remote-hub.js +3698 -3698
- package/scripts/auth-session-smoke.mjs +262 -262
- package/scripts/board-render-ownership-smoke.mjs +85 -85
- package/scripts/codex-model-catalog-smoke.mjs +150 -150
- package/scripts/codex-runtime-home-smoke.mjs +58 -58
- package/scripts/codex-sdk-image-live-smoke.mjs +43 -43
- package/scripts/codex-sdk-image-runtime-smoke.mjs +122 -122
- package/scripts/codex-sdk-runtime-smoke.mjs +89 -89
- package/scripts/desktop-update-publisher-smoke.mjs +89 -89
- package/scripts/desktop-update-worker-smoke.mjs +72 -72
- package/scripts/desktop-workspace-state-smoke.mjs +81 -81
- package/scripts/drive-installed-update-smoke.mjs +67 -67
- package/scripts/npm-fresh-install-smoke.mjs +216 -216
- package/scripts/publish-mindexec-desktop-updates.mjs +224 -224
- package/scripts/remote-agent-managed-smoke.mjs +318 -318
- package/scripts/remote-agent-package-smoke.mjs +64 -64
- package/scripts/remote-agent-ws-smoke.mjs +269 -269
- package/scripts/remote-fast-live-rate-smoke.mjs +343 -343
- package/scripts/remote-fast-mdm-browser-smoke.mjs +453 -453
- package/scripts/remote-fleet-render-smoke.mjs +1350 -1350
- package/scripts/remote-frame-ws-smoke.mjs +234 -234
- package/scripts/remote-http-smoke.mjs +592 -592
- package/scripts/remote-hub-identity-smoke.mjs +146 -146
- package/scripts/remote-hub-scale-smoke.mjs +124 -124
- package/scripts/remote-hub-smoke.mjs +699 -699
- package/scripts/remote-input-ws-smoke.mjs +263 -263
- package/scripts/remote-registry-follower-smoke.mjs +815 -815
- package/scripts/setup-tree-sitter-grammars.mjs +59 -59
- package/server.js +7690 -7690
- package/start-bridge.bat +32 -32
- package/start-bridge.sh +81 -81
- package/wwwroot/_content/MindExecution.Plugins.Admin/css/admin-dashboard.css +546 -546
- package/wwwroot/_content/MindExecution.Plugins.YouTube/css/youtube-search.css +251 -251
- package/wwwroot/_content/MindExecution.Shared/css/app.css +1 -1
- package/wwwroot/_content/MindExecution.Shared/css/mind-map-overrides.css +3789 -3789
- package/wwwroot/_content/MindExecution.Shared/js/agent-visualization.js +27 -27
- package/wwwroot/_content/MindExecution.Shared/js/background-themes.js +1449 -1449
- package/wwwroot/_content/MindExecution.Shared/js/code-master.js +8316 -8316
- package/wwwroot/_content/MindExecution.Shared/js/file-system-helper.js +338 -338
- package/wwwroot/_content/MindExecution.Shared/js/marked.min.js +69 -69
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-animated-image-preview.js +270 -270
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-automation-edge-motion.js +170 -170
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-board-render-ownership.js +81 -81
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-core.js +10506 -10506
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-css3d-hotpath.js +902 -902
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-css3d-manager.js +24637 -24637
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-dev-guards.js +325 -325
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-dnd.js +1491 -1491
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-glow-shader.js +70 -70
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-image-policy.js +218 -218
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-interactions.js +7065 -7065
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-plan-worker.js +160 -160
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-renderer.js +9956 -9956
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-video-placeholder.js +107 -107
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-logic-workers.js +1004 -1004
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-menu-manager.js +1351 -1351
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-multi-select.js +865 -865
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-node-search-worker.js +554 -554
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-nodes.js +4744 -4744
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-normal-boundary-optimizer.js +624 -624
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-object-manager.js +241 -241
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-pipeline.js +2290 -2290
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-remote-codecs.js +202 -202
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-render-plan.js +1971 -1971
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-text-lod-system.js +93 -93
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-texture-factory.js +2391 -2391
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-video-playback-controls.js +95 -95
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-visibility-worker.js +895 -895
- package/wwwroot/_content/MindExecution.Shared/js/mindmap-toolbar.js +636 -636
- package/wwwroot/_content/MindExecution.Shared/js/native-drop-handler.js +45 -45
- package/wwwroot/_content/MindExecution.Shared/js/plan-master.js +117 -117
- package/wwwroot/_content/MindExecution.Shared/js/renderers/CSS3DRenderer.js +114 -114
- package/wwwroot/_content/MindExecution.Shared/js/texture-worker-manager.js +10 -10
- package/wwwroot/_content/MindExecution.Shared/js/three.min.js +6 -6
- package/wwwroot/_content/MindExecution.Shared/js/token-manager.js +7 -7
- package/wwwroot/_content/MindExecution.Shared/js/troika-bundle.js +6 -6
- package/wwwroot/_content/MindExecution.Shared/js/troika-bundle.js.map +2 -2
- package/wwwroot/_content/MindExecution.Shared/lib/font-awesome/css/all.min.css +8 -8
- package/wwwroot/_content/MindExecution.Shared/models/vocab.txt +30522 -30522
- package/wwwroot/_framework/{Google.Protobuf.9h59ukbel7.dll → Google.Protobuf.33g2gb5is0.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Core.ty1xewqp36.dll → MindExecution.Core.z100xo4mg0.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Kernel.h7rqjoo69o.dll → MindExecution.Kernel.i9cldrx8yc.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.Admin.wrfrcvhjde.dll → MindExecution.Plugins.Admin.48lzqddb0a.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.Business.csbcyjurdh.dll → MindExecution.Plugins.Business.7m8u1q142p.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.Concept.buomiysqjn.dll → MindExecution.Plugins.Concept.cl5wmr53od.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.Directory.7k00i2v769.dll → MindExecution.Plugins.Directory.slipi39041.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.PlanMaster.85i5ocraro.dll → MindExecution.Plugins.PlanMaster.qfge05l671.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Plugins.YouTube.nbolrfakte.dll → MindExecution.Plugins.YouTube.tn7v29ut77.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Shared.nqh4porv7x.dll → MindExecution.Shared.rjqlf0umjn.dll} +0 -0
- package/wwwroot/_framework/{MindExecution.Web.211q3bf4mr.dll → MindExecution.Web.rwawrxxk38.dll} +0 -0
- package/wwwroot/_framework/blazor.boot.json +23 -23
- package/wwwroot/_headers +40 -40
- package/wwwroot/_redirects +1 -1
- package/wwwroot/index.html +772 -772
- package/wwwroot/js/marketing-tool.js +180 -180
- package/wwwroot/manifest.webmanifest +23 -23
- package/wwwroot/service-worker-assets.js +78 -106
- package/wwwroot/service-worker.js +33 -33
- package/tree-sitter-grammars/README.md +0 -18
- 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/_content/MindExecution.Plugins.Directory/background.png +0 -0
- package/wwwroot/_content/MindExecution.Shared/fonts/NotoSansKR-Bold.ttf +0 -0
- package/wwwroot/_content/MindExecution.Shared/fonts/NotoSansKR-Regular.ttf +0 -0
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-core.js.backup +0 -1059
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-dnd.js.bak +0 -434
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-object-manager.js.backup +0 -372
- package/wwwroot/_content/MindExecution.Shared/js/mind-map-texture-factory.js.backup +0 -1258
|
@@ -1,699 +1,699 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import net from 'net';
|
|
4
|
-
import assert from 'assert/strict';
|
|
5
|
-
import { createRemoteHub } from '../remote-hub.js';
|
|
6
|
-
|
|
7
|
-
function writeJsonLine(socket, payload) {
|
|
8
|
-
socket.write(`${JSON.stringify(payload)}\n`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function writeBinaryFrame(socket, header, payload) {
|
|
12
|
-
const framePayload = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
|
|
13
|
-
socket.write(`${JSON.stringify({
|
|
14
|
-
...header,
|
|
15
|
-
type: 'frame.binary',
|
|
16
|
-
byteLength: framePayload.length
|
|
17
|
-
})}\n`);
|
|
18
|
-
socket.write(framePayload);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function wait(ms) {
|
|
22
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const defaultHub = createRemoteHub({
|
|
26
|
-
env: {
|
|
27
|
-
MINDEXEC_REMOTE_HUB: '0'
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
assert.equal(defaultHub.getStatus().port, 5198, 'MindExecution RemoteHub must not reuse the LiveDesk 5197 port');
|
|
31
|
-
|
|
32
|
-
async function waitFor(predicate, timeoutMs = 3000) {
|
|
33
|
-
const startedAt = Date.now();
|
|
34
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
35
|
-
const value = predicate();
|
|
36
|
-
if (value) {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
await wait(25);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
throw new Error('Timed out waiting for RemoteHub smoke condition.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const hub = createRemoteHub({
|
|
46
|
-
env: {
|
|
47
|
-
MINDEXEC_REMOTE_HUB: '1',
|
|
48
|
-
REMOTE_HUB_HOST: '127.0.0.1',
|
|
49
|
-
REMOTE_HUB_PORT: '0',
|
|
50
|
-
REMOTE_HUB_PAIR_TOKEN: 'smoke-token',
|
|
51
|
-
REMOTE_HUB_TASK_TIMEOUT_MS: '120'
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
const smokePngFrame = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC', 'base64');
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
await hub.start();
|
|
58
|
-
const status = hub.getStatus({ includeSecrets: true });
|
|
59
|
-
assert.equal(status.started, true);
|
|
60
|
-
assert.equal(status.canvasPagination, 'none');
|
|
61
|
-
|
|
62
|
-
const socket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
63
|
-
socket.setEncoding('utf8');
|
|
64
|
-
await new Promise((resolve, reject) => {
|
|
65
|
-
socket.once('connect', resolve);
|
|
66
|
-
socket.once('error', reject);
|
|
67
|
-
});
|
|
68
|
-
socket.on('error', () => { });
|
|
69
|
-
|
|
70
|
-
writeJsonLine(socket, {
|
|
71
|
-
type: 'hello',
|
|
72
|
-
pairToken: 'smoke-token',
|
|
73
|
-
deviceId: 'smoke-device',
|
|
74
|
-
deviceName: 'Smoke Device',
|
|
75
|
-
hostname: 'smoke-host',
|
|
76
|
-
platform: process.platform,
|
|
77
|
-
arch: process.arch,
|
|
78
|
-
pid: process.pid,
|
|
79
|
-
agentVersion: '0.0.0-smoke',
|
|
80
|
-
capabilities: {
|
|
81
|
-
status: true,
|
|
82
|
-
thumbnail: false,
|
|
83
|
-
control: true,
|
|
84
|
-
liveStream: true,
|
|
85
|
-
computerAgent: true,
|
|
86
|
-
taskDispatch: true,
|
|
87
|
-
aiAssist: true,
|
|
88
|
-
aiModel: 'fake-ai'
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
writeJsonLine(socket, {
|
|
92
|
-
type: 'status',
|
|
93
|
-
status: {
|
|
94
|
-
uptimeSec: 1,
|
|
95
|
-
totalMem: 2,
|
|
96
|
-
freeMem: 1
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const devices = await waitFor(() => {
|
|
101
|
-
const current = hub.listDevices();
|
|
102
|
-
return current.length === 1 && current[0].status?.uptimeSec === 1 ? current : null;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
assert.equal(devices[0].deviceId, 'smoke-device');
|
|
106
|
-
assert.equal(devices[0].connected, true);
|
|
107
|
-
assert.equal(hub.getStatus().deviceCount, 1);
|
|
108
|
-
|
|
109
|
-
const inputCommand = hub.sendInputControl('smoke-device', {
|
|
110
|
-
type: 'noop'
|
|
111
|
-
});
|
|
112
|
-
assert.equal(inputCommand.ok, true);
|
|
113
|
-
writeJsonLine(socket, {
|
|
114
|
-
type: 'command.result',
|
|
115
|
-
commandId: inputCommand.commandId,
|
|
116
|
-
result: {
|
|
117
|
-
input: true,
|
|
118
|
-
handled: true
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const inputDevice = await waitFor(() => {
|
|
122
|
-
const current = hub.listDevices();
|
|
123
|
-
return current[0]?.counters?.commandResultsReceived === 1 ? current[0] : null;
|
|
124
|
-
});
|
|
125
|
-
assert.equal(inputDevice.counters.commandsSent, 1);
|
|
126
|
-
|
|
127
|
-
const thumbnailCommand = hub.requestThumbnail('smoke-device', {
|
|
128
|
-
streamId: 'smoke-thumb',
|
|
129
|
-
maxWidth: 320,
|
|
130
|
-
maxHeight: 180,
|
|
131
|
-
quality: 50
|
|
132
|
-
});
|
|
133
|
-
assert.equal(thumbnailCommand.ok, true);
|
|
134
|
-
|
|
135
|
-
writeJsonLine(socket, {
|
|
136
|
-
type: 'thumbnail.frame',
|
|
137
|
-
commandId: thumbnailCommand.commandId,
|
|
138
|
-
streamId: 'smoke-thumb',
|
|
139
|
-
frameSeq: 1,
|
|
140
|
-
width: 2,
|
|
141
|
-
height: 1,
|
|
142
|
-
mimeType: 'image/png',
|
|
143
|
-
capturedAt: new Date().toISOString(),
|
|
144
|
-
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const thumbnailDevice = await waitFor(() => {
|
|
148
|
-
const current = hub.listDevices();
|
|
149
|
-
return current[0]?.latestThumbnail?.frameSeq === 1 ? current[0] : null;
|
|
150
|
-
});
|
|
151
|
-
assert.equal(thumbnailDevice.latestThumbnail.streamId, 'smoke-thumb');
|
|
152
|
-
assert.equal(thumbnailDevice.counters.thumbnailFramesReceived, 1);
|
|
153
|
-
const serializedFirstThumbnail = hub.getDeviceThumbnail('smoke-device', { includeDataUrl: false });
|
|
154
|
-
const serializedFirstThumbnailUrl = new URL(serializedFirstThumbnail.framePath, 'http://127.0.0.1');
|
|
155
|
-
|
|
156
|
-
const binaryThumbnailCommand = hub.requestThumbnail('smoke-device', {
|
|
157
|
-
streamId: 'smoke-thumb-binary',
|
|
158
|
-
maxWidth: 320,
|
|
159
|
-
maxHeight: 180,
|
|
160
|
-
quality: 50
|
|
161
|
-
});
|
|
162
|
-
assert.equal(binaryThumbnailCommand.ok, true);
|
|
163
|
-
writeBinaryFrame(socket, {
|
|
164
|
-
frameKind: 'thumbnail',
|
|
165
|
-
commandId: binaryThumbnailCommand.commandId,
|
|
166
|
-
streamId: 'smoke-thumb-binary',
|
|
167
|
-
frameSeq: 4,
|
|
168
|
-
width: 2,
|
|
169
|
-
height: 1,
|
|
170
|
-
mimeType: 'image/png',
|
|
171
|
-
capturedAt: new Date().toISOString()
|
|
172
|
-
}, smokePngFrame);
|
|
173
|
-
|
|
174
|
-
const binaryThumbnailDevice = await waitFor(() => {
|
|
175
|
-
const current = hub.listDevices();
|
|
176
|
-
return current[0]?.latestThumbnail?.frameSeq === 4 ? current[0] : null;
|
|
177
|
-
});
|
|
178
|
-
assert.equal(binaryThumbnailDevice.latestThumbnail.streamId, 'smoke-thumb-binary');
|
|
179
|
-
assert.equal(binaryThumbnailDevice.latestThumbnail.transport, 'binary');
|
|
180
|
-
assert.equal(binaryThumbnailDevice.latestThumbnail.byteLength, smokePngFrame.length);
|
|
181
|
-
assert.equal(typeof binaryThumbnailDevice.latestThumbnail.contentHash, 'string');
|
|
182
|
-
assert.equal(binaryThumbnailDevice.latestThumbnail.contentHash.length, 16);
|
|
183
|
-
assert.equal(binaryThumbnailDevice.latestThumbnail.sameContentStreak, 1);
|
|
184
|
-
assert.equal(binaryThumbnailDevice.counters.thumbnailFramesReceived, 2);
|
|
185
|
-
const serializedBinaryThumbnail = hub.getDeviceThumbnail('smoke-device', { includeDataUrl: false });
|
|
186
|
-
assert.equal(serializedBinaryThumbnail.streamId, 'smoke-thumb-binary');
|
|
187
|
-
assert.equal(serializedBinaryThumbnail.frameSeq, 4);
|
|
188
|
-
assert.equal(serializedBinaryThumbnail.contentHash, binaryThumbnailDevice.latestThumbnail.contentHash);
|
|
189
|
-
assert.ok(serializedBinaryThumbnail.framePath.includes('/api/remote/devices/smoke-device/thumbnail?'));
|
|
190
|
-
assert.ok(!('dataUrl' in serializedBinaryThumbnail));
|
|
191
|
-
assert.ok(!('payload' in serializedBinaryThumbnail));
|
|
192
|
-
assert.ok(!('accessToken' in serializedBinaryThumbnail));
|
|
193
|
-
const serializedThumbnailUrl = new URL(serializedBinaryThumbnail.framePath, 'http://127.0.0.1');
|
|
194
|
-
const thumbnailPayload = hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
195
|
-
token: serializedThumbnailUrl.searchParams.get('token'),
|
|
196
|
-
frameSeq: serializedThumbnailUrl.searchParams.get('seq'),
|
|
197
|
-
requireToken: true
|
|
198
|
-
});
|
|
199
|
-
assert.equal(thumbnailPayload?.mimeType, 'image/png');
|
|
200
|
-
assert.equal(thumbnailPayload?.byteLength, smokePngFrame.length);
|
|
201
|
-
assert.equal(Buffer.compare(thumbnailPayload.payload, smokePngFrame), 0);
|
|
202
|
-
const retainedThumbnailPayload = hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
203
|
-
token: serializedFirstThumbnailUrl.searchParams.get('token'),
|
|
204
|
-
frameSeq: serializedFirstThumbnailUrl.searchParams.get('seq'),
|
|
205
|
-
requireToken: true
|
|
206
|
-
});
|
|
207
|
-
assert.equal(retainedThumbnailPayload?.frame?.frameSeq, 1);
|
|
208
|
-
assert.equal(retainedThumbnailPayload?.byteLength, smokePngFrame.length);
|
|
209
|
-
assert.equal(Buffer.compare(retainedThumbnailPayload.payload, smokePngFrame), 0);
|
|
210
|
-
assert.equal(hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
211
|
-
token: 'wrong-token',
|
|
212
|
-
frameSeq: 4,
|
|
213
|
-
requireToken: true
|
|
214
|
-
}), null);
|
|
215
|
-
|
|
216
|
-
const liveCommand = hub.startLiveStream('smoke-device', {
|
|
217
|
-
streamId: 'smoke-live',
|
|
218
|
-
fps: 5,
|
|
219
|
-
maxWidth: 320,
|
|
220
|
-
maxHeight: 180,
|
|
221
|
-
quality: 50
|
|
222
|
-
});
|
|
223
|
-
assert.equal(liveCommand.ok, true);
|
|
224
|
-
assert.equal(liveCommand.frameMode, 'remote-fast');
|
|
225
|
-
writeJsonLine(socket, {
|
|
226
|
-
type: 'stream.open',
|
|
227
|
-
commandId: liveCommand.commandId,
|
|
228
|
-
streamId: 'smoke-live',
|
|
229
|
-
mode: 'remote-fast',
|
|
230
|
-
frameMode: 'remote-fast',
|
|
231
|
-
frameProfile: 'jpeg-binary-v1',
|
|
232
|
-
encoding: 'image',
|
|
233
|
-
codec: 'png',
|
|
234
|
-
compression: 'image/png',
|
|
235
|
-
transferProtocol: 'mindexec.remote.frame.v2',
|
|
236
|
-
transferProtocolVersion: 2,
|
|
237
|
-
handshake: 'smartview-request-open-frame',
|
|
238
|
-
fps: 5,
|
|
239
|
-
openedAt: new Date().toISOString()
|
|
240
|
-
});
|
|
241
|
-
writeJsonLine(socket, {
|
|
242
|
-
type: 'stream.frame',
|
|
243
|
-
commandId: liveCommand.commandId,
|
|
244
|
-
streamId: 'smoke-live',
|
|
245
|
-
frameSeq: 2,
|
|
246
|
-
width: 2,
|
|
247
|
-
height: 1,
|
|
248
|
-
mimeType: 'image/png',
|
|
249
|
-
mode: 'remote-fast',
|
|
250
|
-
frameMode: 'remote-fast',
|
|
251
|
-
frameProfile: 'jpeg-binary-v1',
|
|
252
|
-
encoding: 'image',
|
|
253
|
-
codec: 'png',
|
|
254
|
-
compression: 'image/png',
|
|
255
|
-
transferProtocol: 'mindexec.remote.frame.v2',
|
|
256
|
-
transferProtocolVersion: 2,
|
|
257
|
-
handshake: 'smartview-request-open-frame',
|
|
258
|
-
fps: 5,
|
|
259
|
-
capturedAt: new Date().toISOString(),
|
|
260
|
-
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
const liveDevice = await waitFor(() => {
|
|
264
|
-
const current = hub.listDevices();
|
|
265
|
-
return current[0]?.latestLiveFrame?.streamId === 'smoke-live' ? current[0] : null;
|
|
266
|
-
});
|
|
267
|
-
assert.equal(liveDevice.activeLiveStream.active, true);
|
|
268
|
-
assert.equal(liveDevice.activeLiveStream.open, true);
|
|
269
|
-
assert.equal(liveDevice.activeLiveStream.handshake, 'smartview-request-open-frame');
|
|
270
|
-
assert.equal(liveDevice.latestLiveFrame.mode, 'remote-fast');
|
|
271
|
-
assert.equal(liveDevice.latestLiveFrame.frameMode, 'remote-fast');
|
|
272
|
-
assert.equal(liveDevice.latestLiveFrame.compression, 'image/png');
|
|
273
|
-
assert.equal(liveDevice.counters.liveFramesReceived, 1);
|
|
274
|
-
const serializedFirstLiveFrame = hub.getDeviceLiveFrame('smoke-device', { includeDataUrl: false });
|
|
275
|
-
const serializedFirstLiveUrl = new URL(serializedFirstLiveFrame.framePath, 'http://127.0.0.1');
|
|
276
|
-
|
|
277
|
-
writeBinaryFrame(socket, {
|
|
278
|
-
frameKind: 'stream',
|
|
279
|
-
commandId: liveCommand.commandId,
|
|
280
|
-
streamId: 'smoke-live',
|
|
281
|
-
frameSeq: 5,
|
|
282
|
-
width: 2,
|
|
283
|
-
height: 1,
|
|
284
|
-
mimeType: 'image/png',
|
|
285
|
-
mode: 'remote-fast',
|
|
286
|
-
frameMode: 'remote-fast',
|
|
287
|
-
frameProfile: 'jpeg-binary-v1',
|
|
288
|
-
encoding: 'image',
|
|
289
|
-
codec: 'png',
|
|
290
|
-
compression: 'image/png',
|
|
291
|
-
transferProtocol: 'mindexec.remote.frame.v2',
|
|
292
|
-
transferProtocolVersion: 2,
|
|
293
|
-
handshake: 'smartview-request-open-frame',
|
|
294
|
-
fps: 5,
|
|
295
|
-
capturedAt: new Date().toISOString()
|
|
296
|
-
}, smokePngFrame);
|
|
297
|
-
|
|
298
|
-
const binaryLiveDevice = await waitFor(() => {
|
|
299
|
-
const current = hub.listDevices();
|
|
300
|
-
return current[0]?.latestLiveFrame?.frameSeq === 5 ? current[0] : null;
|
|
301
|
-
});
|
|
302
|
-
assert.equal(binaryLiveDevice.latestLiveFrame.streamId, 'smoke-live');
|
|
303
|
-
assert.equal(binaryLiveDevice.latestLiveFrame.transport, 'binary');
|
|
304
|
-
assert.equal(binaryLiveDevice.latestLiveFrame.byteLength, smokePngFrame.length);
|
|
305
|
-
assert.equal(typeof binaryLiveDevice.latestLiveFrame.contentHash, 'string');
|
|
306
|
-
assert.equal(binaryLiveDevice.latestLiveFrame.contentHash.length, 16);
|
|
307
|
-
assert.equal(binaryLiveDevice.latestLiveFrame.sameContentStreak, 1);
|
|
308
|
-
assert.equal(binaryLiveDevice.counters.liveFramesReceived, 2);
|
|
309
|
-
const serializedBinaryLiveFrame = hub.getDeviceLiveFrame('smoke-device', { includeDataUrl: false });
|
|
310
|
-
assert.equal(serializedBinaryLiveFrame.streamId, 'smoke-live');
|
|
311
|
-
assert.equal(serializedBinaryLiveFrame.frameSeq, 5);
|
|
312
|
-
assert.equal(serializedBinaryLiveFrame.frameMode, 'remote-fast');
|
|
313
|
-
assert.equal(serializedBinaryLiveFrame.compression, 'image/png');
|
|
314
|
-
assert.equal(serializedBinaryLiveFrame.contentHash, binaryLiveDevice.latestLiveFrame.contentHash);
|
|
315
|
-
assert.ok(serializedBinaryLiveFrame.framePath.includes('/api/remote/devices/smoke-device/live/frame?'));
|
|
316
|
-
assert.ok(!('dataUrl' in serializedBinaryLiveFrame));
|
|
317
|
-
assert.ok(!('payload' in serializedBinaryLiveFrame));
|
|
318
|
-
assert.ok(!('accessToken' in serializedBinaryLiveFrame));
|
|
319
|
-
const serializedLiveUrl = new URL(serializedBinaryLiveFrame.framePath, 'http://127.0.0.1');
|
|
320
|
-
const livePayload = hub.getFramePayload('smoke-device', 'live', {
|
|
321
|
-
token: serializedLiveUrl.searchParams.get('token'),
|
|
322
|
-
frameSeq: serializedLiveUrl.searchParams.get('seq'),
|
|
323
|
-
requireToken: true
|
|
324
|
-
});
|
|
325
|
-
assert.equal(livePayload?.mimeType, 'image/png');
|
|
326
|
-
assert.equal(livePayload?.byteLength, smokePngFrame.length);
|
|
327
|
-
assert.equal(Buffer.compare(livePayload.payload, smokePngFrame), 0);
|
|
328
|
-
const retainedLivePayload = hub.getFramePayload('smoke-device', 'live', {
|
|
329
|
-
token: serializedFirstLiveUrl.searchParams.get('token'),
|
|
330
|
-
frameSeq: serializedFirstLiveUrl.searchParams.get('seq'),
|
|
331
|
-
requireToken: true
|
|
332
|
-
});
|
|
333
|
-
assert.equal(retainedLivePayload?.frame?.frameSeq, 2);
|
|
334
|
-
assert.equal(retainedLivePayload?.byteLength, smokePngFrame.length);
|
|
335
|
-
assert.equal(Buffer.compare(retainedLivePayload.payload, smokePngFrame), 0);
|
|
336
|
-
assert.equal(hub.getFramePayload('smoke-device', 'live', {
|
|
337
|
-
token: serializedLiveUrl.searchParams.get('token'),
|
|
338
|
-
frameSeq: 4,
|
|
339
|
-
requireToken: true
|
|
340
|
-
}), null);
|
|
341
|
-
|
|
342
|
-
const staleFrameBefore = liveDevice.counters.liveFramesDropped;
|
|
343
|
-
writeJsonLine(socket, {
|
|
344
|
-
type: 'stream.frame',
|
|
345
|
-
streamId: 'stale-live',
|
|
346
|
-
frameSeq: 3,
|
|
347
|
-
width: 2,
|
|
348
|
-
height: 1,
|
|
349
|
-
mimeType: 'image/png',
|
|
350
|
-
capturedAt: new Date().toISOString(),
|
|
351
|
-
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
352
|
-
});
|
|
353
|
-
const staleDropDevice = await waitFor(() => {
|
|
354
|
-
const current = hub.listDevices();
|
|
355
|
-
return current[0]?.counters?.liveFramesDropped > staleFrameBefore ? current[0] : null;
|
|
356
|
-
});
|
|
357
|
-
assert.equal(staleDropDevice.latestLiveFrame.streamId, 'smoke-live');
|
|
358
|
-
|
|
359
|
-
const stopLiveCommand = hub.stopLiveStream('smoke-device', {
|
|
360
|
-
streamId: 'smoke-live'
|
|
361
|
-
});
|
|
362
|
-
assert.equal(stopLiveCommand.ok, true);
|
|
363
|
-
assert.equal(hub.listDevices()[0].activeLiveStream.active, false);
|
|
364
|
-
|
|
365
|
-
const taskCommand = hub.requestAgentTask('smoke-device', {
|
|
366
|
-
instruction: 'Summarize current desktop status for the manager.',
|
|
367
|
-
title: 'Smoke task'
|
|
368
|
-
});
|
|
369
|
-
assert.equal(taskCommand.ok, true);
|
|
370
|
-
writeJsonLine(socket, {
|
|
371
|
-
type: 'command.result',
|
|
372
|
-
commandId: taskCommand.commandId,
|
|
373
|
-
result: {
|
|
374
|
-
kind: 'agent.task',
|
|
375
|
-
taskId: taskCommand.taskId,
|
|
376
|
-
status: 'completed',
|
|
377
|
-
summary: 'Smoke task accepted.',
|
|
378
|
-
completedAt: new Date().toISOString()
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
const taskDevice = await waitFor(() => {
|
|
383
|
-
const current = hub.listDevices();
|
|
384
|
-
return current[0]?.latestTask?.taskId === taskCommand.taskId
|
|
385
|
-
&& current[0]?.latestTask?.status === 'completed'
|
|
386
|
-
? current[0]
|
|
387
|
-
: null;
|
|
388
|
-
});
|
|
389
|
-
assert.equal(taskDevice.latestTask.resultSummary, 'Smoke task accepted.');
|
|
390
|
-
assert.equal(taskDevice.counters.tasksQueued, 1);
|
|
391
|
-
assert.equal(taskDevice.counters.taskResultsReceived, 1);
|
|
392
|
-
|
|
393
|
-
const aiTaskCommand = hub.requestAgentTask('smoke-device', {
|
|
394
|
-
instruction: 'Use AI assist to summarize the smoke test state.',
|
|
395
|
-
title: 'Smoke AI task',
|
|
396
|
-
approvalLevel: 'ai-assist'
|
|
397
|
-
});
|
|
398
|
-
assert.equal(aiTaskCommand.ok, true);
|
|
399
|
-
assert.equal(aiTaskCommand.approvalLevel, 'ai-assist');
|
|
400
|
-
writeJsonLine(socket, {
|
|
401
|
-
type: 'command.result',
|
|
402
|
-
commandId: aiTaskCommand.commandId,
|
|
403
|
-
result: {
|
|
404
|
-
kind: 'agent.task',
|
|
405
|
-
mode: 'ai-assist',
|
|
406
|
-
taskId: aiTaskCommand.taskId,
|
|
407
|
-
status: 'completed',
|
|
408
|
-
summary: 'Smoke AI task accepted.',
|
|
409
|
-
model: 'smoke-ai-model',
|
|
410
|
-
responseId: 'smoke-ai-response',
|
|
411
|
-
completedAt: new Date().toISOString()
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
const aiTaskDevice = await waitFor(() => {
|
|
416
|
-
const current = hub.listDevices();
|
|
417
|
-
return current[0]?.latestTask?.taskId === aiTaskCommand.taskId
|
|
418
|
-
&& current[0]?.latestTask?.approvalLevel === 'ai-assist'
|
|
419
|
-
&& current[0]?.latestTask?.status === 'completed'
|
|
420
|
-
? current[0]
|
|
421
|
-
: null;
|
|
422
|
-
});
|
|
423
|
-
assert.equal(aiTaskDevice.latestTask.resultSummary, 'Smoke AI task accepted.');
|
|
424
|
-
assert.equal(aiTaskDevice.latestTask.resultModel, 'smoke-ai-model');
|
|
425
|
-
assert.equal(aiTaskDevice.latestTask.resultResponseId, 'smoke-ai-response');
|
|
426
|
-
assert.equal(aiTaskDevice.counters.tasksQueued, 2);
|
|
427
|
-
assert.equal(aiTaskDevice.counters.taskResultsReceived, 2);
|
|
428
|
-
|
|
429
|
-
const batchTask = hub.requestAgentTaskBatch(['smoke-device', 'missing-smoke-device'], {
|
|
430
|
-
instruction: 'Dispatch a smoke batch to one connected and one missing device.',
|
|
431
|
-
title: 'Smoke batch'
|
|
432
|
-
});
|
|
433
|
-
assert.equal(batchTask.ok, true);
|
|
434
|
-
assert.equal(batchTask.total, 2);
|
|
435
|
-
assert.equal(batchTask.queued, 1);
|
|
436
|
-
assert.ok(batchTask.batchId);
|
|
437
|
-
assert.equal(batchTask.batch?.pending, 1);
|
|
438
|
-
assert.equal(batchTask.batch?.failed, 1);
|
|
439
|
-
assert.equal(batchTask.batch?.status, 'running');
|
|
440
|
-
const acceptedBatchItem = batchTask.results.find(result => result.deviceId === 'smoke-device');
|
|
441
|
-
assert.ok(acceptedBatchItem?.commandId);
|
|
442
|
-
writeJsonLine(socket, {
|
|
443
|
-
type: 'command.result',
|
|
444
|
-
commandId: acceptedBatchItem.commandId,
|
|
445
|
-
result: {
|
|
446
|
-
kind: 'agent.task',
|
|
447
|
-
taskId: acceptedBatchItem.taskId,
|
|
448
|
-
status: 'completed',
|
|
449
|
-
summary: 'Smoke batch item accepted.',
|
|
450
|
-
completedAt: new Date().toISOString()
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
const completedBatch = await waitFor(() => {
|
|
455
|
-
const latest = hub.getLatestTaskBatch();
|
|
456
|
-
return latest?.batchId === batchTask.batchId
|
|
457
|
-
&& latest.completed === 1
|
|
458
|
-
&& latest.failed === 1
|
|
459
|
-
? latest
|
|
460
|
-
: null;
|
|
461
|
-
});
|
|
462
|
-
assert.equal(completedBatch.pending, 0);
|
|
463
|
-
assert.equal(completedBatch.status, 'completed-with-failures');
|
|
464
|
-
assert.equal(completedBatch.results.length, 2);
|
|
465
|
-
assert.equal(completedBatch.results.find(result => result.deviceId === 'missing-smoke-device')?.error, 'device-not-found');
|
|
466
|
-
|
|
467
|
-
const timeoutTaskCommand = hub.requestAgentTask('smoke-device', {
|
|
468
|
-
instruction: 'This task intentionally receives no agent response.',
|
|
469
|
-
title: 'Timeout task'
|
|
470
|
-
});
|
|
471
|
-
assert.equal(timeoutTaskCommand.ok, true);
|
|
472
|
-
const timeoutTaskDevice = await waitFor(() => {
|
|
473
|
-
const current = hub.listDevices();
|
|
474
|
-
return current[0]?.latestTask?.taskId === timeoutTaskCommand.taskId
|
|
475
|
-
&& current[0]?.latestTask?.status === 'failed'
|
|
476
|
-
? current[0]
|
|
477
|
-
: null;
|
|
478
|
-
}, 1000);
|
|
479
|
-
assert.equal(timeoutTaskDevice.latestTask.error, 'task-timeout');
|
|
480
|
-
assert.equal(timeoutTaskDevice.latestTask.resultSummary, 'task-timeout');
|
|
481
|
-
assert.equal(timeoutTaskDevice.counters.tasksQueued, 4);
|
|
482
|
-
assert.equal(timeoutTaskDevice.counters.taskResultsReceived, 4);
|
|
483
|
-
assert.equal(timeoutTaskDevice.counters.taskResultsFailed, 1);
|
|
484
|
-
assert.equal(timeoutTaskDevice.counters.taskResultsTimedOut, 1);
|
|
485
|
-
writeJsonLine(socket, {
|
|
486
|
-
type: 'command.result',
|
|
487
|
-
commandId: timeoutTaskCommand.commandId,
|
|
488
|
-
result: {
|
|
489
|
-
kind: 'agent.task',
|
|
490
|
-
taskId: timeoutTaskCommand.taskId,
|
|
491
|
-
status: 'completed',
|
|
492
|
-
summary: 'This late timeout result must be ignored.',
|
|
493
|
-
completedAt: new Date().toISOString()
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
await wait(100);
|
|
497
|
-
const lateTimeoutDevice = hub.listDevices()[0];
|
|
498
|
-
assert.equal(lateTimeoutDevice.latestTask.taskId, timeoutTaskCommand.taskId);
|
|
499
|
-
assert.equal(lateTimeoutDevice.latestTask.status, 'failed');
|
|
500
|
-
assert.equal(lateTimeoutDevice.latestTask.error, 'task-timeout');
|
|
501
|
-
assert.equal(lateTimeoutDevice.latestTask.resultSummary, 'task-timeout');
|
|
502
|
-
assert.equal(lateTimeoutDevice.counters.taskResultsReceived, 4);
|
|
503
|
-
|
|
504
|
-
const timeoutBatch = hub.requestAgentTaskBatch(['smoke-device'], {
|
|
505
|
-
instruction: 'This batch item intentionally times out before a late result arrives.',
|
|
506
|
-
title: 'Timeout batch'
|
|
507
|
-
});
|
|
508
|
-
assert.equal(timeoutBatch.ok, true);
|
|
509
|
-
assert.equal(timeoutBatch.total, 1);
|
|
510
|
-
assert.equal(timeoutBatch.queued, 1);
|
|
511
|
-
assert.equal(timeoutBatch.batch?.pending, 1);
|
|
512
|
-
const timeoutBatchItem = timeoutBatch.results.find(result => result.deviceId === 'smoke-device');
|
|
513
|
-
assert.ok(timeoutBatchItem?.commandId);
|
|
514
|
-
assert.ok(timeoutBatchItem?.taskId);
|
|
515
|
-
|
|
516
|
-
const timedOutBatch = await waitFor(() => {
|
|
517
|
-
const latest = hub.getLatestTaskBatch();
|
|
518
|
-
return latest?.batchId === timeoutBatch.batchId
|
|
519
|
-
&& latest.timedOut === 1
|
|
520
|
-
&& latest.pending === 0
|
|
521
|
-
? latest
|
|
522
|
-
: null;
|
|
523
|
-
}, 1000);
|
|
524
|
-
assert.equal(timedOutBatch.status, 'completed-with-failures');
|
|
525
|
-
assert.equal(timedOutBatch.failed, 1);
|
|
526
|
-
assert.equal(timedOutBatch.results[0]?.status, 'failed');
|
|
527
|
-
assert.equal(timedOutBatch.results[0]?.error, 'task-timeout');
|
|
528
|
-
|
|
529
|
-
writeJsonLine(socket, {
|
|
530
|
-
type: 'command.result',
|
|
531
|
-
commandId: timeoutBatchItem.commandId,
|
|
532
|
-
result: {
|
|
533
|
-
kind: 'agent.task',
|
|
534
|
-
taskId: timeoutBatchItem.taskId,
|
|
535
|
-
status: 'completed',
|
|
536
|
-
summary: 'This late batch timeout result must be ignored.',
|
|
537
|
-
completedAt: new Date().toISOString()
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
await wait(100);
|
|
541
|
-
const lateTimedOutBatch = hub.getLatestTaskBatch();
|
|
542
|
-
const lateTimedOutDevice = hub.listDevices()[0];
|
|
543
|
-
assert.equal(lateTimedOutBatch.batchId, timeoutBatch.batchId);
|
|
544
|
-
assert.equal(lateTimedOutBatch.status, 'completed-with-failures');
|
|
545
|
-
assert.equal(lateTimedOutBatch.completed, 0);
|
|
546
|
-
assert.equal(lateTimedOutBatch.failed, 1);
|
|
547
|
-
assert.equal(lateTimedOutBatch.timedOut, 1);
|
|
548
|
-
assert.equal(lateTimedOutBatch.results[0]?.status, 'failed');
|
|
549
|
-
assert.equal(lateTimedOutBatch.results[0]?.error, 'task-timeout');
|
|
550
|
-
assert.equal(lateTimedOutDevice.latestTask.taskId, timeoutBatchItem.taskId);
|
|
551
|
-
assert.equal(lateTimedOutDevice.latestTask.status, 'failed');
|
|
552
|
-
assert.equal(lateTimedOutDevice.latestTask.error, 'task-timeout');
|
|
553
|
-
assert.equal(lateTimedOutDevice.latestTask.resultSummary, 'task-timeout');
|
|
554
|
-
assert.equal(lateTimedOutDevice.counters.taskResultsReceived, 5);
|
|
555
|
-
assert.equal(lateTimedOutDevice.counters.taskResultsFailed, 2);
|
|
556
|
-
assert.equal(lateTimedOutDevice.counters.taskResultsTimedOut, 2);
|
|
557
|
-
|
|
558
|
-
const staleSessionTask = hub.requestAgentTask('smoke-device', {
|
|
559
|
-
instruction: 'This old session task must not survive reconnect.',
|
|
560
|
-
title: 'Reconnect stale task'
|
|
561
|
-
});
|
|
562
|
-
assert.equal(staleSessionTask.ok, true);
|
|
563
|
-
const oldSessionId = lateTimedOutDevice.sessionId;
|
|
564
|
-
|
|
565
|
-
const duplicateSocket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
566
|
-
duplicateSocket.setEncoding('utf8');
|
|
567
|
-
const duplicateMessages = [];
|
|
568
|
-
let duplicateBuffer = '';
|
|
569
|
-
await new Promise((resolve, reject) => {
|
|
570
|
-
duplicateSocket.once('connect', resolve);
|
|
571
|
-
duplicateSocket.once('error', reject);
|
|
572
|
-
});
|
|
573
|
-
duplicateSocket.on('error', () => { });
|
|
574
|
-
duplicateSocket.on('data', chunk => {
|
|
575
|
-
duplicateBuffer += chunk;
|
|
576
|
-
let lineBreakIndex = duplicateBuffer.indexOf('\n');
|
|
577
|
-
while (lineBreakIndex >= 0) {
|
|
578
|
-
const line = duplicateBuffer.slice(0, lineBreakIndex).trim();
|
|
579
|
-
duplicateBuffer = duplicateBuffer.slice(lineBreakIndex + 1);
|
|
580
|
-
if (line) {
|
|
581
|
-
duplicateMessages.push(JSON.parse(line));
|
|
582
|
-
}
|
|
583
|
-
lineBreakIndex = duplicateBuffer.indexOf('\n');
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
writeJsonLine(duplicateSocket, {
|
|
587
|
-
type: 'hello',
|
|
588
|
-
pairToken: 'smoke-token',
|
|
589
|
-
deviceId: 'smoke-device',
|
|
590
|
-
deviceName: 'Smoke Device Duplicate',
|
|
591
|
-
hostname: 'smoke-host-duplicate',
|
|
592
|
-
platform: process.platform,
|
|
593
|
-
arch: process.arch,
|
|
594
|
-
pid: process.pid,
|
|
595
|
-
agentVersion: '0.0.0-smoke-duplicate',
|
|
596
|
-
capabilities: {
|
|
597
|
-
status: true,
|
|
598
|
-
thumbnail: false,
|
|
599
|
-
control: false,
|
|
600
|
-
liveStream: true,
|
|
601
|
-
computerAgent: true,
|
|
602
|
-
taskDispatch: true,
|
|
603
|
-
aiAssist: false
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
const duplicateDisconnect = await waitFor(() => (
|
|
608
|
-
duplicateMessages.find(message => message?.type === 'disconnect')
|
|
609
|
-
), 1000);
|
|
610
|
-
assert.equal(duplicateDisconnect.reason, 'duplicate-device-active');
|
|
611
|
-
assert.equal(duplicateDisconnect.activeSessionId, oldSessionId);
|
|
612
|
-
assert.equal(duplicateDisconnect.retryAfterMs >= 30000, true);
|
|
613
|
-
await wait(100);
|
|
614
|
-
const duplicateRejectedDevice = hub.listDevices()[0];
|
|
615
|
-
assert.equal(duplicateRejectedDevice.sessionId, oldSessionId);
|
|
616
|
-
assert.equal(duplicateRejectedDevice.deviceName, 'Smoke Device');
|
|
617
|
-
assert.equal(duplicateRejectedDevice.connected, true);
|
|
618
|
-
assert.equal(duplicateRejectedDevice.counters.duplicateConnectionsRejected, 1);
|
|
619
|
-
assert.equal(duplicateRejectedDevice.latestTask.taskId, staleSessionTask.taskId);
|
|
620
|
-
duplicateSocket.destroy();
|
|
621
|
-
|
|
622
|
-
socket.destroy();
|
|
623
|
-
const disconnectedDevice = await waitFor(() => {
|
|
624
|
-
const current = hub.listDevices();
|
|
625
|
-
return current.length === 1
|
|
626
|
-
&& current[0]?.sessionId === oldSessionId
|
|
627
|
-
&& current[0]?.connected === false
|
|
628
|
-
? current[0]
|
|
629
|
-
: null;
|
|
630
|
-
});
|
|
631
|
-
assert.equal(disconnectedDevice.latestTask.status, 'failed');
|
|
632
|
-
assert.equal(
|
|
633
|
-
['device-disconnected', 'task-timeout'].includes(disconnectedDevice.latestTask.error),
|
|
634
|
-
true);
|
|
635
|
-
|
|
636
|
-
const replacementSocket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
637
|
-
replacementSocket.setEncoding('utf8');
|
|
638
|
-
await new Promise((resolve, reject) => {
|
|
639
|
-
replacementSocket.once('connect', resolve);
|
|
640
|
-
replacementSocket.once('error', reject);
|
|
641
|
-
});
|
|
642
|
-
replacementSocket.on('error', () => { });
|
|
643
|
-
writeJsonLine(replacementSocket, {
|
|
644
|
-
type: 'hello',
|
|
645
|
-
pairToken: 'smoke-token',
|
|
646
|
-
deviceId: 'smoke-device',
|
|
647
|
-
deviceName: 'Smoke Device Reconnected',
|
|
648
|
-
hostname: 'smoke-host-reconnected',
|
|
649
|
-
platform: process.platform,
|
|
650
|
-
arch: process.arch,
|
|
651
|
-
pid: process.pid,
|
|
652
|
-
agentVersion: '0.0.0-smoke-reconnected',
|
|
653
|
-
capabilities: {
|
|
654
|
-
status: true,
|
|
655
|
-
thumbnail: false,
|
|
656
|
-
control: false,
|
|
657
|
-
liveStream: true,
|
|
658
|
-
computerAgent: true,
|
|
659
|
-
taskDispatch: true,
|
|
660
|
-
aiAssist: true,
|
|
661
|
-
aiModel: 'fake-ai'
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
writeJsonLine(replacementSocket, {
|
|
665
|
-
type: 'status',
|
|
666
|
-
status: {
|
|
667
|
-
uptimeSec: 2,
|
|
668
|
-
totalMem: 4,
|
|
669
|
-
freeMem: 3
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
const reconnectedDevice = await waitFor(() => {
|
|
674
|
-
const current = hub.listDevices();
|
|
675
|
-
return current.length === 1
|
|
676
|
-
&& current[0]?.deviceName === 'Smoke Device Reconnected'
|
|
677
|
-
&& current[0]?.status?.uptimeSec === 2
|
|
678
|
-
? current[0]
|
|
679
|
-
: null;
|
|
680
|
-
});
|
|
681
|
-
assert.notEqual(reconnectedDevice.sessionId, oldSessionId);
|
|
682
|
-
assert.equal(reconnectedDevice.connected, true);
|
|
683
|
-
assert.equal(reconnectedDevice.latestTask, null);
|
|
684
|
-
assert.equal(reconnectedDevice.counters.taskResultsReceived, 0);
|
|
685
|
-
|
|
686
|
-
await wait(100);
|
|
687
|
-
const staleSessionIgnoredDevice = hub.listDevices()[0];
|
|
688
|
-
assert.equal(staleSessionIgnoredDevice.sessionId, reconnectedDevice.sessionId);
|
|
689
|
-
assert.equal(staleSessionIgnoredDevice.deviceName, 'Smoke Device Reconnected');
|
|
690
|
-
assert.equal(staleSessionIgnoredDevice.status.uptimeSec, 2);
|
|
691
|
-
assert.equal(staleSessionIgnoredDevice.latestTask, null);
|
|
692
|
-
assert.equal(staleSessionIgnoredDevice.counters.taskResultsReceived, 0);
|
|
693
|
-
|
|
694
|
-
replacementSocket.destroy();
|
|
695
|
-
await waitFor(() => hub.listDevices()[0]?.connected === false);
|
|
696
|
-
console.log('RemoteHub smoke OK');
|
|
697
|
-
} finally {
|
|
698
|
-
await hub.close();
|
|
699
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import net from 'net';
|
|
4
|
+
import assert from 'assert/strict';
|
|
5
|
+
import { createRemoteHub } from '../remote-hub.js';
|
|
6
|
+
|
|
7
|
+
function writeJsonLine(socket, payload) {
|
|
8
|
+
socket.write(`${JSON.stringify(payload)}\n`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function writeBinaryFrame(socket, header, payload) {
|
|
12
|
+
const framePayload = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
|
|
13
|
+
socket.write(`${JSON.stringify({
|
|
14
|
+
...header,
|
|
15
|
+
type: 'frame.binary',
|
|
16
|
+
byteLength: framePayload.length
|
|
17
|
+
})}\n`);
|
|
18
|
+
socket.write(framePayload);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function wait(ms) {
|
|
22
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultHub = createRemoteHub({
|
|
26
|
+
env: {
|
|
27
|
+
MINDEXEC_REMOTE_HUB: '0'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
assert.equal(defaultHub.getStatus().port, 5198, 'MindExecution RemoteHub must not reuse the LiveDesk 5197 port');
|
|
31
|
+
|
|
32
|
+
async function waitFor(predicate, timeoutMs = 3000) {
|
|
33
|
+
const startedAt = Date.now();
|
|
34
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
35
|
+
const value = predicate();
|
|
36
|
+
if (value) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
await wait(25);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new Error('Timed out waiting for RemoteHub smoke condition.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const hub = createRemoteHub({
|
|
46
|
+
env: {
|
|
47
|
+
MINDEXEC_REMOTE_HUB: '1',
|
|
48
|
+
REMOTE_HUB_HOST: '127.0.0.1',
|
|
49
|
+
REMOTE_HUB_PORT: '0',
|
|
50
|
+
REMOTE_HUB_PAIR_TOKEN: 'smoke-token',
|
|
51
|
+
REMOTE_HUB_TASK_TIMEOUT_MS: '120'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const smokePngFrame = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC', 'base64');
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await hub.start();
|
|
58
|
+
const status = hub.getStatus({ includeSecrets: true });
|
|
59
|
+
assert.equal(status.started, true);
|
|
60
|
+
assert.equal(status.canvasPagination, 'none');
|
|
61
|
+
|
|
62
|
+
const socket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
63
|
+
socket.setEncoding('utf8');
|
|
64
|
+
await new Promise((resolve, reject) => {
|
|
65
|
+
socket.once('connect', resolve);
|
|
66
|
+
socket.once('error', reject);
|
|
67
|
+
});
|
|
68
|
+
socket.on('error', () => { });
|
|
69
|
+
|
|
70
|
+
writeJsonLine(socket, {
|
|
71
|
+
type: 'hello',
|
|
72
|
+
pairToken: 'smoke-token',
|
|
73
|
+
deviceId: 'smoke-device',
|
|
74
|
+
deviceName: 'Smoke Device',
|
|
75
|
+
hostname: 'smoke-host',
|
|
76
|
+
platform: process.platform,
|
|
77
|
+
arch: process.arch,
|
|
78
|
+
pid: process.pid,
|
|
79
|
+
agentVersion: '0.0.0-smoke',
|
|
80
|
+
capabilities: {
|
|
81
|
+
status: true,
|
|
82
|
+
thumbnail: false,
|
|
83
|
+
control: true,
|
|
84
|
+
liveStream: true,
|
|
85
|
+
computerAgent: true,
|
|
86
|
+
taskDispatch: true,
|
|
87
|
+
aiAssist: true,
|
|
88
|
+
aiModel: 'fake-ai'
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
writeJsonLine(socket, {
|
|
92
|
+
type: 'status',
|
|
93
|
+
status: {
|
|
94
|
+
uptimeSec: 1,
|
|
95
|
+
totalMem: 2,
|
|
96
|
+
freeMem: 1
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const devices = await waitFor(() => {
|
|
101
|
+
const current = hub.listDevices();
|
|
102
|
+
return current.length === 1 && current[0].status?.uptimeSec === 1 ? current : null;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
assert.equal(devices[0].deviceId, 'smoke-device');
|
|
106
|
+
assert.equal(devices[0].connected, true);
|
|
107
|
+
assert.equal(hub.getStatus().deviceCount, 1);
|
|
108
|
+
|
|
109
|
+
const inputCommand = hub.sendInputControl('smoke-device', {
|
|
110
|
+
type: 'noop'
|
|
111
|
+
});
|
|
112
|
+
assert.equal(inputCommand.ok, true);
|
|
113
|
+
writeJsonLine(socket, {
|
|
114
|
+
type: 'command.result',
|
|
115
|
+
commandId: inputCommand.commandId,
|
|
116
|
+
result: {
|
|
117
|
+
input: true,
|
|
118
|
+
handled: true
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const inputDevice = await waitFor(() => {
|
|
122
|
+
const current = hub.listDevices();
|
|
123
|
+
return current[0]?.counters?.commandResultsReceived === 1 ? current[0] : null;
|
|
124
|
+
});
|
|
125
|
+
assert.equal(inputDevice.counters.commandsSent, 1);
|
|
126
|
+
|
|
127
|
+
const thumbnailCommand = hub.requestThumbnail('smoke-device', {
|
|
128
|
+
streamId: 'smoke-thumb',
|
|
129
|
+
maxWidth: 320,
|
|
130
|
+
maxHeight: 180,
|
|
131
|
+
quality: 50
|
|
132
|
+
});
|
|
133
|
+
assert.equal(thumbnailCommand.ok, true);
|
|
134
|
+
|
|
135
|
+
writeJsonLine(socket, {
|
|
136
|
+
type: 'thumbnail.frame',
|
|
137
|
+
commandId: thumbnailCommand.commandId,
|
|
138
|
+
streamId: 'smoke-thumb',
|
|
139
|
+
frameSeq: 1,
|
|
140
|
+
width: 2,
|
|
141
|
+
height: 1,
|
|
142
|
+
mimeType: 'image/png',
|
|
143
|
+
capturedAt: new Date().toISOString(),
|
|
144
|
+
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const thumbnailDevice = await waitFor(() => {
|
|
148
|
+
const current = hub.listDevices();
|
|
149
|
+
return current[0]?.latestThumbnail?.frameSeq === 1 ? current[0] : null;
|
|
150
|
+
});
|
|
151
|
+
assert.equal(thumbnailDevice.latestThumbnail.streamId, 'smoke-thumb');
|
|
152
|
+
assert.equal(thumbnailDevice.counters.thumbnailFramesReceived, 1);
|
|
153
|
+
const serializedFirstThumbnail = hub.getDeviceThumbnail('smoke-device', { includeDataUrl: false });
|
|
154
|
+
const serializedFirstThumbnailUrl = new URL(serializedFirstThumbnail.framePath, 'http://127.0.0.1');
|
|
155
|
+
|
|
156
|
+
const binaryThumbnailCommand = hub.requestThumbnail('smoke-device', {
|
|
157
|
+
streamId: 'smoke-thumb-binary',
|
|
158
|
+
maxWidth: 320,
|
|
159
|
+
maxHeight: 180,
|
|
160
|
+
quality: 50
|
|
161
|
+
});
|
|
162
|
+
assert.equal(binaryThumbnailCommand.ok, true);
|
|
163
|
+
writeBinaryFrame(socket, {
|
|
164
|
+
frameKind: 'thumbnail',
|
|
165
|
+
commandId: binaryThumbnailCommand.commandId,
|
|
166
|
+
streamId: 'smoke-thumb-binary',
|
|
167
|
+
frameSeq: 4,
|
|
168
|
+
width: 2,
|
|
169
|
+
height: 1,
|
|
170
|
+
mimeType: 'image/png',
|
|
171
|
+
capturedAt: new Date().toISOString()
|
|
172
|
+
}, smokePngFrame);
|
|
173
|
+
|
|
174
|
+
const binaryThumbnailDevice = await waitFor(() => {
|
|
175
|
+
const current = hub.listDevices();
|
|
176
|
+
return current[0]?.latestThumbnail?.frameSeq === 4 ? current[0] : null;
|
|
177
|
+
});
|
|
178
|
+
assert.equal(binaryThumbnailDevice.latestThumbnail.streamId, 'smoke-thumb-binary');
|
|
179
|
+
assert.equal(binaryThumbnailDevice.latestThumbnail.transport, 'binary');
|
|
180
|
+
assert.equal(binaryThumbnailDevice.latestThumbnail.byteLength, smokePngFrame.length);
|
|
181
|
+
assert.equal(typeof binaryThumbnailDevice.latestThumbnail.contentHash, 'string');
|
|
182
|
+
assert.equal(binaryThumbnailDevice.latestThumbnail.contentHash.length, 16);
|
|
183
|
+
assert.equal(binaryThumbnailDevice.latestThumbnail.sameContentStreak, 1);
|
|
184
|
+
assert.equal(binaryThumbnailDevice.counters.thumbnailFramesReceived, 2);
|
|
185
|
+
const serializedBinaryThumbnail = hub.getDeviceThumbnail('smoke-device', { includeDataUrl: false });
|
|
186
|
+
assert.equal(serializedBinaryThumbnail.streamId, 'smoke-thumb-binary');
|
|
187
|
+
assert.equal(serializedBinaryThumbnail.frameSeq, 4);
|
|
188
|
+
assert.equal(serializedBinaryThumbnail.contentHash, binaryThumbnailDevice.latestThumbnail.contentHash);
|
|
189
|
+
assert.ok(serializedBinaryThumbnail.framePath.includes('/api/remote/devices/smoke-device/thumbnail?'));
|
|
190
|
+
assert.ok(!('dataUrl' in serializedBinaryThumbnail));
|
|
191
|
+
assert.ok(!('payload' in serializedBinaryThumbnail));
|
|
192
|
+
assert.ok(!('accessToken' in serializedBinaryThumbnail));
|
|
193
|
+
const serializedThumbnailUrl = new URL(serializedBinaryThumbnail.framePath, 'http://127.0.0.1');
|
|
194
|
+
const thumbnailPayload = hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
195
|
+
token: serializedThumbnailUrl.searchParams.get('token'),
|
|
196
|
+
frameSeq: serializedThumbnailUrl.searchParams.get('seq'),
|
|
197
|
+
requireToken: true
|
|
198
|
+
});
|
|
199
|
+
assert.equal(thumbnailPayload?.mimeType, 'image/png');
|
|
200
|
+
assert.equal(thumbnailPayload?.byteLength, smokePngFrame.length);
|
|
201
|
+
assert.equal(Buffer.compare(thumbnailPayload.payload, smokePngFrame), 0);
|
|
202
|
+
const retainedThumbnailPayload = hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
203
|
+
token: serializedFirstThumbnailUrl.searchParams.get('token'),
|
|
204
|
+
frameSeq: serializedFirstThumbnailUrl.searchParams.get('seq'),
|
|
205
|
+
requireToken: true
|
|
206
|
+
});
|
|
207
|
+
assert.equal(retainedThumbnailPayload?.frame?.frameSeq, 1);
|
|
208
|
+
assert.equal(retainedThumbnailPayload?.byteLength, smokePngFrame.length);
|
|
209
|
+
assert.equal(Buffer.compare(retainedThumbnailPayload.payload, smokePngFrame), 0);
|
|
210
|
+
assert.equal(hub.getFramePayload('smoke-device', 'thumbnail', {
|
|
211
|
+
token: 'wrong-token',
|
|
212
|
+
frameSeq: 4,
|
|
213
|
+
requireToken: true
|
|
214
|
+
}), null);
|
|
215
|
+
|
|
216
|
+
const liveCommand = hub.startLiveStream('smoke-device', {
|
|
217
|
+
streamId: 'smoke-live',
|
|
218
|
+
fps: 5,
|
|
219
|
+
maxWidth: 320,
|
|
220
|
+
maxHeight: 180,
|
|
221
|
+
quality: 50
|
|
222
|
+
});
|
|
223
|
+
assert.equal(liveCommand.ok, true);
|
|
224
|
+
assert.equal(liveCommand.frameMode, 'remote-fast');
|
|
225
|
+
writeJsonLine(socket, {
|
|
226
|
+
type: 'stream.open',
|
|
227
|
+
commandId: liveCommand.commandId,
|
|
228
|
+
streamId: 'smoke-live',
|
|
229
|
+
mode: 'remote-fast',
|
|
230
|
+
frameMode: 'remote-fast',
|
|
231
|
+
frameProfile: 'jpeg-binary-v1',
|
|
232
|
+
encoding: 'image',
|
|
233
|
+
codec: 'png',
|
|
234
|
+
compression: 'image/png',
|
|
235
|
+
transferProtocol: 'mindexec.remote.frame.v2',
|
|
236
|
+
transferProtocolVersion: 2,
|
|
237
|
+
handshake: 'smartview-request-open-frame',
|
|
238
|
+
fps: 5,
|
|
239
|
+
openedAt: new Date().toISOString()
|
|
240
|
+
});
|
|
241
|
+
writeJsonLine(socket, {
|
|
242
|
+
type: 'stream.frame',
|
|
243
|
+
commandId: liveCommand.commandId,
|
|
244
|
+
streamId: 'smoke-live',
|
|
245
|
+
frameSeq: 2,
|
|
246
|
+
width: 2,
|
|
247
|
+
height: 1,
|
|
248
|
+
mimeType: 'image/png',
|
|
249
|
+
mode: 'remote-fast',
|
|
250
|
+
frameMode: 'remote-fast',
|
|
251
|
+
frameProfile: 'jpeg-binary-v1',
|
|
252
|
+
encoding: 'image',
|
|
253
|
+
codec: 'png',
|
|
254
|
+
compression: 'image/png',
|
|
255
|
+
transferProtocol: 'mindexec.remote.frame.v2',
|
|
256
|
+
transferProtocolVersion: 2,
|
|
257
|
+
handshake: 'smartview-request-open-frame',
|
|
258
|
+
fps: 5,
|
|
259
|
+
capturedAt: new Date().toISOString(),
|
|
260
|
+
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const liveDevice = await waitFor(() => {
|
|
264
|
+
const current = hub.listDevices();
|
|
265
|
+
return current[0]?.latestLiveFrame?.streamId === 'smoke-live' ? current[0] : null;
|
|
266
|
+
});
|
|
267
|
+
assert.equal(liveDevice.activeLiveStream.active, true);
|
|
268
|
+
assert.equal(liveDevice.activeLiveStream.open, true);
|
|
269
|
+
assert.equal(liveDevice.activeLiveStream.handshake, 'smartview-request-open-frame');
|
|
270
|
+
assert.equal(liveDevice.latestLiveFrame.mode, 'remote-fast');
|
|
271
|
+
assert.equal(liveDevice.latestLiveFrame.frameMode, 'remote-fast');
|
|
272
|
+
assert.equal(liveDevice.latestLiveFrame.compression, 'image/png');
|
|
273
|
+
assert.equal(liveDevice.counters.liveFramesReceived, 1);
|
|
274
|
+
const serializedFirstLiveFrame = hub.getDeviceLiveFrame('smoke-device', { includeDataUrl: false });
|
|
275
|
+
const serializedFirstLiveUrl = new URL(serializedFirstLiveFrame.framePath, 'http://127.0.0.1');
|
|
276
|
+
|
|
277
|
+
writeBinaryFrame(socket, {
|
|
278
|
+
frameKind: 'stream',
|
|
279
|
+
commandId: liveCommand.commandId,
|
|
280
|
+
streamId: 'smoke-live',
|
|
281
|
+
frameSeq: 5,
|
|
282
|
+
width: 2,
|
|
283
|
+
height: 1,
|
|
284
|
+
mimeType: 'image/png',
|
|
285
|
+
mode: 'remote-fast',
|
|
286
|
+
frameMode: 'remote-fast',
|
|
287
|
+
frameProfile: 'jpeg-binary-v1',
|
|
288
|
+
encoding: 'image',
|
|
289
|
+
codec: 'png',
|
|
290
|
+
compression: 'image/png',
|
|
291
|
+
transferProtocol: 'mindexec.remote.frame.v2',
|
|
292
|
+
transferProtocolVersion: 2,
|
|
293
|
+
handshake: 'smartview-request-open-frame',
|
|
294
|
+
fps: 5,
|
|
295
|
+
capturedAt: new Date().toISOString()
|
|
296
|
+
}, smokePngFrame);
|
|
297
|
+
|
|
298
|
+
const binaryLiveDevice = await waitFor(() => {
|
|
299
|
+
const current = hub.listDevices();
|
|
300
|
+
return current[0]?.latestLiveFrame?.frameSeq === 5 ? current[0] : null;
|
|
301
|
+
});
|
|
302
|
+
assert.equal(binaryLiveDevice.latestLiveFrame.streamId, 'smoke-live');
|
|
303
|
+
assert.equal(binaryLiveDevice.latestLiveFrame.transport, 'binary');
|
|
304
|
+
assert.equal(binaryLiveDevice.latestLiveFrame.byteLength, smokePngFrame.length);
|
|
305
|
+
assert.equal(typeof binaryLiveDevice.latestLiveFrame.contentHash, 'string');
|
|
306
|
+
assert.equal(binaryLiveDevice.latestLiveFrame.contentHash.length, 16);
|
|
307
|
+
assert.equal(binaryLiveDevice.latestLiveFrame.sameContentStreak, 1);
|
|
308
|
+
assert.equal(binaryLiveDevice.counters.liveFramesReceived, 2);
|
|
309
|
+
const serializedBinaryLiveFrame = hub.getDeviceLiveFrame('smoke-device', { includeDataUrl: false });
|
|
310
|
+
assert.equal(serializedBinaryLiveFrame.streamId, 'smoke-live');
|
|
311
|
+
assert.equal(serializedBinaryLiveFrame.frameSeq, 5);
|
|
312
|
+
assert.equal(serializedBinaryLiveFrame.frameMode, 'remote-fast');
|
|
313
|
+
assert.equal(serializedBinaryLiveFrame.compression, 'image/png');
|
|
314
|
+
assert.equal(serializedBinaryLiveFrame.contentHash, binaryLiveDevice.latestLiveFrame.contentHash);
|
|
315
|
+
assert.ok(serializedBinaryLiveFrame.framePath.includes('/api/remote/devices/smoke-device/live/frame?'));
|
|
316
|
+
assert.ok(!('dataUrl' in serializedBinaryLiveFrame));
|
|
317
|
+
assert.ok(!('payload' in serializedBinaryLiveFrame));
|
|
318
|
+
assert.ok(!('accessToken' in serializedBinaryLiveFrame));
|
|
319
|
+
const serializedLiveUrl = new URL(serializedBinaryLiveFrame.framePath, 'http://127.0.0.1');
|
|
320
|
+
const livePayload = hub.getFramePayload('smoke-device', 'live', {
|
|
321
|
+
token: serializedLiveUrl.searchParams.get('token'),
|
|
322
|
+
frameSeq: serializedLiveUrl.searchParams.get('seq'),
|
|
323
|
+
requireToken: true
|
|
324
|
+
});
|
|
325
|
+
assert.equal(livePayload?.mimeType, 'image/png');
|
|
326
|
+
assert.equal(livePayload?.byteLength, smokePngFrame.length);
|
|
327
|
+
assert.equal(Buffer.compare(livePayload.payload, smokePngFrame), 0);
|
|
328
|
+
const retainedLivePayload = hub.getFramePayload('smoke-device', 'live', {
|
|
329
|
+
token: serializedFirstLiveUrl.searchParams.get('token'),
|
|
330
|
+
frameSeq: serializedFirstLiveUrl.searchParams.get('seq'),
|
|
331
|
+
requireToken: true
|
|
332
|
+
});
|
|
333
|
+
assert.equal(retainedLivePayload?.frame?.frameSeq, 2);
|
|
334
|
+
assert.equal(retainedLivePayload?.byteLength, smokePngFrame.length);
|
|
335
|
+
assert.equal(Buffer.compare(retainedLivePayload.payload, smokePngFrame), 0);
|
|
336
|
+
assert.equal(hub.getFramePayload('smoke-device', 'live', {
|
|
337
|
+
token: serializedLiveUrl.searchParams.get('token'),
|
|
338
|
+
frameSeq: 4,
|
|
339
|
+
requireToken: true
|
|
340
|
+
}), null);
|
|
341
|
+
|
|
342
|
+
const staleFrameBefore = liveDevice.counters.liveFramesDropped;
|
|
343
|
+
writeJsonLine(socket, {
|
|
344
|
+
type: 'stream.frame',
|
|
345
|
+
streamId: 'stale-live',
|
|
346
|
+
frameSeq: 3,
|
|
347
|
+
width: 2,
|
|
348
|
+
height: 1,
|
|
349
|
+
mimeType: 'image/png',
|
|
350
|
+
capturedAt: new Date().toISOString(),
|
|
351
|
+
data: 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADElEQVR42mP8z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC'
|
|
352
|
+
});
|
|
353
|
+
const staleDropDevice = await waitFor(() => {
|
|
354
|
+
const current = hub.listDevices();
|
|
355
|
+
return current[0]?.counters?.liveFramesDropped > staleFrameBefore ? current[0] : null;
|
|
356
|
+
});
|
|
357
|
+
assert.equal(staleDropDevice.latestLiveFrame.streamId, 'smoke-live');
|
|
358
|
+
|
|
359
|
+
const stopLiveCommand = hub.stopLiveStream('smoke-device', {
|
|
360
|
+
streamId: 'smoke-live'
|
|
361
|
+
});
|
|
362
|
+
assert.equal(stopLiveCommand.ok, true);
|
|
363
|
+
assert.equal(hub.listDevices()[0].activeLiveStream.active, false);
|
|
364
|
+
|
|
365
|
+
const taskCommand = hub.requestAgentTask('smoke-device', {
|
|
366
|
+
instruction: 'Summarize current desktop status for the manager.',
|
|
367
|
+
title: 'Smoke task'
|
|
368
|
+
});
|
|
369
|
+
assert.equal(taskCommand.ok, true);
|
|
370
|
+
writeJsonLine(socket, {
|
|
371
|
+
type: 'command.result',
|
|
372
|
+
commandId: taskCommand.commandId,
|
|
373
|
+
result: {
|
|
374
|
+
kind: 'agent.task',
|
|
375
|
+
taskId: taskCommand.taskId,
|
|
376
|
+
status: 'completed',
|
|
377
|
+
summary: 'Smoke task accepted.',
|
|
378
|
+
completedAt: new Date().toISOString()
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const taskDevice = await waitFor(() => {
|
|
383
|
+
const current = hub.listDevices();
|
|
384
|
+
return current[0]?.latestTask?.taskId === taskCommand.taskId
|
|
385
|
+
&& current[0]?.latestTask?.status === 'completed'
|
|
386
|
+
? current[0]
|
|
387
|
+
: null;
|
|
388
|
+
});
|
|
389
|
+
assert.equal(taskDevice.latestTask.resultSummary, 'Smoke task accepted.');
|
|
390
|
+
assert.equal(taskDevice.counters.tasksQueued, 1);
|
|
391
|
+
assert.equal(taskDevice.counters.taskResultsReceived, 1);
|
|
392
|
+
|
|
393
|
+
const aiTaskCommand = hub.requestAgentTask('smoke-device', {
|
|
394
|
+
instruction: 'Use AI assist to summarize the smoke test state.',
|
|
395
|
+
title: 'Smoke AI task',
|
|
396
|
+
approvalLevel: 'ai-assist'
|
|
397
|
+
});
|
|
398
|
+
assert.equal(aiTaskCommand.ok, true);
|
|
399
|
+
assert.equal(aiTaskCommand.approvalLevel, 'ai-assist');
|
|
400
|
+
writeJsonLine(socket, {
|
|
401
|
+
type: 'command.result',
|
|
402
|
+
commandId: aiTaskCommand.commandId,
|
|
403
|
+
result: {
|
|
404
|
+
kind: 'agent.task',
|
|
405
|
+
mode: 'ai-assist',
|
|
406
|
+
taskId: aiTaskCommand.taskId,
|
|
407
|
+
status: 'completed',
|
|
408
|
+
summary: 'Smoke AI task accepted.',
|
|
409
|
+
model: 'smoke-ai-model',
|
|
410
|
+
responseId: 'smoke-ai-response',
|
|
411
|
+
completedAt: new Date().toISOString()
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const aiTaskDevice = await waitFor(() => {
|
|
416
|
+
const current = hub.listDevices();
|
|
417
|
+
return current[0]?.latestTask?.taskId === aiTaskCommand.taskId
|
|
418
|
+
&& current[0]?.latestTask?.approvalLevel === 'ai-assist'
|
|
419
|
+
&& current[0]?.latestTask?.status === 'completed'
|
|
420
|
+
? current[0]
|
|
421
|
+
: null;
|
|
422
|
+
});
|
|
423
|
+
assert.equal(aiTaskDevice.latestTask.resultSummary, 'Smoke AI task accepted.');
|
|
424
|
+
assert.equal(aiTaskDevice.latestTask.resultModel, 'smoke-ai-model');
|
|
425
|
+
assert.equal(aiTaskDevice.latestTask.resultResponseId, 'smoke-ai-response');
|
|
426
|
+
assert.equal(aiTaskDevice.counters.tasksQueued, 2);
|
|
427
|
+
assert.equal(aiTaskDevice.counters.taskResultsReceived, 2);
|
|
428
|
+
|
|
429
|
+
const batchTask = hub.requestAgentTaskBatch(['smoke-device', 'missing-smoke-device'], {
|
|
430
|
+
instruction: 'Dispatch a smoke batch to one connected and one missing device.',
|
|
431
|
+
title: 'Smoke batch'
|
|
432
|
+
});
|
|
433
|
+
assert.equal(batchTask.ok, true);
|
|
434
|
+
assert.equal(batchTask.total, 2);
|
|
435
|
+
assert.equal(batchTask.queued, 1);
|
|
436
|
+
assert.ok(batchTask.batchId);
|
|
437
|
+
assert.equal(batchTask.batch?.pending, 1);
|
|
438
|
+
assert.equal(batchTask.batch?.failed, 1);
|
|
439
|
+
assert.equal(batchTask.batch?.status, 'running');
|
|
440
|
+
const acceptedBatchItem = batchTask.results.find(result => result.deviceId === 'smoke-device');
|
|
441
|
+
assert.ok(acceptedBatchItem?.commandId);
|
|
442
|
+
writeJsonLine(socket, {
|
|
443
|
+
type: 'command.result',
|
|
444
|
+
commandId: acceptedBatchItem.commandId,
|
|
445
|
+
result: {
|
|
446
|
+
kind: 'agent.task',
|
|
447
|
+
taskId: acceptedBatchItem.taskId,
|
|
448
|
+
status: 'completed',
|
|
449
|
+
summary: 'Smoke batch item accepted.',
|
|
450
|
+
completedAt: new Date().toISOString()
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const completedBatch = await waitFor(() => {
|
|
455
|
+
const latest = hub.getLatestTaskBatch();
|
|
456
|
+
return latest?.batchId === batchTask.batchId
|
|
457
|
+
&& latest.completed === 1
|
|
458
|
+
&& latest.failed === 1
|
|
459
|
+
? latest
|
|
460
|
+
: null;
|
|
461
|
+
});
|
|
462
|
+
assert.equal(completedBatch.pending, 0);
|
|
463
|
+
assert.equal(completedBatch.status, 'completed-with-failures');
|
|
464
|
+
assert.equal(completedBatch.results.length, 2);
|
|
465
|
+
assert.equal(completedBatch.results.find(result => result.deviceId === 'missing-smoke-device')?.error, 'device-not-found');
|
|
466
|
+
|
|
467
|
+
const timeoutTaskCommand = hub.requestAgentTask('smoke-device', {
|
|
468
|
+
instruction: 'This task intentionally receives no agent response.',
|
|
469
|
+
title: 'Timeout task'
|
|
470
|
+
});
|
|
471
|
+
assert.equal(timeoutTaskCommand.ok, true);
|
|
472
|
+
const timeoutTaskDevice = await waitFor(() => {
|
|
473
|
+
const current = hub.listDevices();
|
|
474
|
+
return current[0]?.latestTask?.taskId === timeoutTaskCommand.taskId
|
|
475
|
+
&& current[0]?.latestTask?.status === 'failed'
|
|
476
|
+
? current[0]
|
|
477
|
+
: null;
|
|
478
|
+
}, 1000);
|
|
479
|
+
assert.equal(timeoutTaskDevice.latestTask.error, 'task-timeout');
|
|
480
|
+
assert.equal(timeoutTaskDevice.latestTask.resultSummary, 'task-timeout');
|
|
481
|
+
assert.equal(timeoutTaskDevice.counters.tasksQueued, 4);
|
|
482
|
+
assert.equal(timeoutTaskDevice.counters.taskResultsReceived, 4);
|
|
483
|
+
assert.equal(timeoutTaskDevice.counters.taskResultsFailed, 1);
|
|
484
|
+
assert.equal(timeoutTaskDevice.counters.taskResultsTimedOut, 1);
|
|
485
|
+
writeJsonLine(socket, {
|
|
486
|
+
type: 'command.result',
|
|
487
|
+
commandId: timeoutTaskCommand.commandId,
|
|
488
|
+
result: {
|
|
489
|
+
kind: 'agent.task',
|
|
490
|
+
taskId: timeoutTaskCommand.taskId,
|
|
491
|
+
status: 'completed',
|
|
492
|
+
summary: 'This late timeout result must be ignored.',
|
|
493
|
+
completedAt: new Date().toISOString()
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
await wait(100);
|
|
497
|
+
const lateTimeoutDevice = hub.listDevices()[0];
|
|
498
|
+
assert.equal(lateTimeoutDevice.latestTask.taskId, timeoutTaskCommand.taskId);
|
|
499
|
+
assert.equal(lateTimeoutDevice.latestTask.status, 'failed');
|
|
500
|
+
assert.equal(lateTimeoutDevice.latestTask.error, 'task-timeout');
|
|
501
|
+
assert.equal(lateTimeoutDevice.latestTask.resultSummary, 'task-timeout');
|
|
502
|
+
assert.equal(lateTimeoutDevice.counters.taskResultsReceived, 4);
|
|
503
|
+
|
|
504
|
+
const timeoutBatch = hub.requestAgentTaskBatch(['smoke-device'], {
|
|
505
|
+
instruction: 'This batch item intentionally times out before a late result arrives.',
|
|
506
|
+
title: 'Timeout batch'
|
|
507
|
+
});
|
|
508
|
+
assert.equal(timeoutBatch.ok, true);
|
|
509
|
+
assert.equal(timeoutBatch.total, 1);
|
|
510
|
+
assert.equal(timeoutBatch.queued, 1);
|
|
511
|
+
assert.equal(timeoutBatch.batch?.pending, 1);
|
|
512
|
+
const timeoutBatchItem = timeoutBatch.results.find(result => result.deviceId === 'smoke-device');
|
|
513
|
+
assert.ok(timeoutBatchItem?.commandId);
|
|
514
|
+
assert.ok(timeoutBatchItem?.taskId);
|
|
515
|
+
|
|
516
|
+
const timedOutBatch = await waitFor(() => {
|
|
517
|
+
const latest = hub.getLatestTaskBatch();
|
|
518
|
+
return latest?.batchId === timeoutBatch.batchId
|
|
519
|
+
&& latest.timedOut === 1
|
|
520
|
+
&& latest.pending === 0
|
|
521
|
+
? latest
|
|
522
|
+
: null;
|
|
523
|
+
}, 1000);
|
|
524
|
+
assert.equal(timedOutBatch.status, 'completed-with-failures');
|
|
525
|
+
assert.equal(timedOutBatch.failed, 1);
|
|
526
|
+
assert.equal(timedOutBatch.results[0]?.status, 'failed');
|
|
527
|
+
assert.equal(timedOutBatch.results[0]?.error, 'task-timeout');
|
|
528
|
+
|
|
529
|
+
writeJsonLine(socket, {
|
|
530
|
+
type: 'command.result',
|
|
531
|
+
commandId: timeoutBatchItem.commandId,
|
|
532
|
+
result: {
|
|
533
|
+
kind: 'agent.task',
|
|
534
|
+
taskId: timeoutBatchItem.taskId,
|
|
535
|
+
status: 'completed',
|
|
536
|
+
summary: 'This late batch timeout result must be ignored.',
|
|
537
|
+
completedAt: new Date().toISOString()
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
await wait(100);
|
|
541
|
+
const lateTimedOutBatch = hub.getLatestTaskBatch();
|
|
542
|
+
const lateTimedOutDevice = hub.listDevices()[0];
|
|
543
|
+
assert.equal(lateTimedOutBatch.batchId, timeoutBatch.batchId);
|
|
544
|
+
assert.equal(lateTimedOutBatch.status, 'completed-with-failures');
|
|
545
|
+
assert.equal(lateTimedOutBatch.completed, 0);
|
|
546
|
+
assert.equal(lateTimedOutBatch.failed, 1);
|
|
547
|
+
assert.equal(lateTimedOutBatch.timedOut, 1);
|
|
548
|
+
assert.equal(lateTimedOutBatch.results[0]?.status, 'failed');
|
|
549
|
+
assert.equal(lateTimedOutBatch.results[0]?.error, 'task-timeout');
|
|
550
|
+
assert.equal(lateTimedOutDevice.latestTask.taskId, timeoutBatchItem.taskId);
|
|
551
|
+
assert.equal(lateTimedOutDevice.latestTask.status, 'failed');
|
|
552
|
+
assert.equal(lateTimedOutDevice.latestTask.error, 'task-timeout');
|
|
553
|
+
assert.equal(lateTimedOutDevice.latestTask.resultSummary, 'task-timeout');
|
|
554
|
+
assert.equal(lateTimedOutDevice.counters.taskResultsReceived, 5);
|
|
555
|
+
assert.equal(lateTimedOutDevice.counters.taskResultsFailed, 2);
|
|
556
|
+
assert.equal(lateTimedOutDevice.counters.taskResultsTimedOut, 2);
|
|
557
|
+
|
|
558
|
+
const staleSessionTask = hub.requestAgentTask('smoke-device', {
|
|
559
|
+
instruction: 'This old session task must not survive reconnect.',
|
|
560
|
+
title: 'Reconnect stale task'
|
|
561
|
+
});
|
|
562
|
+
assert.equal(staleSessionTask.ok, true);
|
|
563
|
+
const oldSessionId = lateTimedOutDevice.sessionId;
|
|
564
|
+
|
|
565
|
+
const duplicateSocket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
566
|
+
duplicateSocket.setEncoding('utf8');
|
|
567
|
+
const duplicateMessages = [];
|
|
568
|
+
let duplicateBuffer = '';
|
|
569
|
+
await new Promise((resolve, reject) => {
|
|
570
|
+
duplicateSocket.once('connect', resolve);
|
|
571
|
+
duplicateSocket.once('error', reject);
|
|
572
|
+
});
|
|
573
|
+
duplicateSocket.on('error', () => { });
|
|
574
|
+
duplicateSocket.on('data', chunk => {
|
|
575
|
+
duplicateBuffer += chunk;
|
|
576
|
+
let lineBreakIndex = duplicateBuffer.indexOf('\n');
|
|
577
|
+
while (lineBreakIndex >= 0) {
|
|
578
|
+
const line = duplicateBuffer.slice(0, lineBreakIndex).trim();
|
|
579
|
+
duplicateBuffer = duplicateBuffer.slice(lineBreakIndex + 1);
|
|
580
|
+
if (line) {
|
|
581
|
+
duplicateMessages.push(JSON.parse(line));
|
|
582
|
+
}
|
|
583
|
+
lineBreakIndex = duplicateBuffer.indexOf('\n');
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
writeJsonLine(duplicateSocket, {
|
|
587
|
+
type: 'hello',
|
|
588
|
+
pairToken: 'smoke-token',
|
|
589
|
+
deviceId: 'smoke-device',
|
|
590
|
+
deviceName: 'Smoke Device Duplicate',
|
|
591
|
+
hostname: 'smoke-host-duplicate',
|
|
592
|
+
platform: process.platform,
|
|
593
|
+
arch: process.arch,
|
|
594
|
+
pid: process.pid,
|
|
595
|
+
agentVersion: '0.0.0-smoke-duplicate',
|
|
596
|
+
capabilities: {
|
|
597
|
+
status: true,
|
|
598
|
+
thumbnail: false,
|
|
599
|
+
control: false,
|
|
600
|
+
liveStream: true,
|
|
601
|
+
computerAgent: true,
|
|
602
|
+
taskDispatch: true,
|
|
603
|
+
aiAssist: false
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const duplicateDisconnect = await waitFor(() => (
|
|
608
|
+
duplicateMessages.find(message => message?.type === 'disconnect')
|
|
609
|
+
), 1000);
|
|
610
|
+
assert.equal(duplicateDisconnect.reason, 'duplicate-device-active');
|
|
611
|
+
assert.equal(duplicateDisconnect.activeSessionId, oldSessionId);
|
|
612
|
+
assert.equal(duplicateDisconnect.retryAfterMs >= 30000, true);
|
|
613
|
+
await wait(100);
|
|
614
|
+
const duplicateRejectedDevice = hub.listDevices()[0];
|
|
615
|
+
assert.equal(duplicateRejectedDevice.sessionId, oldSessionId);
|
|
616
|
+
assert.equal(duplicateRejectedDevice.deviceName, 'Smoke Device');
|
|
617
|
+
assert.equal(duplicateRejectedDevice.connected, true);
|
|
618
|
+
assert.equal(duplicateRejectedDevice.counters.duplicateConnectionsRejected, 1);
|
|
619
|
+
assert.equal(duplicateRejectedDevice.latestTask.taskId, staleSessionTask.taskId);
|
|
620
|
+
duplicateSocket.destroy();
|
|
621
|
+
|
|
622
|
+
socket.destroy();
|
|
623
|
+
const disconnectedDevice = await waitFor(() => {
|
|
624
|
+
const current = hub.listDevices();
|
|
625
|
+
return current.length === 1
|
|
626
|
+
&& current[0]?.sessionId === oldSessionId
|
|
627
|
+
&& current[0]?.connected === false
|
|
628
|
+
? current[0]
|
|
629
|
+
: null;
|
|
630
|
+
});
|
|
631
|
+
assert.equal(disconnectedDevice.latestTask.status, 'failed');
|
|
632
|
+
assert.equal(
|
|
633
|
+
['device-disconnected', 'task-timeout'].includes(disconnectedDevice.latestTask.error),
|
|
634
|
+
true);
|
|
635
|
+
|
|
636
|
+
const replacementSocket = net.createConnection({ host: '127.0.0.1', port: status.port });
|
|
637
|
+
replacementSocket.setEncoding('utf8');
|
|
638
|
+
await new Promise((resolve, reject) => {
|
|
639
|
+
replacementSocket.once('connect', resolve);
|
|
640
|
+
replacementSocket.once('error', reject);
|
|
641
|
+
});
|
|
642
|
+
replacementSocket.on('error', () => { });
|
|
643
|
+
writeJsonLine(replacementSocket, {
|
|
644
|
+
type: 'hello',
|
|
645
|
+
pairToken: 'smoke-token',
|
|
646
|
+
deviceId: 'smoke-device',
|
|
647
|
+
deviceName: 'Smoke Device Reconnected',
|
|
648
|
+
hostname: 'smoke-host-reconnected',
|
|
649
|
+
platform: process.platform,
|
|
650
|
+
arch: process.arch,
|
|
651
|
+
pid: process.pid,
|
|
652
|
+
agentVersion: '0.0.0-smoke-reconnected',
|
|
653
|
+
capabilities: {
|
|
654
|
+
status: true,
|
|
655
|
+
thumbnail: false,
|
|
656
|
+
control: false,
|
|
657
|
+
liveStream: true,
|
|
658
|
+
computerAgent: true,
|
|
659
|
+
taskDispatch: true,
|
|
660
|
+
aiAssist: true,
|
|
661
|
+
aiModel: 'fake-ai'
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
writeJsonLine(replacementSocket, {
|
|
665
|
+
type: 'status',
|
|
666
|
+
status: {
|
|
667
|
+
uptimeSec: 2,
|
|
668
|
+
totalMem: 4,
|
|
669
|
+
freeMem: 3
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
const reconnectedDevice = await waitFor(() => {
|
|
674
|
+
const current = hub.listDevices();
|
|
675
|
+
return current.length === 1
|
|
676
|
+
&& current[0]?.deviceName === 'Smoke Device Reconnected'
|
|
677
|
+
&& current[0]?.status?.uptimeSec === 2
|
|
678
|
+
? current[0]
|
|
679
|
+
: null;
|
|
680
|
+
});
|
|
681
|
+
assert.notEqual(reconnectedDevice.sessionId, oldSessionId);
|
|
682
|
+
assert.equal(reconnectedDevice.connected, true);
|
|
683
|
+
assert.equal(reconnectedDevice.latestTask, null);
|
|
684
|
+
assert.equal(reconnectedDevice.counters.taskResultsReceived, 0);
|
|
685
|
+
|
|
686
|
+
await wait(100);
|
|
687
|
+
const staleSessionIgnoredDevice = hub.listDevices()[0];
|
|
688
|
+
assert.equal(staleSessionIgnoredDevice.sessionId, reconnectedDevice.sessionId);
|
|
689
|
+
assert.equal(staleSessionIgnoredDevice.deviceName, 'Smoke Device Reconnected');
|
|
690
|
+
assert.equal(staleSessionIgnoredDevice.status.uptimeSec, 2);
|
|
691
|
+
assert.equal(staleSessionIgnoredDevice.latestTask, null);
|
|
692
|
+
assert.equal(staleSessionIgnoredDevice.counters.taskResultsReceived, 0);
|
|
693
|
+
|
|
694
|
+
replacementSocket.destroy();
|
|
695
|
+
await waitFor(() => hub.listDevices()[0]?.connected === false);
|
|
696
|
+
console.log('RemoteHub smoke OK');
|
|
697
|
+
} finally {
|
|
698
|
+
await hub.close();
|
|
699
|
+
}
|