edge-impulse-linux 1.26.0 → 1.26.2
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 +14 -5
- package/build/cli/linux/agent-capture.d.ts +29 -0
- package/build/cli/linux/agent-capture.js +94 -0
- package/build/cli/linux/agent-capture.js.map +1 -0
- package/build/cli/linux/agent-runner-metadata.d.ts +12 -3
- package/build/cli/linux/agent-runner-metadata.js +15 -3
- package/build/cli/linux/agent-runner-metadata.js.map +1 -1
- package/build/cli/linux/audio-utils.d.ts +1 -10
- package/build/cli/linux/audio-utils.js +2 -25
- package/build/cli/linux/audio-utils.js.map +1 -1
- package/build/cli/linux/runner-downloader.js +27 -1
- package/build/cli/linux/runner-downloader.js.map +1 -1
- package/build/cli/linux/runner-utils.d.ts +5 -0
- package/build/cli/linux/runner-utils.js +7 -2
- package/build/cli/linux/runner-utils.js.map +1 -1
- package/build/cli/linux/runner.js +332 -117
- package/build/cli/linux/runner.js.map +1 -1
- package/build/cli-common/model-monitor.d.ts +97 -10
- package/build/cli-common/model-monitor.js +380 -373
- package/build/cli-common/model-monitor.js.map +1 -1
- package/build/cli-common/remote-mgmt-service.d.ts +1 -0
- package/build/cli-common/remote-mgmt-service.js +29 -11
- package/build/cli-common/remote-mgmt-service.js.map +1 -1
- package/build/library/classifier/audio-classifier.d.ts +28 -3
- package/build/library/classifier/audio-classifier.js +126 -40
- package/build/library/classifier/audio-classifier.js.map +1 -1
- package/build/library/classifier/image-classifier.d.ts +14 -0
- package/build/library/classifier/image-classifier.js +79 -3
- package/build/library/classifier/image-classifier.js.map +1 -1
- package/build/library/classifier/libcwrapper.d.ts +7 -1
- package/build/library/classifier/libcwrapper.js +10 -2
- package/build/library/classifier/libcwrapper.js.map +1 -1
- package/build/library/classifier/linux-impulse-runner.d.ts +36 -1
- package/build/library/classifier/linux-impulse-runner.js +266 -55
- package/build/library/classifier/linux-impulse-runner.js.map +1 -1
- package/build/library/sensors/audio-utils.d.ts +4 -0
- package/build/library/sensors/audio-utils.js +23 -0
- package/build/library/sensors/audio-utils.js.map +1 -0
- package/build/library/sensors/gstreamer.d.ts +1 -1
- package/build/library/sensors/gstreamer.js +45 -9
- package/build/library/sensors/gstreamer.js.map +1 -1
- package/build/library/sensors/recorder.js +61 -23
- package/build/library/sensors/recorder.js.map +1 -1
- package/build/sdk/studio/sdk/api/devicesApi.d.ts +2 -2
- package/build/sdk/studio/sdk/api/devicesApi.js +2 -2
- package/build/sdk/studio/sdk/model/additionalMetricOptionalFullPrecisionValue.d.ts +7 -0
- package/build/sdk/studio/sdk/model/additionalMetricOptionalFullPrecisionValue.js +4 -0
- package/build/sdk/studio/sdk/model/additionalMetricOptionalFullPrecisionValue.js.map +1 -0
- package/build/sdk/studio/sdk/model/dSPGroupItem.d.ts +9 -1
- package/build/sdk/studio/sdk/model/dSPGroupItem.js +3 -1
- package/build/sdk/studio/sdk/model/dSPGroupItem.js.map +1 -1
- package/build/sdk/studio/sdk/model/device.d.ts +9 -0
- package/build/sdk/studio/sdk/model/device.js.map +1 -1
- package/build/sdk/studio/sdk/model/deviceApplication.d.ts +12 -0
- package/build/sdk/studio/sdk/model/deviceApplication.js +4 -0
- package/build/sdk/studio/sdk/model/deviceApplication.js.map +1 -0
- package/build/sdk/studio/sdk/model/deviceApplicationModel.d.ts +13 -0
- package/build/sdk/studio/sdk/model/deviceApplicationModel.js +4 -0
- package/build/sdk/studio/sdk/model/deviceApplicationModel.js.map +1 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.d.ts +9 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.js.map +1 -1
- package/build/sdk/studio/sdk/model/deviceModelDeploymentRequest.d.ts +5 -0
- package/build/sdk/studio/sdk/model/foldModelMetadata.d.ts +5 -0
- package/build/sdk/studio/sdk/model/getMonitoringEventDetailsResponse.d.ts +4 -0
- package/build/sdk/studio/sdk/model/getMonitoringEventDetailsResponse.js.map +1 -1
- package/build/sdk/studio/sdk/model/inferenceHistoryAggregate.d.ts +8 -0
- package/build/sdk/studio/sdk/model/kerasModelMetadata.d.ts +5 -0
- package/build/sdk/studio/sdk/model/kerasModelMetadataBase.d.ts +5 -0
- package/build/sdk/studio/sdk/model/kerasModelMetadataResponse.d.ts +5 -0
- package/build/sdk/studio/sdk/model/models.d.ts +3 -0
- package/build/sdk/studio/sdk/model/models.js +3 -0
- package/build/sdk/studio/sdk/model/models.js.map +1 -1
- package/build/sdk/studio/sdk/model/monitoringEventContext.d.ts +12 -0
- package/build/sdk/studio/sdk/model/monitoringInferenceSummary.d.ts +4 -0
- package/build/sdk/studio/sdk/model/userOrganization.d.ts +2 -0
- package/build/shared/viewmodels/init.d.ts +0 -1
- package/build/shared/viewmodels/init.js +0 -1
- package/build/shared/viewmodels/init.js.map +1 -1
- package/package.json +5 -2
- package/test/agent-bundle-lifecycle.test.ts +445 -0
- package/test/agent-bundle.test.ts +104 -0
- package/test/agent-capture.test.ts +528 -0
- package/test/agent-client.test.ts +263 -138
- package/test/agent-command-processor.test.ts +194 -0
- package/test/agent-preview-replacement.test.ts +114 -0
- package/test/agent-runner-configuration.test.ts +119 -0
- package/test/agent-runner-integration.test.ts +372 -0
- package/test/gstreamer.test.ts +1 -1
- package/test/helpers/mock-agent.ts +106 -0
- package/test/model-monitor.test.ts +250 -55
- package/test/monitoring-fixture.ts +168 -0
- package/test/monitoring-policy-protocol.test.ts +193 -1
- package/test/runner-preview.test.ts +59 -0
- package/test/summary-rules-fixtures.test.ts +194 -0
- package/test/utils/agent-runner-fixtures.ts +147 -0
- package/test/agent-runner-metadata.test.ts +0 -31
- package/test/sensor-selection.test.ts +0 -26
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exercises the client used by an agent-managed runner to register, report inference events and
|
|
3
|
-
* receive commands over the device agent's Unix-socket HTTP API. Each test starts a small mock agent
|
|
4
|
-
* server on a temporary Unix socket, registers only the routes needed for that flow, and asserts the
|
|
5
|
-
* JSON requests sent by the client together with its handling of agent responses and shutdown.
|
|
6
|
-
*/
|
|
7
1
|
import assert from 'node:assert';
|
|
8
2
|
import fs from 'node:fs/promises';
|
|
9
3
|
import http from 'node:http';
|
|
10
4
|
import os from 'node:os';
|
|
11
5
|
import Path from 'node:path';
|
|
6
|
+
import { mockAgentServer, MockAgentRequest, MockAgentResponse, MockAgentRoute, testRegistration, waitFor } from './helpers/mock-agent';
|
|
12
7
|
import { AgentClient } from '../cli-common/agent-client';
|
|
13
8
|
import {
|
|
14
9
|
Command,
|
|
@@ -16,25 +11,15 @@ import {
|
|
|
16
11
|
CompletedInferenceEvent,
|
|
17
12
|
EventBatch,
|
|
18
13
|
InferenceRunnerRegistration,
|
|
19
|
-
} from '../shared/device-protocol/
|
|
20
|
-
|
|
21
|
-
interface MockAgentRequest {
|
|
22
|
-
body: unknown;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface MockAgentResponse {
|
|
26
|
-
statusCode?: number;
|
|
27
|
-
headers?: http.OutgoingHttpHeaders;
|
|
28
|
-
body?: object | string;
|
|
29
|
-
keepOpen?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface MockAgentRoute {
|
|
33
|
-
method: 'GET' | 'POST';
|
|
34
|
-
path: string;
|
|
35
|
-
response: MockAgentResponse | ((request: MockAgentRequest) => MockAgentResponse | Promise<MockAgentResponse>);
|
|
36
|
-
}
|
|
14
|
+
} from '../shared/device-protocol/application-contract';
|
|
37
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Exercises `AgentClient`, the Unix-socket application transport for registration, commands and inference
|
|
18
|
+
* events. Normal flows register canonical state, maintain the command stream, post results, apply input
|
|
19
|
+
* policy and send inline or spooled inference inputs. Failure flows cover unavailable or malformed agent
|
|
20
|
+
* responses, registration recovery, command-result retry and expiry, spool failure, request timeout,
|
|
21
|
+
* stream reconnection and graceful shutdown while event requests are still pending.
|
|
22
|
+
*/
|
|
38
23
|
describe('AgentClient', () => {
|
|
39
24
|
let tempDir: string;
|
|
40
25
|
let socketPath: string;
|
|
@@ -71,7 +56,7 @@ describe('AgentClient', () => {
|
|
|
71
56
|
registration = mockRequest.body as InferenceRunnerRegistration;
|
|
72
57
|
return {
|
|
73
58
|
body: {
|
|
74
|
-
|
|
59
|
+
applicationId: 'vision',
|
|
75
60
|
inputPolicy: { mode: 'none' },
|
|
76
61
|
inlineSizeLimitBytes: 1024,
|
|
77
62
|
},
|
|
@@ -97,7 +82,7 @@ describe('AgentClient', () => {
|
|
|
97
82
|
await waitFor(() => commandStreamOpened);
|
|
98
83
|
|
|
99
84
|
assert.deepStrictEqual(registration, request);
|
|
100
|
-
assert.strictEqual(response.
|
|
85
|
+
assert.strictEqual(response.applicationId, 'vision');
|
|
101
86
|
await client.close();
|
|
102
87
|
});
|
|
103
88
|
|
|
@@ -106,7 +91,7 @@ describe('AgentClient', () => {
|
|
|
106
91
|
server = await mockAgentServer(socketPath, [{
|
|
107
92
|
method: 'POST',
|
|
108
93
|
path: '/v1/register',
|
|
109
|
-
response: { body: {
|
|
94
|
+
response: { body: { applicationId: 'vision' } },
|
|
110
95
|
}]);
|
|
111
96
|
|
|
112
97
|
const client = new AgentClient(socketPath);
|
|
@@ -130,7 +115,7 @@ describe('AgentClient', () => {
|
|
|
130
115
|
path: '/v1/register',
|
|
131
116
|
response: {
|
|
132
117
|
body: {
|
|
133
|
-
|
|
118
|
+
applicationId: 'vision',
|
|
134
119
|
inputPolicy: { mode: 'none' },
|
|
135
120
|
inlineSizeLimitBytes: 1024,
|
|
136
121
|
},
|
|
@@ -147,7 +132,7 @@ describe('AgentClient', () => {
|
|
|
147
132
|
]);
|
|
148
133
|
|
|
149
134
|
const response = await connecting;
|
|
150
|
-
assert.strictEqual(response.
|
|
135
|
+
assert.strictEqual(response.applicationId, 'vision');
|
|
151
136
|
await client.close();
|
|
152
137
|
});
|
|
153
138
|
|
|
@@ -162,8 +147,8 @@ describe('AgentClient', () => {
|
|
|
162
147
|
await rejected;
|
|
163
148
|
});
|
|
164
149
|
|
|
165
|
-
//
|
|
166
|
-
it('
|
|
150
|
+
// Rejects an unconfirmed model registration and reconnects with the last confirmed state.
|
|
151
|
+
it('restores the previous registration after an update transport failure', async () => {
|
|
167
152
|
let registrations = 0;
|
|
168
153
|
let commandStreams = 0;
|
|
169
154
|
let recoveredRegistration: InferenceRunnerRegistration | undefined;
|
|
@@ -183,7 +168,7 @@ describe('AgentClient', () => {
|
|
|
183
168
|
}
|
|
184
169
|
return {
|
|
185
170
|
body: {
|
|
186
|
-
|
|
171
|
+
applicationId: 'vision',
|
|
187
172
|
inputPolicy: { mode: 'none' },
|
|
188
173
|
inlineSizeLimitBytes: 1024,
|
|
189
174
|
},
|
|
@@ -220,10 +205,13 @@ describe('AgentClient', () => {
|
|
|
220
205
|
}],
|
|
221
206
|
} satisfies InferenceRunnerRegistration;
|
|
222
207
|
|
|
223
|
-
await
|
|
208
|
+
await assert.rejects(
|
|
209
|
+
client.updateRegistration(updatedRegistration),
|
|
210
|
+
/timed out after 20 ms/
|
|
211
|
+
);
|
|
224
212
|
await waitFor(() => registrations === 3 && commandStreams === 2);
|
|
225
213
|
|
|
226
|
-
assert.deepStrictEqual(recoveredRegistration,
|
|
214
|
+
assert.deepStrictEqual(recoveredRegistration, testRegistration());
|
|
227
215
|
await client.close();
|
|
228
216
|
});
|
|
229
217
|
|
|
@@ -238,12 +226,12 @@ describe('AgentClient', () => {
|
|
|
238
226
|
registrations++;
|
|
239
227
|
return registrations === 1 ? {
|
|
240
228
|
body: {
|
|
241
|
-
|
|
229
|
+
applicationId: 'vision',
|
|
242
230
|
inputPolicy: { mode: 'none' },
|
|
243
231
|
inlineSizeLimitBytes: 1024,
|
|
244
232
|
},
|
|
245
233
|
} : {
|
|
246
|
-
body: {
|
|
234
|
+
body: { applicationId: 'vision' },
|
|
247
235
|
};
|
|
248
236
|
},
|
|
249
237
|
},
|
|
@@ -278,7 +266,7 @@ describe('AgentClient', () => {
|
|
|
278
266
|
registrations++;
|
|
279
267
|
return {
|
|
280
268
|
body: {
|
|
281
|
-
|
|
269
|
+
applicationId: 'vision',
|
|
282
270
|
inputPolicy: { mode: 'none' },
|
|
283
271
|
inlineSizeLimitBytes: 1024,
|
|
284
272
|
},
|
|
@@ -309,16 +297,119 @@ describe('AgentClient', () => {
|
|
|
309
297
|
await client.close();
|
|
310
298
|
});
|
|
311
299
|
|
|
312
|
-
//
|
|
313
|
-
it('
|
|
314
|
-
let
|
|
300
|
+
// An expired command result is final; it must not disrupt a healthy stream or repeat the action.
|
|
301
|
+
it('does not reconnect when the agent refuses an expired command result', async () => {
|
|
302
|
+
let registrations = 0;
|
|
303
|
+
let commandStreams = 0;
|
|
304
|
+
let results = 0;
|
|
305
|
+
server = await mockAgentServer(socketPath, [
|
|
306
|
+
{
|
|
307
|
+
method: 'POST',
|
|
308
|
+
path: '/v1/register',
|
|
309
|
+
response: () => {
|
|
310
|
+
registrations++;
|
|
311
|
+
return {
|
|
312
|
+
body: {
|
|
313
|
+
applicationId: 'vision',
|
|
314
|
+
inputPolicy: { mode: 'none' },
|
|
315
|
+
inlineSizeLimitBytes: 1024,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
method: 'GET',
|
|
322
|
+
path: '/v1/commands',
|
|
323
|
+
response: () => {
|
|
324
|
+
commandStreams++;
|
|
325
|
+
return {
|
|
326
|
+
headers: { 'content-type': 'text/event-stream' },
|
|
327
|
+
body: 'data: {"id":"policy-expired","type":"updateInputPolicy",' +
|
|
328
|
+
'"inputPolicy":{"mode":"all"}}\n\n',
|
|
329
|
+
keepOpen: true,
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
method: 'POST',
|
|
335
|
+
path: '/v1/commands/policy-expired/result',
|
|
336
|
+
response: () => {
|
|
337
|
+
results++;
|
|
338
|
+
return {
|
|
339
|
+
statusCode: 404,
|
|
340
|
+
body: { code: 'unknown_command', message: 'The command has expired' },
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
const client = new AgentClient(socketPath, { reconnectDelayMs: 10 });
|
|
347
|
+
await client.connect(testRegistration());
|
|
348
|
+
await waitFor(() => results === 1);
|
|
349
|
+
await client.commands.waitForIdle(100);
|
|
350
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
351
|
+
|
|
352
|
+
assert.strictEqual(registrations, 1);
|
|
353
|
+
assert.strictEqual(commandStreams, 1);
|
|
354
|
+
await client.close();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// A request timeout response is ambiguous, so retry the identical result without applying the command twice.
|
|
358
|
+
it('retries a command result after HTTP 408', async () => {
|
|
359
|
+
let handlerCalls = 0;
|
|
360
|
+
const results: CommandResult[] = [];
|
|
361
|
+
server = await mockAgentServer(socketPath, commandResultRetryRoutes('activate-timeout', results, attempt =>
|
|
362
|
+
attempt === 1 ? { statusCode: 408, body: { message: 'Timed out' } } : { body: {} }));
|
|
363
|
+
|
|
364
|
+
const client = new AgentClient(socketPath, { reconnectDelayMs: 10 });
|
|
365
|
+
client.commands.on('activateBundle', () => {
|
|
366
|
+
handlerCalls++;
|
|
367
|
+
return Promise.resolve();
|
|
368
|
+
});
|
|
369
|
+
await client.connect(testRegistration());
|
|
370
|
+
await waitFor(() => results.length === 2);
|
|
371
|
+
|
|
372
|
+
assert.strictEqual(handlerCalls, 1);
|
|
373
|
+
assert.deepStrictEqual(results[1], results[0]);
|
|
374
|
+
await client.close();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// An internal contract response requires same-ID delivery retry because the first result may have been accepted.
|
|
378
|
+
it('retries a command result after an internal response', async () => {
|
|
379
|
+
let handlerCalls = 0;
|
|
380
|
+
const results: CommandResult[] = [];
|
|
381
|
+
server = await mockAgentServer(socketPath, commandResultRetryRoutes('activate-internal', results, attempt =>
|
|
382
|
+
attempt === 1 ? {
|
|
383
|
+
statusCode: 500,
|
|
384
|
+
body: { code: 'internal', message: 'Result state is uncertain' },
|
|
385
|
+
} : { body: {} }));
|
|
386
|
+
|
|
387
|
+
const client = new AgentClient(socketPath, { reconnectDelayMs: 10 });
|
|
388
|
+
client.commands.on('activateBundle', () => {
|
|
389
|
+
handlerCalls++;
|
|
390
|
+
return Promise.resolve();
|
|
391
|
+
});
|
|
392
|
+
await client.connect(testRegistration());
|
|
393
|
+
await waitFor(() => results.length === 2);
|
|
394
|
+
|
|
395
|
+
assert.strictEqual(handlerCalls, 1);
|
|
396
|
+
assert.deepStrictEqual(results[1], results[0]);
|
|
397
|
+
await client.close();
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// A permanently ambiguous result must eventually be logged and released so rollback can run.
|
|
401
|
+
it('bounds ambiguous result retries and processes the next queued command', async () => {
|
|
402
|
+
let handlerCalls = 0;
|
|
403
|
+
let ambiguousResults = 0;
|
|
404
|
+
let nextResults = 0;
|
|
405
|
+
const warnings: string[] = [];
|
|
315
406
|
server = await mockAgentServer(socketPath, [
|
|
316
407
|
{
|
|
317
408
|
method: 'POST',
|
|
318
409
|
path: '/v1/register',
|
|
319
410
|
response: {
|
|
320
411
|
body: {
|
|
321
|
-
|
|
412
|
+
applicationId: 'vision',
|
|
322
413
|
inputPolicy: { mode: 'none' },
|
|
323
414
|
inlineSizeLimitBytes: 1024,
|
|
324
415
|
},
|
|
@@ -329,21 +420,99 @@ describe('AgentClient', () => {
|
|
|
329
420
|
path: '/v1/commands',
|
|
330
421
|
response: {
|
|
331
422
|
headers: { 'content-type': 'text/event-stream' },
|
|
332
|
-
body: 'data: {"id":"
|
|
333
|
-
'"
|
|
423
|
+
body: 'data: {"id":"activate-stuck","type":"activateBundle",' +
|
|
424
|
+
'"bundle":{"kind":"model","path":"/models/version-2",' +
|
|
425
|
+
'"deploymentVersion":2}}\n\n' +
|
|
426
|
+
'data: {"id":"policy-next","type":"updateInputPolicy",' +
|
|
427
|
+
'"inputPolicy":{"mode":"none"}}\n\n',
|
|
334
428
|
keepOpen: true,
|
|
335
429
|
},
|
|
336
430
|
},
|
|
431
|
+
{
|
|
432
|
+
method: 'POST',
|
|
433
|
+
path: '/v1/commands/activate-stuck/result',
|
|
434
|
+
response: () => {
|
|
435
|
+
ambiguousResults++;
|
|
436
|
+
return {
|
|
437
|
+
statusCode: 500,
|
|
438
|
+
body: { code: 'internal', message: 'Result state is uncertain' },
|
|
439
|
+
};
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
method: 'POST',
|
|
444
|
+
path: '/v1/commands/policy-next/result',
|
|
445
|
+
response: () => {
|
|
446
|
+
nextResults++;
|
|
447
|
+
return { body: {} };
|
|
448
|
+
},
|
|
449
|
+
},
|
|
337
450
|
]);
|
|
338
451
|
|
|
339
|
-
const client = new AgentClient(socketPath
|
|
340
|
-
|
|
341
|
-
|
|
452
|
+
const client = new AgentClient(socketPath, {
|
|
453
|
+
reconnectDelayMs: 10,
|
|
454
|
+
commandResultRetryTimeoutMs: 25,
|
|
455
|
+
});
|
|
456
|
+
client.commands.on('activateBundle', () => {
|
|
457
|
+
handlerCalls++;
|
|
458
|
+
return Promise.resolve();
|
|
342
459
|
});
|
|
343
|
-
|
|
460
|
+
const originalWarn = console.warn;
|
|
461
|
+
console.warn = (...args: unknown[]) => warnings.push(args.map(String).join(' '));
|
|
462
|
+
try {
|
|
463
|
+
await client.connect(testRegistration());
|
|
464
|
+
await waitFor(() => nextResults === 1);
|
|
465
|
+
await client.commands.waitForIdle(100);
|
|
466
|
+
|
|
467
|
+
assert.strictEqual(handlerCalls, 1);
|
|
468
|
+
assert(ambiguousResults >= 2);
|
|
469
|
+
assert(warnings.some(message =>
|
|
470
|
+
message.includes('Stopped retrying result for command "activate-stuck" after 25 ms')));
|
|
471
|
+
}
|
|
472
|
+
finally {
|
|
473
|
+
console.warn = originalWarn;
|
|
474
|
+
await client.close();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
344
477
|
|
|
345
|
-
|
|
346
|
-
|
|
478
|
+
it('acknowledges activation failure and then handles rollback on the same stream', async () => {
|
|
479
|
+
const results: CommandResult[] = [];
|
|
480
|
+
let handled = 0;
|
|
481
|
+
server = await mockAgentServer(socketPath, [
|
|
482
|
+
{ method: 'POST', path: '/v1/register', response: { body: {
|
|
483
|
+
applicationId: 'vision', inputPolicy: { mode: 'none' }, inlineSizeLimitBytes: 1024,
|
|
484
|
+
} } },
|
|
485
|
+
{ method: 'GET', path: '/v1/commands', response: {
|
|
486
|
+
headers: { 'content-type': 'text/event-stream' }, keepOpen: true,
|
|
487
|
+
body: [ 7, 3 ].map(version => 'data: ' + JSON.stringify({ id: 'activate-' + version,
|
|
488
|
+
type: 'activateBundle', bundle: { kind: 'model', deploymentVersion: version,
|
|
489
|
+
path: '/models/12345/' + version } }) + '\n\n').join(''),
|
|
490
|
+
} },
|
|
491
|
+
...[ 7, 3 ].map(version => ({ method: 'POST' as const,
|
|
492
|
+
path: '/v1/commands/activate-' + version + '/result',
|
|
493
|
+
response: (request: MockAgentRequest) => {
|
|
494
|
+
results.push(request.body as CommandResult); return { statusCode: 204 };
|
|
495
|
+
},
|
|
496
|
+
})),
|
|
497
|
+
]);
|
|
498
|
+
const client = new AgentClient(socketPath);
|
|
499
|
+
try {
|
|
500
|
+
client.commands.on('activateBundle', command => {
|
|
501
|
+
handled++;
|
|
502
|
+
if (command.bundle.deploymentVersion === 7) {
|
|
503
|
+
throw new Error('failed executable');
|
|
504
|
+
}
|
|
505
|
+
return Promise.resolve();
|
|
506
|
+
});
|
|
507
|
+
await client.connect(testRegistration());
|
|
508
|
+
await waitFor(() => results.length === 2);
|
|
509
|
+
assert.strictEqual(handled, 2);
|
|
510
|
+
assert.deepStrictEqual(results, [
|
|
511
|
+
{ commandId: 'activate-7', type: 'activateBundle', success: false, reason: 'failed executable' },
|
|
512
|
+
{ commandId: 'activate-3', type: 'activateBundle', success: true },
|
|
513
|
+
]);
|
|
514
|
+
}
|
|
515
|
+
finally { await client.close(); }
|
|
347
516
|
});
|
|
348
517
|
|
|
349
518
|
// Confirms a selected small input is embedded in the event JSON and acknowledged by the agent.
|
|
@@ -355,7 +524,7 @@ describe('AgentClient', () => {
|
|
|
355
524
|
path: '/v1/register',
|
|
356
525
|
response: {
|
|
357
526
|
body: {
|
|
358
|
-
|
|
527
|
+
applicationId: 'vision',
|
|
359
528
|
inputPolicy: { mode: 'all' },
|
|
360
529
|
inlineSizeLimitBytes: 1024,
|
|
361
530
|
},
|
|
@@ -408,7 +577,7 @@ describe('AgentClient', () => {
|
|
|
408
577
|
path: '/v1/register',
|
|
409
578
|
response: {
|
|
410
579
|
body: {
|
|
411
|
-
|
|
580
|
+
applicationId: 'vision',
|
|
412
581
|
inputPolicy: { mode: 'all' },
|
|
413
582
|
inlineSizeLimitBytes: 1,
|
|
414
583
|
spoolDirectory,
|
|
@@ -465,7 +634,7 @@ describe('AgentClient', () => {
|
|
|
465
634
|
path: '/v1/register',
|
|
466
635
|
response: {
|
|
467
636
|
body: {
|
|
468
|
-
|
|
637
|
+
applicationId: 'vision',
|
|
469
638
|
inputPolicy: { mode: 'all' },
|
|
470
639
|
inlineSizeLimitBytes: 1,
|
|
471
640
|
spoolDirectory: Path.join(tempDir, 'missing-spool'),
|
|
@@ -512,7 +681,7 @@ describe('AgentClient', () => {
|
|
|
512
681
|
path: '/v1/register',
|
|
513
682
|
response: {
|
|
514
683
|
body: {
|
|
515
|
-
|
|
684
|
+
applicationId: 'vision',
|
|
516
685
|
inputPolicy: { mode: 'fraction', fraction: 0.5 },
|
|
517
686
|
inlineSizeLimitBytes: 1024,
|
|
518
687
|
},
|
|
@@ -565,7 +734,7 @@ describe('AgentClient', () => {
|
|
|
565
734
|
path: '/v1/register',
|
|
566
735
|
response: {
|
|
567
736
|
body: {
|
|
568
|
-
|
|
737
|
+
applicationId: 'vision',
|
|
569
738
|
inputPolicy: { mode: 'all', maxPerSecond: 1 },
|
|
570
739
|
inlineSizeLimitBytes: 1024,
|
|
571
740
|
},
|
|
@@ -610,7 +779,7 @@ describe('AgentClient', () => {
|
|
|
610
779
|
path: '/v1/register',
|
|
611
780
|
response: {
|
|
612
781
|
body: {
|
|
613
|
-
|
|
782
|
+
applicationId: 'vision',
|
|
614
783
|
inputPolicy: { mode: 'none' },
|
|
615
784
|
inlineSizeLimitBytes: 1024,
|
|
616
785
|
},
|
|
@@ -674,7 +843,7 @@ describe('AgentClient', () => {
|
|
|
674
843
|
path: '/v1/register',
|
|
675
844
|
response: {
|
|
676
845
|
body: {
|
|
677
|
-
|
|
846
|
+
applicationId: 'vision',
|
|
678
847
|
inputPolicy: { mode: 'none' },
|
|
679
848
|
inlineSizeLimitBytes: 1024,
|
|
680
849
|
},
|
|
@@ -724,7 +893,7 @@ describe('AgentClient', () => {
|
|
|
724
893
|
path: '/v1/register',
|
|
725
894
|
response: {
|
|
726
895
|
body: {
|
|
727
|
-
|
|
896
|
+
applicationId: 'vision',
|
|
728
897
|
inputPolicy: { mode: 'none' },
|
|
729
898
|
inlineSizeLimitBytes: 1024,
|
|
730
899
|
},
|
|
@@ -753,72 +922,44 @@ describe('AgentClient', () => {
|
|
|
753
922
|
});
|
|
754
923
|
});
|
|
755
924
|
|
|
756
|
-
/**
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
try {
|
|
774
|
-
let requestBody = '';
|
|
775
|
-
request.setEncoding('utf-8');
|
|
776
|
-
for await (const chunk of request) {
|
|
777
|
-
requestBody += chunk;
|
|
778
|
-
}
|
|
779
|
-
const mockRequest: MockAgentRequest = {
|
|
780
|
-
body: requestBody ? JSON.parse(requestBody) : undefined,
|
|
781
|
-
};
|
|
782
|
-
const mockResponse = typeof route.response === 'function' ?
|
|
783
|
-
await route.response(mockRequest) : route.response;
|
|
784
|
-
const statusCode = mockResponse.statusCode ?? 200;
|
|
785
|
-
const headers = { ...mockResponse.headers };
|
|
786
|
-
const body = typeof mockResponse.body === 'string' ?
|
|
787
|
-
mockResponse.body : mockResponse.body === undefined ? undefined : JSON.stringify(mockResponse.body);
|
|
788
|
-
if (typeof mockResponse.body === 'object' && !headers['content-type']) {
|
|
789
|
-
headers['content-type'] = 'application/json';
|
|
790
|
-
}
|
|
791
|
-
response.writeHead(statusCode, headers);
|
|
792
|
-
if (body !== undefined) {
|
|
793
|
-
response.write(body);
|
|
794
|
-
}
|
|
795
|
-
if (!mockResponse.keepOpen) {
|
|
796
|
-
response.end();
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
catch (error) {
|
|
800
|
-
response.writeHead(500).end(error instanceof Error ? error.message : String(error));
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
await new Promise<void>(resolve => server.listen(socketPath, resolve));
|
|
804
|
-
return server;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Returns the smallest valid inference-runner registration used to exercise the client transport
|
|
809
|
-
* independently of model loading.
|
|
810
|
-
*/
|
|
811
|
-
function testRegistration(): InferenceRunnerRegistration {
|
|
812
|
-
return {
|
|
813
|
-
kind: 'inference_runner',
|
|
814
|
-
version: '1.0.0',
|
|
815
|
-
contractVersion: 1,
|
|
816
|
-
artifact: {
|
|
817
|
-
kind: 'containerImage',
|
|
818
|
-
reference: 'inference-container:test',
|
|
925
|
+
/** Creates a complete agent session that initially refuses one command-result delivery. */
|
|
926
|
+
function commandResultRetryRoutes(
|
|
927
|
+
commandId: string,
|
|
928
|
+
results: CommandResult[],
|
|
929
|
+
response: (attempt: number) => MockAgentResponse
|
|
930
|
+
): MockAgentRoute[] {
|
|
931
|
+
return [
|
|
932
|
+
{
|
|
933
|
+
method: 'POST',
|
|
934
|
+
path: '/v1/register',
|
|
935
|
+
response: {
|
|
936
|
+
body: {
|
|
937
|
+
applicationId: 'vision',
|
|
938
|
+
inputPolicy: { mode: 'none' },
|
|
939
|
+
inlineSizeLimitBytes: 1024,
|
|
940
|
+
},
|
|
941
|
+
},
|
|
819
942
|
},
|
|
820
|
-
|
|
821
|
-
|
|
943
|
+
{
|
|
944
|
+
method: 'GET',
|
|
945
|
+
path: '/v1/commands',
|
|
946
|
+
response: {
|
|
947
|
+
headers: { 'content-type': 'text/event-stream' },
|
|
948
|
+
body: `data: {"id":"${commandId}","type":"activateBundle",` +
|
|
949
|
+
'"bundle":{"kind":"model","path":"/models/version-2",' +
|
|
950
|
+
'"deploymentVersion":2}}\n\n',
|
|
951
|
+
keepOpen: true,
|
|
952
|
+
},
|
|
953
|
+
},
|
|
954
|
+
{
|
|
955
|
+
method: 'POST',
|
|
956
|
+
path: `/v1/commands/${commandId}/result`,
|
|
957
|
+
response: request => {
|
|
958
|
+
results.push(request.body as CommandResult);
|
|
959
|
+
return response(results.length);
|
|
960
|
+
},
|
|
961
|
+
},
|
|
962
|
+
];
|
|
822
963
|
}
|
|
823
964
|
|
|
824
965
|
/**
|
|
@@ -835,19 +976,3 @@ function testInference(): CompletedInferenceEvent {
|
|
|
835
976
|
}],
|
|
836
977
|
};
|
|
837
978
|
}
|
|
838
|
-
|
|
839
|
-
/**
|
|
840
|
-
* Waits for an asynchronous server observation so the tests can verify command-stream setup without
|
|
841
|
-
* coupling themselves to the exact ordering of Node.js HTTP callbacks.
|
|
842
|
-
*
|
|
843
|
-
* @param predicate Returns true once the expected server-side observation has occurred.
|
|
844
|
-
*/
|
|
845
|
-
async function waitFor(predicate: () => boolean) {
|
|
846
|
-
const deadline = Date.now() + 1000;
|
|
847
|
-
while (!predicate()) {
|
|
848
|
-
if (Date.now() >= deadline) {
|
|
849
|
-
throw new Error('Timed out waiting for condition');
|
|
850
|
-
}
|
|
851
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
852
|
-
}
|
|
853
|
-
}
|