edge-impulse-linux 1.26.1 → 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 +7 -2
- 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 +3 -0
- package/build/cli/linux/runner-downloader.js.map +1 -1
- package/build/cli/linux/runner-utils.js +1 -1
- package/build/cli/linux/runner-utils.js.map +1 -1
- package/build/cli/linux/runner.js +96 -60
- 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 +16 -0
- package/build/library/classifier/audio-classifier.js +77 -1
- 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/linux-impulse-runner.d.ts +8 -1
- package/build/library/classifier/linux-impulse-runner.js +13 -0
- 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 +7 -4
- package/build/library/sensors/gstreamer.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 +5 -5
- package/build/sdk/studio/sdk/model/deviceApplication.d.ts +12 -0
- package/build/sdk/studio/sdk/model/{deviceWorkload.js → deviceApplication.js} +1 -1
- package/build/sdk/studio/sdk/model/deviceApplication.js.map +1 -0
- package/build/sdk/studio/sdk/model/{deviceWorkloadModel.d.ts → deviceApplicationModel.d.ts} +2 -2
- package/build/sdk/studio/sdk/model/{deviceWorkloadModel.js → deviceApplicationModel.js} +1 -1
- package/build/sdk/studio/sdk/model/deviceApplicationModel.js.map +1 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.d.ts +4 -4
- 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 +2 -2
- 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 -2
- package/build/sdk/studio/sdk/model/models.js +3 -2
- package/build/sdk/studio/sdk/model/models.js.map +1 -1
- package/build/sdk/studio/sdk/model/monitoringEventContext.d.ts +6 -2
- 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 +2 -2
- package/test/agent-bundle-lifecycle.test.ts +2 -2
- package/test/agent-bundle.test.ts +104 -0
- package/test/agent-capture.test.ts +528 -0
- package/test/agent-client.test.ts +64 -169
- package/test/agent-command-processor.test.ts +1 -1
- package/test/agent-preview-replacement.test.ts +114 -0
- package/test/agent-runner-configuration.test.ts +12 -3
- package/test/agent-runner-integration.test.ts +50 -8
- 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 +22 -7
- package/build/sdk/studio/sdk/model/deviceWorkload.d.ts +0 -12
- package/build/sdk/studio/sdk/model/deviceWorkload.js.map +0 -1
- package/build/sdk/studio/sdk/model/deviceWorkloadModel.js.map +0 -1
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import Path from 'node:path';
|
|
6
|
+
import { EventEmitter } from 'tsee';
|
|
7
|
+
import sharp from 'sharp';
|
|
8
|
+
import { AgentClient, AgentCommandProcessor, PreparedAgentInput } from '../cli-common/agent-client';
|
|
9
|
+
import { AgentCaptureController } from '../cli/linux/agent-capture';
|
|
10
|
+
import { AudioClassifier } from '../library/classifier/audio-classifier';
|
|
11
|
+
import { ImageClassifier } from '../library/classifier/image-classifier';
|
|
12
|
+
import {
|
|
13
|
+
LinuxImpulseRunner,
|
|
14
|
+
ModelInformation,
|
|
15
|
+
RunnerClassifyResponseSuccess,
|
|
16
|
+
RunnerHelloHasAnomaly,
|
|
17
|
+
RunnerHelloInferencingEngine,
|
|
18
|
+
} from '../library/classifier/linux-impulse-runner';
|
|
19
|
+
import {
|
|
20
|
+
ICamera,
|
|
21
|
+
ICameraProfilingInfoEvent,
|
|
22
|
+
ICameraSnapshotForInferenceEvent,
|
|
23
|
+
ICameraStartOptions,
|
|
24
|
+
} from '../library/sensors/icamera';
|
|
25
|
+
import { CaptureSample, Command, CommandResult } from '../shared/device-protocol/application-contract';
|
|
26
|
+
import { mockAgentServer, testRegistration, waitFor } from './helpers/mock-agent';
|
|
27
|
+
|
|
28
|
+
/** Covers live sensor capture, registration metadata, result redelivery and spool cleanup. */
|
|
29
|
+
describe('Agent capture', () => {
|
|
30
|
+
describe('AgentCaptureController', () => {
|
|
31
|
+
// Camera registration uses an observed source frame and capture returns metadata for the command frame.
|
|
32
|
+
it('advertises and captures from the live camera', async () => {
|
|
33
|
+
const frames = [
|
|
34
|
+
{ buffer: Buffer.from('registration'), capturedAt: 1, width: 640, height: 480 },
|
|
35
|
+
{ buffer: Buffer.from('capture'), capturedAt: 2, width: 640, height: 480 },
|
|
36
|
+
];
|
|
37
|
+
const classifier = {
|
|
38
|
+
captureNextFrame: () => Promise.resolve(frames.shift()!),
|
|
39
|
+
} as unknown as ImageClassifier;
|
|
40
|
+
const controller = new AgentCaptureController();
|
|
41
|
+
|
|
42
|
+
await controller.useCamera(classifier);
|
|
43
|
+
const captured = await controller.capture({ sensor: 'Camera (640x480)' });
|
|
44
|
+
|
|
45
|
+
assert.deepStrictEqual(controller.sensors(), [{
|
|
46
|
+
name: 'Camera (640x480)', frequencies: [], maxSampleLengthS: 60000,
|
|
47
|
+
}]);
|
|
48
|
+
assert.strictEqual(captured.format, 'jpg');
|
|
49
|
+
assert.deepStrictEqual(captured.metadata, {
|
|
50
|
+
sensor: 'Camera (640x480)', capturedAt: 2, width: 640, height: 480,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Registration and capture use the same live sample rate, while shutdown removes capture availability.
|
|
55
|
+
it('uses canonical microphone metadata and rejects capture after shutdown', async () => {
|
|
56
|
+
const classifier = {
|
|
57
|
+
sampleRateHz: () => 16_000,
|
|
58
|
+
captureWindow: () => Promise.resolve({
|
|
59
|
+
buffer: Buffer.from('wav'), capturedAt: 3, durationMs: 1000, sampleRateHz: 16_000,
|
|
60
|
+
}),
|
|
61
|
+
} as unknown as AudioClassifier;
|
|
62
|
+
const controller = new AgentCaptureController();
|
|
63
|
+
controller.useMicrophone(classifier);
|
|
64
|
+
|
|
65
|
+
assert.deepStrictEqual(controller.sensors(), [{
|
|
66
|
+
name: 'Microphone', frequencies: [ 16_000 ], maxSampleLengthS: 60,
|
|
67
|
+
}]);
|
|
68
|
+
await controller.capture({ sensor: 'Microphone', lengthMs: 1000 });
|
|
69
|
+
controller.disable();
|
|
70
|
+
await assert.rejects(
|
|
71
|
+
controller.capture({ sensor: 'Microphone', lengthMs: 1000 }),
|
|
72
|
+
/no live sensor is registered/);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('ImageClassifier capture', () => {
|
|
77
|
+
// Registration can inspect a live frame while inference stays paused until activation commits.
|
|
78
|
+
it('captures while paused without running inference', async () => {
|
|
79
|
+
const camera = new TestCamera();
|
|
80
|
+
const classifier = new ImageClassifier(fakeRunner(), camera);
|
|
81
|
+
const results: RunnerClassifyResponseSuccess[] = [];
|
|
82
|
+
classifier.on('result', result => results.push(result));
|
|
83
|
+
await classifier.start();
|
|
84
|
+
classifier.pause();
|
|
85
|
+
|
|
86
|
+
const capturing = classifier.captureNextFrame();
|
|
87
|
+
const jpeg = await sharp({
|
|
88
|
+
create: { width: 3, height: 2, channels: 3, background: 'white' },
|
|
89
|
+
}).jpeg().toBuffer();
|
|
90
|
+
camera.emit('snapshot', jpeg, 'source.jpg');
|
|
91
|
+
camera.emit('snapshotForInference', frame('before-activation.jpg'));
|
|
92
|
+
const captured = await capturing;
|
|
93
|
+
|
|
94
|
+
assert.strictEqual(captured.width, 3);
|
|
95
|
+
assert.strictEqual(captured.height, 2);
|
|
96
|
+
assert.deepStrictEqual(captured.buffer, jpeg);
|
|
97
|
+
assert.strictEqual(results.length, 0);
|
|
98
|
+
|
|
99
|
+
classifier.resume();
|
|
100
|
+
camera.emit('snapshotForInference', frame('after-capture.jpg'));
|
|
101
|
+
await waitFor(() => results.length === 1);
|
|
102
|
+
await classifier.stop();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('AudioClassifier capture', () => {
|
|
107
|
+
// A capture reads an exact window while other listeners continue receiving the same recorder data.
|
|
108
|
+
it('captures PCM from the live recorder without removing inference listeners', async () => {
|
|
109
|
+
const classifier = classifierWithStream();
|
|
110
|
+
const stream = liveStream(classifier);
|
|
111
|
+
let inferenceChunks = 0;
|
|
112
|
+
stream.on('data', () => inferenceChunks++);
|
|
113
|
+
|
|
114
|
+
const capturing = classifier.captureWindow(2);
|
|
115
|
+
stream.emit('data', Buffer.from([ 1, 0, 2, 0, 3, 0 ]));
|
|
116
|
+
const captured = await capturing;
|
|
117
|
+
|
|
118
|
+
assert.strictEqual(inferenceChunks, 1);
|
|
119
|
+
assert.strictEqual(captured.sampleRateHz, 1000);
|
|
120
|
+
assert.strictEqual(captured.durationMs, 2);
|
|
121
|
+
assert.deepStrictEqual(captured.buffer.subarray(44), Buffer.from([ 1, 0, 2, 0 ]));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Pausing the lifecycle must reject a pending capture so it cannot block the ordered command queue.
|
|
125
|
+
it('rejects a capture interrupted by lifecycle pause', async () => {
|
|
126
|
+
const classifier = classifierWithStream();
|
|
127
|
+
const capturing = classifier.captureWindow(10);
|
|
128
|
+
|
|
129
|
+
classifier.pause();
|
|
130
|
+
|
|
131
|
+
await assert.rejects(capturing, /interrupted because the classifier was paused/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// The classifier enforces the same one-minute limit advertised by the agent capture API.
|
|
135
|
+
it('rejects capture lengths above the advertised maximum', async () => {
|
|
136
|
+
const classifier = classifierWithStream();
|
|
137
|
+
|
|
138
|
+
await assert.rejects(classifier.captureWindow(60_001), /between 1 and 60000 ms/);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('Capture result retention', () => {
|
|
143
|
+
// A lost capture result retains its exact sample until redelivery succeeds, then releases it once.
|
|
144
|
+
it('reuses and releases a prepared capture after acknowledgement', async () => {
|
|
145
|
+
let handlerCalls = 0;
|
|
146
|
+
let releases = 0;
|
|
147
|
+
const acknowledged: CommandResult[] = [];
|
|
148
|
+
const processor = new AgentCommandProcessor(result => {
|
|
149
|
+
acknowledged.push(result);
|
|
150
|
+
return acknowledged.length === 1 ?
|
|
151
|
+
Promise.reject(new Error('result was lost')) : Promise.resolve();
|
|
152
|
+
});
|
|
153
|
+
const command = captureCommand('capture-retry');
|
|
154
|
+
const sample = captureSample();
|
|
155
|
+
processor.on('capture', () => {
|
|
156
|
+
handlerCalls++;
|
|
157
|
+
return Promise.resolve({
|
|
158
|
+
capture: sample,
|
|
159
|
+
preparedInput: preparedInput(sample, 8, () => releases++),
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
await assert.rejects(processor.process(command), /result was lost/);
|
|
164
|
+
assert.strictEqual(releases, 0);
|
|
165
|
+
await processor.process(command);
|
|
166
|
+
|
|
167
|
+
assert.strictEqual(handlerCalls, 1);
|
|
168
|
+
assert.strictEqual(releases, 1);
|
|
169
|
+
assert.deepStrictEqual(acknowledged[1], acknowledged[0]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Retention pressure replaces old samples with tombstones so redelivery cannot recapture them.
|
|
173
|
+
it('bounds failed capture retention without repeating physical capture', async () => {
|
|
174
|
+
let handlerCalls = 0;
|
|
175
|
+
const releases: string[] = [];
|
|
176
|
+
const acknowledged: CommandResult[] = [];
|
|
177
|
+
const processor = new AgentCommandProcessor(result => {
|
|
178
|
+
acknowledged.push(result);
|
|
179
|
+
return acknowledged.length <= 2 ?
|
|
180
|
+
Promise.reject(new Error('agent unavailable')) : Promise.resolve();
|
|
181
|
+
}, () => 5);
|
|
182
|
+
processor.on('capture', command => {
|
|
183
|
+
handlerCalls++;
|
|
184
|
+
const sample = captureSample();
|
|
185
|
+
return Promise.resolve({
|
|
186
|
+
capture: sample,
|
|
187
|
+
preparedInput: preparedInput(sample, 4, () => releases.push(command.id)),
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await assert.rejects(processor.process(captureCommand('capture-old')), /agent unavailable/);
|
|
192
|
+
await assert.rejects(processor.process(captureCommand('capture-new')), /agent unavailable/);
|
|
193
|
+
await processor.process(captureCommand('capture-old'));
|
|
194
|
+
await processor.process(captureCommand('capture-new'));
|
|
195
|
+
|
|
196
|
+
assert.strictEqual(handlerCalls, 2);
|
|
197
|
+
assert.deepStrictEqual(releases, [ 'capture-old', 'capture-new' ]);
|
|
198
|
+
assert.deepStrictEqual(acknowledged[2], {
|
|
199
|
+
commandId: 'capture-old',
|
|
200
|
+
type: 'capture',
|
|
201
|
+
success: false,
|
|
202
|
+
reason: 'Capture result expired before delivery; capture was not repeated',
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Shutdown releases an unacknowledged sample and refuses later delivery so spool ownership cannot leak.
|
|
207
|
+
it('releases retained capture input when closing', async () => {
|
|
208
|
+
let releases = 0;
|
|
209
|
+
const processor = new AgentCommandProcessor(() => Promise.reject(new Error('agent unavailable')));
|
|
210
|
+
const sample = captureSample();
|
|
211
|
+
processor.on('capture', () => Promise.resolve({
|
|
212
|
+
capture: sample,
|
|
213
|
+
preparedInput: preparedInput(sample, 8, () => releases++),
|
|
214
|
+
}));
|
|
215
|
+
|
|
216
|
+
await assert.rejects(processor.process(captureCommand('capture-close')), /agent unavailable/);
|
|
217
|
+
await processor.close(100);
|
|
218
|
+
|
|
219
|
+
assert.strictEqual(releases, 1);
|
|
220
|
+
await assert.rejects(
|
|
221
|
+
processor.process(captureCommand('capture-after-close')),
|
|
222
|
+
/processor has closed/
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('Capture transport', () => {
|
|
228
|
+
let tempDir: string;
|
|
229
|
+
let socketPath: string;
|
|
230
|
+
let server: http.Server | undefined;
|
|
231
|
+
|
|
232
|
+
beforeEach(async () => {
|
|
233
|
+
server = undefined;
|
|
234
|
+
tempDir = await fs.mkdtemp(Path.join(os.tmpdir(), 'ei-agent-capture-'));
|
|
235
|
+
socketPath = Path.join(tempDir, 'contract.sock');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
afterEach(async () => {
|
|
239
|
+
const activeServer = server;
|
|
240
|
+
server = undefined;
|
|
241
|
+
await new Promise<void>((resolve, reject) => {
|
|
242
|
+
if (!activeServer?.listening) {
|
|
243
|
+
resolve();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
activeServer.close(error => error ? reject(error) : resolve());
|
|
247
|
+
});
|
|
248
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// Verifies command handlers receive the validated, type-specific command.
|
|
252
|
+
it('delivers application commands to their registered handler', async () => {
|
|
253
|
+
let delivered: Command | undefined;
|
|
254
|
+
server = await mockAgentServer(socketPath, [
|
|
255
|
+
{
|
|
256
|
+
method: 'POST',
|
|
257
|
+
path: '/v1/register',
|
|
258
|
+
response: {
|
|
259
|
+
body: {
|
|
260
|
+
applicationId: 'vision',
|
|
261
|
+
inputPolicy: { mode: 'none' },
|
|
262
|
+
inlineSizeLimitBytes: 1024,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
method: 'GET',
|
|
268
|
+
path: '/v1/commands',
|
|
269
|
+
response: {
|
|
270
|
+
headers: { 'content-type': 'text/event-stream' },
|
|
271
|
+
body: 'data: {"id":"capture-1","type":"capture",' +
|
|
272
|
+
'"capture":{"sensor":"Microphone","lengthMs":2000}}\n\n',
|
|
273
|
+
keepOpen: true,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
method: 'POST',
|
|
278
|
+
path: '/v1/commands/capture-1/result',
|
|
279
|
+
response: { body: {} },
|
|
280
|
+
},
|
|
281
|
+
]);
|
|
282
|
+
|
|
283
|
+
const client = new AgentClient(socketPath);
|
|
284
|
+
client.commands.on('capture', command => {
|
|
285
|
+
delivered = command;
|
|
286
|
+
return client.prepareCapture({ type: 'wav', buffer: Buffer.from('sample') }, {
|
|
287
|
+
capturedAt: Date.now(),
|
|
288
|
+
sensor: command.capture.sensor,
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
await client.connect(testRegistration());
|
|
292
|
+
await waitFor(() => delivered !== undefined);
|
|
293
|
+
|
|
294
|
+
assert.strictEqual(delivered?.type, 'capture');
|
|
295
|
+
await client.close();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// Closing after a failed result post releases the retained spool file owned by that capture.
|
|
299
|
+
it('removes an unacknowledged capture spool when closing', async () => {
|
|
300
|
+
const spoolDirectory = Path.join(tempDir, 'capture-spool');
|
|
301
|
+
await fs.mkdir(spoolDirectory);
|
|
302
|
+
let spoolPath: string | undefined;
|
|
303
|
+
let results = 0;
|
|
304
|
+
server = await mockAgentServer(socketPath, [
|
|
305
|
+
{
|
|
306
|
+
method: 'POST',
|
|
307
|
+
path: '/v1/register',
|
|
308
|
+
response: {
|
|
309
|
+
body: {
|
|
310
|
+
applicationId: 'vision',
|
|
311
|
+
inputPolicy: { mode: 'none' },
|
|
312
|
+
inlineSizeLimitBytes: 1,
|
|
313
|
+
spoolDirectory,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
method: 'GET',
|
|
319
|
+
path: '/v1/commands',
|
|
320
|
+
response: {
|
|
321
|
+
headers: { 'content-type': 'text/event-stream' },
|
|
322
|
+
body: 'data: {"id":"capture-close","type":"capture",' +
|
|
323
|
+
'"capture":{"sensor":"Microphone","lengthMs":1000}}\n\n',
|
|
324
|
+
keepOpen: true,
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
method: 'POST',
|
|
329
|
+
path: '/v1/commands/capture-close/result',
|
|
330
|
+
response: request => {
|
|
331
|
+
results++;
|
|
332
|
+
const result = request.body as CommandResult;
|
|
333
|
+
assert(result.success && result.type === 'capture');
|
|
334
|
+
const input = result.capture.input;
|
|
335
|
+
if (input.location !== 'spool') throw new Error('Expected a spooled capture result');
|
|
336
|
+
spoolPath = Path.join(spoolDirectory, input.path);
|
|
337
|
+
return { statusCode: 503, body: { message: 'Unavailable' } };
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
]);
|
|
341
|
+
|
|
342
|
+
const client = new AgentClient(socketPath);
|
|
343
|
+
client.commands.on('capture', command => client.prepareCapture({
|
|
344
|
+
type: 'wav',
|
|
345
|
+
buffer: Buffer.from('sample'),
|
|
346
|
+
}, {
|
|
347
|
+
capturedAt: Date.now(),
|
|
348
|
+
sensor: command.capture.sensor,
|
|
349
|
+
}));
|
|
350
|
+
const originalWarn = console.warn;
|
|
351
|
+
console.warn = () => undefined;
|
|
352
|
+
try {
|
|
353
|
+
await client.connect(testRegistration());
|
|
354
|
+
await waitFor(() => results === 1 && spoolPath !== undefined);
|
|
355
|
+
await client.commands.waitForIdle(100);
|
|
356
|
+
assert(spoolPath);
|
|
357
|
+
await fs.access(spoolPath);
|
|
358
|
+
|
|
359
|
+
await client.close();
|
|
360
|
+
|
|
361
|
+
await assert.rejects(fs.access(spoolPath), error =>
|
|
362
|
+
(error as NodeJS.ErrnoException).code === 'ENOENT');
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
console.warn = originalWarn;
|
|
366
|
+
await client.close();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
/** Minimal camera whose frames are controlled directly by the test. */
|
|
374
|
+
class TestCamera extends EventEmitter<{
|
|
375
|
+
snapshot: (buffer: Buffer, filename: string) => void;
|
|
376
|
+
snapshotForInference: (event: ICameraSnapshotForInferenceEvent) => void;
|
|
377
|
+
error: (message: string) => void;
|
|
378
|
+
profilingInfo: (event: ICameraProfilingInfoEvent) => void;
|
|
379
|
+
}> implements ICamera {
|
|
380
|
+
async init(): Promise<void> { return Promise.resolve(); }
|
|
381
|
+
async listDevices(): Promise<string[]> { return [ 'test' ]; }
|
|
382
|
+
async start(_options: ICameraStartOptions): Promise<void> { return Promise.resolve(); }
|
|
383
|
+
async stop(): Promise<void> { return Promise.resolve(); }
|
|
384
|
+
getLastOptions(): ICameraStartOptions | undefined { return undefined; }
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Creates the runner surface used by ImageClassifier without transport concerns. */
|
|
388
|
+
function fakeRunner(): LinuxImpulseRunner {
|
|
389
|
+
return {
|
|
390
|
+
getModel: () => cameraModel(),
|
|
391
|
+
classify: () => Promise.resolve({
|
|
392
|
+
result: { classification: { live: 1 } },
|
|
393
|
+
timing: { dsp: 1, classification: 1, anomaly: 0 },
|
|
394
|
+
info: undefined,
|
|
395
|
+
}),
|
|
396
|
+
stop: () => Promise.resolve(''),
|
|
397
|
+
} as unknown as LinuxImpulseRunner;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** Returns one 1x1 RGB frame so the test reaches inference without image decoding. */
|
|
401
|
+
function frame(filename: string): ICameraSnapshotForInferenceEvent {
|
|
402
|
+
return {
|
|
403
|
+
filename,
|
|
404
|
+
imageForInferenceRgb: Buffer.from([ 1, 2, 3 ]),
|
|
405
|
+
imageForInferenceJpg: Buffer.from('jpeg'),
|
|
406
|
+
imageFromCameraJpg: Buffer.from('jpeg'),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Returns model metadata for the fixed camera pipeline used by the test. */
|
|
411
|
+
function cameraModel(): ModelInformation {
|
|
412
|
+
return {
|
|
413
|
+
project: { id: 1, name: 'Test', owner: 'Owner', deploy_version: 1 },
|
|
414
|
+
inferencingEngine: { inferencing_engine: RunnerHelloInferencingEngine.Tflite },
|
|
415
|
+
modelParameters: {
|
|
416
|
+
axis_count: 1,
|
|
417
|
+
frequency: 1,
|
|
418
|
+
has_anomaly: RunnerHelloHasAnomaly.None,
|
|
419
|
+
input_features_count: 1,
|
|
420
|
+
image_input_height: 1,
|
|
421
|
+
image_input_width: 1,
|
|
422
|
+
image_input_frames: 1,
|
|
423
|
+
image_channel_count: 3,
|
|
424
|
+
image_resize_mode: 'squash',
|
|
425
|
+
interval_ms: 1,
|
|
426
|
+
label_count: 1,
|
|
427
|
+
sensor: 3,
|
|
428
|
+
sensorType: 'camera',
|
|
429
|
+
labels: [ 'live' ],
|
|
430
|
+
model_type: 'classification',
|
|
431
|
+
slice_size: undefined,
|
|
432
|
+
use_continuous_mode: false,
|
|
433
|
+
has_performance_calibration: false,
|
|
434
|
+
inferencing_engine: RunnerHelloInferencingEngine.Tflite,
|
|
435
|
+
thresholds: [],
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Creates a classifier with a controlled live stream instead of opening a physical recorder. */
|
|
441
|
+
function classifierWithStream(): AudioClassifier {
|
|
442
|
+
const classifier = new AudioClassifier({
|
|
443
|
+
getModel: () => microphoneModel(),
|
|
444
|
+
} as unknown as LinuxImpulseRunner);
|
|
445
|
+
Object.assign(classifier as unknown as Record<string, unknown>, {
|
|
446
|
+
_audio: {
|
|
447
|
+
ee: new EventEmitter<{ data: (buffer: Buffer) => void }>(),
|
|
448
|
+
stop: () => Promise.resolve(),
|
|
449
|
+
},
|
|
450
|
+
_stopped: false,
|
|
451
|
+
});
|
|
452
|
+
return classifier;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Returns the controlled stream installed by classifierWithStream(). */
|
|
456
|
+
function liveStream(classifier: AudioClassifier): EventEmitter<{ data: (buffer: Buffer) => void }> {
|
|
457
|
+
return (classifier as unknown as {
|
|
458
|
+
_audio: { ee: EventEmitter<{ data: (buffer: Buffer) => void }> };
|
|
459
|
+
})._audio.ee;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Returns a 1 kHz microphone model so millisecond windows have simple byte counts. */
|
|
463
|
+
function microphoneModel(): ModelInformation {
|
|
464
|
+
return {
|
|
465
|
+
project: { id: 1, name: 'Test', owner: 'Owner', deploy_version: 1 },
|
|
466
|
+
inferencingEngine: { inferencing_engine: RunnerHelloInferencingEngine.Tflite },
|
|
467
|
+
modelParameters: {
|
|
468
|
+
axis_count: 1,
|
|
469
|
+
frequency: 1000,
|
|
470
|
+
has_anomaly: RunnerHelloHasAnomaly.None,
|
|
471
|
+
input_features_count: 2,
|
|
472
|
+
image_input_height: 0,
|
|
473
|
+
image_input_width: 0,
|
|
474
|
+
image_input_frames: 1,
|
|
475
|
+
image_channel_count: 0,
|
|
476
|
+
image_resize_mode: 'none',
|
|
477
|
+
interval_ms: 1,
|
|
478
|
+
label_count: 1,
|
|
479
|
+
sensor: 1,
|
|
480
|
+
sensorType: 'microphone',
|
|
481
|
+
labels: [ 'sound' ],
|
|
482
|
+
model_type: 'classification',
|
|
483
|
+
slice_size: undefined,
|
|
484
|
+
use_continuous_mode: false,
|
|
485
|
+
has_performance_calibration: false,
|
|
486
|
+
inferencing_engine: RunnerHelloInferencingEngine.Tflite,
|
|
487
|
+
thresholds: [],
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Creates a valid capture command for result-shape tests. */
|
|
493
|
+
function captureCommand(id: string): Extract<Command, { type: 'capture' }> {
|
|
494
|
+
return {
|
|
495
|
+
id,
|
|
496
|
+
type: 'capture',
|
|
497
|
+
capture: { sensor: 'Microphone', lengthMs: 1000 },
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** Creates the sample returned by a successful capture handler. */
|
|
502
|
+
function captureSample(): CaptureSample {
|
|
503
|
+
return {
|
|
504
|
+
input: {
|
|
505
|
+
bufferBase64: 'c2FtcGxl',
|
|
506
|
+
location: 'inline',
|
|
507
|
+
type: 'wav',
|
|
508
|
+
},
|
|
509
|
+
metadata: {
|
|
510
|
+
capturedAt: 1234,
|
|
511
|
+
durationMs: 1000,
|
|
512
|
+
sampleRateHz: 16000,
|
|
513
|
+
sensor: 'Microphone',
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** Wraps a capture input with observable retention ownership for processor tests. */
|
|
519
|
+
function preparedInput(sample: CaptureSample, retainedBytes: number, release: () => void): PreparedAgentInput {
|
|
520
|
+
return {
|
|
521
|
+
input: sample.input,
|
|
522
|
+
retainedBytes,
|
|
523
|
+
release: () => {
|
|
524
|
+
release();
|
|
525
|
+
return Promise.resolve();
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|