@trillboards/edge-sdk 0.2.260 → 0.2.263
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/deploy/windows/ci/test-published-install.ps1 +10 -1
- package/dist/CloudSensingManager.d.ts +36 -0
- package/dist/CloudSensingManager.d.ts.map +1 -1
- package/dist/CloudSensingManager.js +147 -20
- package/dist/CloudSensingManager.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/VideoSegmentUploader.d.ts +4 -0
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +21 -1
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/autoSense.d.ts +5 -4
- package/dist/autoSense.d.ts.map +1 -1
- package/dist/autoSense.js +24 -9
- package/dist/autoSense.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/sensingRunMode.d.ts +8 -0
- package/dist/sensingRunMode.d.ts.map +1 -1
- package/dist/sensingRunMode.js +59 -11
- package/dist/sensingRunMode.js.map +1 -1
- package/package.json +5 -4
- package/retained/CapturedTheftProfile.cjs +83 -0
- package/retained/ExperimentalTheftConnector.cjs +392 -0
- package/retained/FrameTheftRuntime.cjs +111 -0
- package/retained/FrameTheftWorker.py +136 -0
- package/retained/InstalledTheftLifecycle.cjs +165 -0
- package/retained/InstalledTheftPackage.cjs +91 -0
- package/retained/LiveTheftBinding.cjs +55 -0
- package/retained/ObservedReviewCaseEvidence.py +188 -0
- package/retained/ObservedSameWristPolicy.py +205 -0
- package/retained/OrderedPerceptionDelivery.cjs +72 -0
- package/retained/PairedTheftRoute.cjs +402 -0
- package/retained/ReplayRpc.cjs +157 -0
- package/retained/RetainedCaptureClient.cjs +63 -16
- package/retained/SavedTheftSession.cjs +110 -0
- package/retained/TheftCaseContract.cjs +36 -0
- package/retained/TheftCaseDelivery.cjs +81 -0
- package/retained/TheftDeliveryPump.cjs +41 -0
- package/retained/TheftMovementOwner.py +234 -0
- package/retained/TheftReviewPolicy.cjs +8 -0
- package/retained/__tests__/paired-theft-manager.test.cjs +509 -0
- package/retained/__tests__/support/live-shelf-api.cjs +139 -0
- package/retained/__tests__/support/load-sdk-sources.cjs +41 -0
- package/retained/__tests__/support/loopback-proxy.cjs +33 -0
- package/retained/__tests__/support/pinned-api-loader.cjs +11 -0
- package/retained/__tests__/support/theft-builder.cjs +61 -0
- package/retained/__tests__/support/theft-packet-fixture.cjs +58 -0
- package/retained/__tests__/support/theft-readiness.cjs +51 -0
- package/retained/__tests__/test_live_theft_input.py +103 -0
- package/retained/__tests__/theft-case-api.test.cjs +135 -0
- package/retained/__tests__/theft-ci-regression.test.cjs +92 -0
- package/retained/__tests__/theft-config.test.cjs +84 -0
- package/retained/__tests__/theft-entry.test.cjs +76 -0
- package/retained/__tests__/theft-native-recovery.test.cjs +90 -0
- package/retained/__tests__/theft-readiness.test.cjs +164 -0
- package/retained/manager.cjs +61 -7
- package/retained/pilot-profile-client.cjs +4 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
require('./support/load-sdk-sources.cjs');
|
|
3
|
+
if(process.platform==='win32')require('./support/loopback-proxy.cjs');
|
|
4
|
+
const {test: nodeTest, afterEach} = require('node:test');
|
|
5
|
+
const assert = require('node:assert/strict'), fs = require('node:fs'), os = require('node:os'), path = require('node:path');
|
|
6
|
+
const crypto = require('node:crypto'), http = require('node:http');
|
|
7
|
+
const {actorProofHash} = require('../../dist/ActorTracking');
|
|
8
|
+
const {configuredWebsiteReview} = require('../../dist/sensingRunMode');
|
|
9
|
+
const {createWebsiteManager} = require('../manager.cjs');
|
|
10
|
+
const {RF, POSE} = require('../ExperimentalTheftConnector.cjs');
|
|
11
|
+
const {FrameTheftRuntime} = require('../FrameTheftRuntime.cjs');
|
|
12
|
+
const GEMMA = 'ab7838cdfc8f77e54d8ca45eadceb20452d9f01e4bfade03e5dce27911b27e42';
|
|
13
|
+
const hash = value => crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
14
|
+
const sha = bytes => crypto.createHash('sha256').update(bytes).digest('hex');
|
|
15
|
+
const cleanups=[];let stopped=false;
|
|
16
|
+
const test=(name,fn)=>nodeTest(name,async t=>{if(stopped){t.skip('Dependent checks unrun after failure');return;}
|
|
17
|
+
try{await fn(t);}catch(error){stopped=true;throw error;}});
|
|
18
|
+
afterEach(async()=>{for(const close of cleanups.splice(0).reverse())await close();});
|
|
19
|
+
|
|
20
|
+
async function fixture({enabled=true,positive=true,live=false}={}) {
|
|
21
|
+
const directory=fs.mkdtempSync(path.join(os.tmpdir(),'paired-theft-manager-'));
|
|
22
|
+
const cameras=[0,1].map(i=>({name:'camera-'+i,rtspUrl:'rtsp://127.0.0.1/fixture-'+i,deviceToken:'token-'+i,screenId:String(i+1).repeat(24)}));
|
|
23
|
+
const environment={sourceVideoSha256:'a'.repeat(64),regionConfigurationSha256:'b'.repeat(64),frameSize:[640,480]};
|
|
24
|
+
const state={mode:live?'ordinary':'theft',selection:'theft-selection',opens:0,providers:0,ordinaryReviews:0,detects:0,reviews:0,now:Math.floor(Date.now()/500)*500+6500};
|
|
25
|
+
const api = live ? require('./support/live-shelf-api.cjs').liveShelfFixture(cameras[0],
|
|
26
|
+
{modelId:'rfdetr_medium',format:'onnx',sha256:RF}) : null;
|
|
27
|
+
const baseTime=state.now-6500, originals=new Map();
|
|
28
|
+
const server=http.createServer(async(req,res)=>{
|
|
29
|
+
res.setHeader('Content-Type','application/json');const url=new URL(req.url,'http://127.0.0.1');
|
|
30
|
+
if(url.pathname==='/ready') {
|
|
31
|
+
const chunks=[];for await(const c of req)chunks.push(c);const b=JSON.parse(Buffer.concat(chunks));
|
|
32
|
+
assert.deepEqual(b.models,[{modelId:'rfdetr_medium',sha256:RF}]);
|
|
33
|
+
res.end(JSON.stringify({version:1,ready:true,models:[{modelId:'rfdetr_medium',sha256:RF,task:'object_detection'}],capabilities:[]}));return;
|
|
34
|
+
}
|
|
35
|
+
const camera=cameras.find(c=>c.deviceToken===req.headers['x-device-token']);
|
|
36
|
+
if(!camera){res.writeHead(403).end('{}');return;}
|
|
37
|
+
if(url.pathname.endsWith('/capabilities')) {
|
|
38
|
+
res.end(JSON.stringify({retainedReview:true,protocolVersion:1,lateEvidenceAccepted:true,timedModes:['any','wait_recheck'],cameraId:camera.screenId,
|
|
39
|
+
maxBodyBytes:2*1024*1024,maxCaptureAgeMs:120000}));return;
|
|
40
|
+
}
|
|
41
|
+
if(!url.pathname.endsWith('/sensing-profile')){res.writeHead(405).end('{}');return;}
|
|
42
|
+
if (api && camera === cameras[0] && state.mode === 'theft') {
|
|
43
|
+
try { res.end(JSON.stringify(await api.serve(req.headers))); }
|
|
44
|
+
catch (error) { res.writeHead(500).end(JSON.stringify({reason:error.stack})); }
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const theft=camera===cameras[0]&&state.mode==='theft',active=camera!==cameras[0]||state.mode!=='inactive';
|
|
48
|
+
const profileId=theft?'theft-profile':'ordinary-profile',field={field:'review',type:'boolean',description:'Review this camera.'};
|
|
49
|
+
const identity={version:1,kind:'wait_boolean_endpoints',screenId:camera.screenId,profileId,profileName:theft?'Theft experiment':'Ordinary profile',
|
|
50
|
+
rules:[{routeId:'route-'+camera.name,revision:'r1',field:'review',waitMs:1000}]};
|
|
51
|
+
const issuedAtMs=Date.now();
|
|
52
|
+
res.end(JSON.stringify({success:true,screenId:camera.screenId,profileState:active?'active':'inactive',profileId:active?profileId:null,
|
|
53
|
+
profileName:active?identity.profileName:null,profileType:active?'custom_intent':null,fields:active?[field]:[],absenceWatchedFields:[],
|
|
54
|
+
retainedPilot:{version:1,reviewFieldSet:'declared'},
|
|
55
|
+
...(active?{websiteReviewAdmission:{...identity,revision:hash(identity),lease:{issuedAtMs,expiresAtMs:issuedAtMs+30000}}}:{}),
|
|
56
|
+
fieldRouting:{vlm:active?[field]:[],producer:[],withheld:[],operatingPoints:{},alertFocusRegions:state.regions??[]},
|
|
57
|
+
modelSelection:active?{version:1,selectionId:theft?state.selection:'ordinary-selection',
|
|
58
|
+
models:[{modelId:'gemma_4_e2b',format:'litert-lm',sha256:GEMMA},...(theft?[{modelId:'rfdetr_medium',format:'onnx',sha256:RF}]:[])],
|
|
59
|
+
fieldOwners:[{field:'review',modelId:'gemma_4_e2b'}],...(theft?{tasks:[{task:'actor_detection',modelId:'rfdetr_medium',minConfidence:.1}]}:{})}:null}));
|
|
60
|
+
});
|
|
61
|
+
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
|
|
62
|
+
cleanups.push(async()=>{server.closeAllConnections();await new Promise(resolve=>server.close(resolve));const owned=fs.realpathSync(directory),base=fs.realpathSync(os.tmpdir());assert(owned.startsWith(base+path.sep)&&!fs.lstatSync(directory).isSymbolicLink());fs.rmSync(owned,{recursive:true});assert(!fs.existsSync(directory));});
|
|
63
|
+
const base='http://127.0.0.1:'+server.address().port;
|
|
64
|
+
const registration=api?.registration ?? {feedName:cameras[0].name,profileId:'theft-profile',selectionId:'theft-selection',sceneId:1,environment};
|
|
65
|
+
const config=configuredWebsiteReview({apiBaseUrl:base,cameras,dataDir:directory,localSensing:{enabled:true}});
|
|
66
|
+
const input={...config,pilot:{websiteManaged:true,requiresDetector:true,...(enabled?{experimentalTheft:{version:1,profiles:[registration]}}:{})}};
|
|
67
|
+
const rpc={async call(method,body){
|
|
68
|
+
assert.equal(method,'detect');state.detects++;const f=body.native_frame,scope=body.native_scope,key=hash(scope);
|
|
69
|
+
const rows=originals.get(key)??[];rows.push(f);originals.set(key,rows);
|
|
70
|
+
const actor={kind:'person',cameraId:scope.cameraId,epoch:key,id:'p'};
|
|
71
|
+
const unsigned={...body.tracking,algorithm:'bytetrack_2.6.1',epoch:key,imageSha256:f.sha256,contextSha256:'c'.repeat(64),
|
|
72
|
+
modelHashes:{rfdetr_medium:RF},continuity:'continued',actors:[{detectionIndex:0,actor}],unconfirmed:[],endedActors:[]};
|
|
73
|
+
const tracking={...unsigned,sha256:actorProofHash(unsigned)},ref=p=>[p.sourceIndex,p.capturedAtMs,p.sha256];
|
|
74
|
+
const receipt=positive&&rows.length===13?[{caseId:key,actor:actorProofHash(actor),kind:'open_case',firstCaptureMs:rows[6].capturedAtMs,
|
|
75
|
+
deadlineMs:rows[6].capturedAtMs+90000,snapshotAnchorMs:f.capturedAtMs,pictures:rows.map(ref),
|
|
76
|
+
episodes:[{originMs:rows[4].capturedAtMs,arrivalMs:rows[6].capturedAtMs,side:'right',support:rows.slice(4,7).map(ref)}]}]:[];
|
|
77
|
+
return {detections:[{label:'person',confidence:.9,box:{x:100,y:70,width:180,height:300}}],inference_ms:3,
|
|
78
|
+
model:'rfdetr_medium',model_hashes:{rfdetr_medium:RF},tracking,
|
|
79
|
+
lab_sidecar:{inputBinding:{...body.tracking,testOnly:false,nativeScope:scope,imageSha256:f.sha256,poseModelSha256:POSE,
|
|
80
|
+
modelHashes:{rfdetr_medium:RF},trackingSha256:tracking.sha256},cameraEvidence:{guard:'stable_hypothesis',trackerResetDiagnostic:false,resetMovementEvidence:false},
|
|
81
|
+
movementObservation:{cues:[],caseEvidenceReceipts:receipt}}};
|
|
82
|
+
}};
|
|
83
|
+
const runtime={rpc,describeOriginal:FrameTheftRuntime.prototype.describeOriginal,
|
|
84
|
+
reviewer:live?null:{async review(packet,{deadlineMs}){state.reviews++;assert.equal(packet.pictures.length,13);assert.equal(deadlineMs,packet.receipt.firstCaptureMs+90000);
|
|
85
|
+
return {status:'completed',opinion:{movement:'unclear',explanation:'Controlled model-free fixture'}};}},
|
|
86
|
+
...(live ? { caseTransportFor: () => ({ async accept() { throw Error('No delivery authorized in this fixture'); } }) } : {})};
|
|
87
|
+
const deps={...(enabled?{theftRuntime:runtime}:{}),detectorFieldProducerOptions:{baseUrl:base,timeoutMs:1000},
|
|
88
|
+
rtspProviderFactory:()=>{state.providers++;return {isOpen:()=>false,open:async()=>{state.opens++;throw Error('No camera run authorized');}};},
|
|
89
|
+
localProviderFactory:()=>({analyze(){state.ordinaryReviews++;throw Error('No ordinary model run authorized');}})};
|
|
90
|
+
let built;
|
|
91
|
+
async function build(){built=await createWebsiteManager(input,path.join(directory,'state'),deps);return built;}
|
|
92
|
+
async function refresh(mode){state.mode=mode;built.clients[0].client.client.lastProfileFetchMs=0;await built.clients[0].prepareReview();return built.clients[0].captureReviewContext();}
|
|
93
|
+
function retain(i,client=built.clients[0],context=client.captureReviewContext()) {
|
|
94
|
+
const jpeg=Buffer.concat([Buffer.from([255,216,255,192,0,11,8,1,224,2,128,1,1,17,0,255,217]),Buffer.from(String(i))]);
|
|
95
|
+
client.retainOrderedCapture({name:client.cameraId,enqueuedAtMs:baseTime+i*500,jpeg,reviewContext:context});
|
|
96
|
+
return client.previousCaptureRecord;
|
|
97
|
+
}
|
|
98
|
+
async function capture(i){const row=retain(i);assert.equal(await built.clients[0].perceiveNextOrderedCapture(),true);return row;}
|
|
99
|
+
return {directory,input,deps,state,registration,runtime,build,refresh,retain,capture,baseTime,api};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
test('live shelf profile selection starts case review and switching away stops it without affecting the other camera', async () => {
|
|
103
|
+
const f = await fixture({live:true}), r = await f.build();
|
|
104
|
+
const client = r.clients[0], peer = r.clients[1];
|
|
105
|
+
const route = r.theftRoutes.get('camera-0');
|
|
106
|
+
assert.equal(client.isNativeTheftActive(), false);
|
|
107
|
+
f.api.verifyCatalogueIsolation();
|
|
108
|
+
assert.equal(await f.api.canOffer(f.api.identity.ownerId), true);
|
|
109
|
+
assert.equal(await f.api.canOffer('another-owner'), false);
|
|
110
|
+
const first = await f.api.select('a'.repeat(64));
|
|
111
|
+
const context = await f.refresh('theft');
|
|
112
|
+
const scope = context.privateTheftSession.scope;
|
|
113
|
+
assert.equal(context.websiteReviewAdmission.profileId, first);
|
|
114
|
+
assert.equal(scope.sourceKind, 'live_shelf_review_v1');
|
|
115
|
+
assert.equal(scope.sourceId, f.api.environment.sourceId);
|
|
116
|
+
assert.equal(scope.regionConfigurationSha256, f.api.environment.regionConfigurationSha256);
|
|
117
|
+
assert.equal(Object.hasOwn(scope, 'sourceVideoSha256'), false);
|
|
118
|
+
assert.equal(context.modelSelection.models.length, 1);
|
|
119
|
+
assert.equal(client.isNativeTheftActive(), true);
|
|
120
|
+
assert.equal((await f.api.resolveCase()).profileId, first);
|
|
121
|
+
for (let i = 0; i < 13; i++) await f.capture(i);
|
|
122
|
+
const deliveries = route.deliveries();
|
|
123
|
+
assert.equal(deliveries.length, 1);
|
|
124
|
+
const [envelope] = deliveries[0].pending();
|
|
125
|
+
assert.equal(envelope.profileId, first);
|
|
126
|
+
assert.equal(envelope.packet.pictures.length, 13);
|
|
127
|
+
assert.equal(envelope.packet.receipt.deadlineMs, f.baseTime + 3000 + 90000);
|
|
128
|
+
assert.equal(envelope.packet.opinionRole, 'not_requested_human_review');
|
|
129
|
+
assert.equal(f.state.detects, 13);
|
|
130
|
+
assert.equal(f.state.reviews, 0);
|
|
131
|
+
assert.equal(f.state.ordinaryReviews, 0);
|
|
132
|
+
const peerRow = f.retain(0,peer);
|
|
133
|
+
assert.equal(peerRow.perceptionDelivery, undefined);
|
|
134
|
+
assert.equal(peerRow.candidate.reviewContext.privateTheftSession, undefined);
|
|
135
|
+
const unfinished = f.retain(13,client);
|
|
136
|
+
assert.equal(unfinished.perceptionDelivery.status, 'awaiting_perception');
|
|
137
|
+
const savedImageHash = unfinished.imageSha256;
|
|
138
|
+
f.api.stop();
|
|
139
|
+
const switched = await f.refresh('ordinary');
|
|
140
|
+
assert.equal(switched.privateTheftSession, undefined);
|
|
141
|
+
assert.equal(client.isNativeTheftActive(), false);
|
|
142
|
+
assert.equal(route.deliveries().length, 0);
|
|
143
|
+
assert.equal(deliveries[0].pending().length, 1, 'switch-away preserves saved evidence');
|
|
144
|
+
await assert.rejects(f.api.resolveCase(), /theft_case_current_profile_changed/);
|
|
145
|
+
assert.equal(await client.perceiveNextOrderedCapture(), false);
|
|
146
|
+
assert.equal(unfinished.perceptionDelivery.status, 'withheld');
|
|
147
|
+
assert.equal(unfinished.perceptionDelivery.reason, 'live_shelf_profile_ended');
|
|
148
|
+
assert.equal(unfinished.imageSha256, savedImageHash);
|
|
149
|
+
const statistics = client.stats().actorPerception;
|
|
150
|
+
assert.equal(statistics.completed, 13);
|
|
151
|
+
assert.equal(statistics.pending, 0);
|
|
152
|
+
assert.equal(statistics.delivery.withheld, 1);
|
|
153
|
+
const ordinary = f.retain(14, client, switched);
|
|
154
|
+
assert.equal(ordinary.perceptionDelivery, undefined);
|
|
155
|
+
assert.equal(f.state.detects, 13);
|
|
156
|
+
|
|
157
|
+
const second = await f.api.select('b'.repeat(64));
|
|
158
|
+
assert.notEqual(second, first);
|
|
159
|
+
const restarted = await f.refresh('theft');
|
|
160
|
+
assert.equal(restarted.websiteReviewAdmission.profileId, second);
|
|
161
|
+
assert.equal(restarted.privateTheftSession.scope.profileGeneration, scope.profileGeneration + 1);
|
|
162
|
+
assert.equal(route.deliveries().length, 0, 'new assignment cannot deliver the old case');
|
|
163
|
+
assert.equal(f.state.opens, 0);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('operator modes are exclusive and returning to shelf changes its case authority', async () => {
|
|
167
|
+
const f = await fixture({live:true});
|
|
168
|
+
const at = Date.now();
|
|
169
|
+
const headers = {'x-cctv-live-shelf': f.api.environment.sourceId+'.'+f.api.environment.regionConfigurationSha256};
|
|
170
|
+
f.api.setPilotMode('off', at-3000);
|
|
171
|
+
assert.equal(await f.api.canOffer(f.api.identity.ownerId), false);
|
|
172
|
+
assert.equal(await f.api.allowsConcealment(at), false);
|
|
173
|
+
f.api.setPilotMode('concealment', at-2000);
|
|
174
|
+
assert.equal(await f.api.allowsConcealment(at-2500), false);
|
|
175
|
+
assert.equal(await f.api.allowsConcealment(at), true);
|
|
176
|
+
await assert.rejects(f.api.select('d'.repeat(64)), /prepared|shelf/i);
|
|
177
|
+
f.api.setPilotMode('shelf', at-1000);
|
|
178
|
+
const deployment = await f.api.select('e'.repeat(64));
|
|
179
|
+
const shelf = await f.api.serve(headers);
|
|
180
|
+
assert.equal(shelf.profileId, deployment);
|
|
181
|
+
assert.equal(await f.api.allowsConcealment(at), false);
|
|
182
|
+
f.api.setPilotMode('off', at);
|
|
183
|
+
assert.equal((await f.api.serve(headers)).profileState, 'inactive');
|
|
184
|
+
f.api.setPilotMode('shelf', at+1);
|
|
185
|
+
const resumed = await f.api.serve(headers);
|
|
186
|
+
assert.equal(resumed.profileId, deployment);
|
|
187
|
+
assert.notEqual(shelf.modelSelection.selectionId, resumed.modelSelection.selectionId);
|
|
188
|
+
assert.equal(await f.api.allowsConcealment(at+2), false);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('live shelf authority stays off for an unprepared connector and rejects an edited shelf or wrong route', async () => {
|
|
192
|
+
const f = await fixture({live:true,positive:false});
|
|
193
|
+
await f.api.select('c'.repeat(64));
|
|
194
|
+
const env = f.api.environment;
|
|
195
|
+
const headers = {'x-cctv-live-shelf':env.sourceId+'.'+env.regionConfigurationSha256};
|
|
196
|
+
assert.equal((await f.api.serve()).profileState, 'inactive');
|
|
197
|
+
assert.equal((await f.api.serve({'x-cctv-live-shelf':'f'.repeat(64)+'.'+env.regionConfigurationSha256})).profileState, 'inactive');
|
|
198
|
+
assert.equal((await f.api.serve(headers)).profileState, 'active');
|
|
199
|
+
assert.deepEqual(f.api.ordinaryRouteFields(), [null, null, [], []]);
|
|
200
|
+
const saved = f.api.route.screenFocusRegions[0].points[0].x;
|
|
201
|
+
f.api.route.screenFocusRegions[0].points[0].x = saved + .01;
|
|
202
|
+
assert.equal((await f.api.serve(headers)).profileState, 'inactive');
|
|
203
|
+
await assert.rejects(f.api.resolveCase(), /theft_case_live_binding_changed/);
|
|
204
|
+
f.api.route.screenFocusRegions[0].points[0].x = saved;
|
|
205
|
+
f.api.route.condition.field = 'person_present';
|
|
206
|
+
assert.equal((await f.api.serve(headers)).profileState, 'inactive');
|
|
207
|
+
f.api.route.condition.field = 'shelf_movement_review_case';
|
|
208
|
+
f.api.modelEligibility.models = [];
|
|
209
|
+
assert.equal((await f.api.serve(headers)).profileState, 'inactive');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('manager rejects a registered theft profile without its explicit frame runtime before constructing cameras',async()=>{
|
|
213
|
+
const f=await fixture();delete f.deps.theftRuntime;
|
|
214
|
+
await assert.rejects(f.build(),/runtime|metadata source/i);assert.equal(f.state.providers,0);assert.equal(f.state.opens,0);assert.equal(f.state.detects,0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('real manager routes thirteen theft originals through one detector lane and one private alert',async()=>{
|
|
218
|
+
const f=await fixture(),r=await f.build();assert.equal(r.loops.length,2);assert.equal(f.state.providers,2);
|
|
219
|
+
assert.equal(r.clients[0].reviewQueue,r.manager.candidates);assert.equal(r.clients[1].reviewQueue,r.manager.candidates);
|
|
220
|
+
for(let i=0;i<13;i++)await f.capture(i);
|
|
221
|
+
const route=r.theftRoutes.get('camera-0'),session=[...route.sessions.values()][0];assert(session);
|
|
222
|
+
assert.equal(f.state.detects,13);assert.equal(session.consumer.stats.alerts,1);assert.equal(session.consumer.rows.length,13);
|
|
223
|
+
assert.equal(session.consumer.pending.size,1);assert.equal(r.clients[0].entries.size,0);assert.equal(r.clients[0].deferred.size,0);
|
|
224
|
+
assert.equal(r.clients[0].pendingOrderedCandidates().length,0);assert.equal(f.state.ordinaryReviews,0);assert.equal(f.state.opens,0);
|
|
225
|
+
const packet=[...session.consumer.pending.values()][0];assert.equal(packet.pictures.length,13);assert.equal(packet.customerMessageSent,false);
|
|
226
|
+
assert.equal(packet.receipt.deadlineMs,f.baseTime+3000+90000);
|
|
227
|
+
assert.equal((await route.reviewOne({cameraBusy:true})).status,'paused_for_camera');assert.equal(f.state.reviews,0);
|
|
228
|
+
assert.equal((await route.reviewOne({cameraBusy:false})).status,'completed');assert.equal(f.state.reviews,1);assert.equal(session.consumer.stats.alerts,1);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('ordinary and unregistered camera profiles keep the website admission queue',async()=>{
|
|
232
|
+
const f=await fixture({positive:false}),r=await f.build();const ordinary=f.retain(0,r.clients[1]);
|
|
233
|
+
assert.equal(ordinary.disposition,'awaiting_rule_decision');assert.equal(ordinary.perceptionDelivery,undefined);
|
|
234
|
+
assert.equal(ordinary.candidate.reviewContext.privateTheftSession,undefined);assert.equal(r.clients[1].deferred.size,1);
|
|
235
|
+
const context=await f.refresh('ordinary'),row=f.retain(1,r.clients[0],context);
|
|
236
|
+
assert.equal(row.disposition,'awaiting_rule_decision');assert.equal(row.perceptionDelivery,undefined);assert.equal(r.clients[0].deferred.size,1);
|
|
237
|
+
assert.equal(context.privateTheftSession,undefined);assert.equal(f.state.detects,0);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('valid lease renewal retains movement scope while an ordinary-profile switch creates a new generation',async()=>{
|
|
241
|
+
const f=await fixture({positive:false}),r=await f.build();const a=r.clients[0].captureReviewContext();await f.capture(0);
|
|
242
|
+
const renewed=await f.refresh('theft');assert.deepEqual(renewed.privateTheftSession,a.privateTheftSession);
|
|
243
|
+
await f.refresh('ordinary');const b=await f.refresh('theft');
|
|
244
|
+
assert.equal(b.privateTheftSession.scope.captureEpoch,a.privateTheftSession.scope.captureEpoch);
|
|
245
|
+
assert.equal(b.privateTheftSession.scope.profileGeneration,a.privateTheftSession.scope.profileGeneration+1);
|
|
246
|
+
await f.capture(1);const route=r.theftRoutes.get('camera-0');assert.equal(route.sessions.size,1);
|
|
247
|
+
assert.equal([...route.sessions.values()][0].consumer.rows.length,1);assert.equal(f.state.detects,2);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('queued originals keep their captured scope when the live profile has already changed',async()=>{
|
|
251
|
+
const f=await fixture({positive:false}),r=await f.build(),old=f.retain(0);await f.refresh('ordinary');await f.refresh('theft');const fresh=f.retain(1);
|
|
252
|
+
assert.notEqual(old.candidate.reviewContext.privateTheftSession.scope.profileGeneration,fresh.candidate.reviewContext.privateTheftSession.scope.profileGeneration);
|
|
253
|
+
await r.clients[0].perceiveNextOrderedCapture();assert.equal(r.clients[0].recordFor(old.id).perceptionDelivery.status,'delivered');
|
|
254
|
+
await r.clients[0].perceiveNextOrderedCapture();assert.equal(f.state.detects,2);
|
|
255
|
+
assert.equal([...r.theftRoutes.get('camera-0').sessions.values()][0].consumer.rows.length,1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('inactive profile captures do not enter theft inference or acquire a private session',async()=>{
|
|
259
|
+
const f=await fixture(),r=await f.build(),context=await f.refresh('inactive'),row=f.retain(0,r.clients[0],context);
|
|
260
|
+
assert.equal(context.privateTheftSession,undefined);assert.equal(row.actorPerceptionPolicy,undefined);assert.equal(row.perceptionDelivery,undefined);
|
|
261
|
+
assert.equal(await r.clients[0].perceiveNextOrderedCapture(),false);assert.equal(f.state.detects,0);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('registered profile cannot silently use a different selected model contract',async()=>{
|
|
265
|
+
const f=await fixture();f.state.selection='other-selection';await assert.rejects(f.build(),/selection changed/);
|
|
266
|
+
assert.equal(f.state.detects,0);assert.equal(f.state.opens,0);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('changed source metadata fails before detector inference and preserves its exact diagnostic',async()=>{
|
|
270
|
+
const f=await fixture(),r=await f.build();const row=f.retain(0);row.candidate.privateOriginalFrame.capturedAtMs++;
|
|
271
|
+
await assert.rejects(r.clients[0].perceiveNextOrderedCapture(),/original source metadata/);assert.equal(f.state.detects,0);
|
|
272
|
+
const saved=JSON.parse(fs.readFileSync(r.clients[0].file(row.id)));assert.match(saved.actorPerceptionFailure.error??saved.actorPerceptionFailure.message??JSON.stringify(saved.actorPerceptionFailure),/metadata/);
|
|
273
|
+
assert.equal(saved.perceptionDelivery.status,'awaiting_perception');
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('default manager retains the original capture class and does not load a theft route',async()=>{
|
|
277
|
+
const f=await fixture({enabled:false}),r=await f.build();assert.equal(r.theftRoutes,undefined);
|
|
278
|
+
assert(r.clients.every(c=>c.constructor.name==='WebsiteAdmissionCaptureClient'));assert.equal(f.state.opens,0);assert.equal(f.state.detects,0);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('restart uses a new epoch and refuses to silently analyze an old unprocessed capture',async()=>{
|
|
282
|
+
const f=await fixture({positive:false}),first=await f.build(),old=f.retain(0),second=await f.build();
|
|
283
|
+
const oldScope=old.candidate.reviewContext.privateTheftSession.scope,newScope=second.clients[0].captureReviewContext().privateTheftSession.scope;
|
|
284
|
+
assert.notEqual(newScope.captureEpoch,oldScope.captureEpoch);assert(newScope.profileGeneration>oldScope.profileGeneration);
|
|
285
|
+
await assert.rejects(second.clients[0].perceiveNextOrderedCapture(),/old-epoch capture/);assert.equal(f.state.detects,0);
|
|
286
|
+
assert.equal(JSON.parse(fs.readFileSync(second.clients[0].file(old.id))).perceptionDelivery.status,'awaiting_perception');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('inactive then reactive without an inactive snapshot cannot reuse the old movement generation',async()=>{
|
|
290
|
+
const f=await fixture({positive:false}),r=await f.build(),client=r.clients[0];const before=client.captureReviewContext().privateTheftSession;
|
|
291
|
+
await f.capture(0);f.state.mode='inactive';client.client.client.lastProfileFetchMs=0;await client.prepareReview();
|
|
292
|
+
assert.equal(client.isReviewActive(),false);
|
|
293
|
+
f.state.mode='theft';client.client.client.lastProfileFetchMs=0;await client.prepareReview();assert.equal(client.isReviewActive(),true);
|
|
294
|
+
const after=client.captureReviewContext().privateTheftSession;assert.equal(after.scope.profileGeneration,before.scope.profileGeneration+1);
|
|
295
|
+
await f.capture(1);assert.equal([...r.theftRoutes.get('camera-0').sessions.values()][0].consumer.rows.length,1);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('real manager start transitions rotate scope once and retain only queued work from the same runtime owner',async()=>{
|
|
299
|
+
const f=await fixture({positive:false}),r=await f.build(),client=r.clients[0],old=f.retain(0);
|
|
300
|
+
const loops=r.manager.loops;r.manager.loops=[]; // lifecycle only: no simulated or real camera is started
|
|
301
|
+
try {
|
|
302
|
+
await r.manager.start({healthOnly:true});const first=client.captureReviewContext().privateTheftSession.scope;
|
|
303
|
+
assert.notEqual(first.captureEpoch,old.candidate.reviewContext.privateTheftSession.scope.captureEpoch);
|
|
304
|
+
await r.manager.start({healthOnly:true});assert.deepEqual(client.captureReviewContext().privateTheftSession.scope,first);
|
|
305
|
+
await client.perceiveNextOrderedCapture();await f.capture(1);assert.equal(f.state.detects,2);
|
|
306
|
+
assert.equal([...r.theftRoutes.get('camera-0').sessions.values()][0].consumer.rows.length,1);
|
|
307
|
+
await r.manager.stop();await r.manager.start({healthOnly:true});const second=client.captureReviewContext().privateTheftSession.scope;
|
|
308
|
+
assert.notEqual(second.captureEpoch,first.captureEpoch);assert(second.profileGeneration>first.profileGeneration);
|
|
309
|
+
} finally {await r.manager.stop();r.manager.loops=loops;}
|
|
310
|
+
assert.equal(f.state.opens,0);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('restart restores queued opinions even when every original frame was already acknowledged',async()=>{
|
|
314
|
+
const f=await fixture(),first=await f.build();for(let i=0;i<13;i++)await f.capture(i);
|
|
315
|
+
assert.equal(first.clients[0].perceptionPending.size,0);const second=await f.build(),route=second.theftRoutes.get('camera-0');
|
|
316
|
+
assert.equal(route.sessions.size,1);const consumer=[...route.sessions.values()][0].consumer;
|
|
317
|
+
assert.equal(consumer.pending.size,1);assert.equal(consumer.rows.length,13);assert.equal(f.state.detects,13);
|
|
318
|
+
assert.equal((await route.reviewOne({cameraBusy:false})).status,'completed');assert.equal(f.state.reviews,1);assert.equal(f.state.detects,13);
|
|
319
|
+
assert.equal(consumer.stats.alerts,1);assert.equal(route.sessions.size,0);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('a changed shelf marking cannot silently reuse the earlier registered movement environment',async()=>{
|
|
323
|
+
const f=await fixture(),r=await f.build();const file=path.join(f.directory,'state','private-theft-camera-0','REGISTRATION.json'),before=fs.readFileSync(file);
|
|
324
|
+
f.state.regions=[{field:'review',region:{x:.1,y:.1,width:.3,height:.3}}];
|
|
325
|
+
await assert.rejects(f.refresh('theft'),/Registered theft definition changed/);
|
|
326
|
+
assert.deepEqual(fs.readFileSync(file),before);assert.equal(f.state.detects,0);assert.equal(f.state.opens,0);
|
|
327
|
+
assert.equal(r.clients[0].records.size,0);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('private delivery progress does not require website offers and switching back keeps the ordinary watchdog',async()=>{
|
|
331
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0],reports=[];let now=Date.now();
|
|
332
|
+
c.realtime.now=()=>now;c.onOfferStall=x=>reports.push(x);
|
|
333
|
+
await f.capture(0);c.watchOfferPath();now+=300001;await f.capture(1);c.watchOfferPath();
|
|
334
|
+
assert.equal(reports.length,0,'Private deliveries must not be mistaken for missing website offers');
|
|
335
|
+
assert.equal(c.entries.size,0);assert.equal(c.privateHealth.completed,2);
|
|
336
|
+
const ordinary=await f.refresh('ordinary');f.retain(2,c,ordinary);c.watchOfferPath();assert.equal(reports.length,0);
|
|
337
|
+
now+=240001;f.retain(3,c,ordinary);c.watchOfferPath();assert.equal(reports.length,1);assert.equal(reports[0].kind,undefined);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('a stalled private perception is reported without releasing or duplicating its live owner',async()=>{
|
|
341
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0],reports=[];let now=Date.now(),finish;
|
|
342
|
+
c.realtime.now=()=>now;c.onOfferStall=x=>reports.push(x);
|
|
343
|
+
const call=f.runtime.rpc.call;f.runtime.rpc.call=async(...args)=>{await new Promise(resolve=>finish=resolve);return call(...args);};
|
|
344
|
+
const first=f.retain(0),work=c.perceiveNextOrderedCapture();await new Promise(resolve=>setImmediate(resolve));assert(finish);
|
|
345
|
+
c.watchOfferPath();now+=240001;f.retain(1);c.watchOfferPath();
|
|
346
|
+
assert.equal(reports.length,1);assert.equal(reports[0].kind,'private_perception_stalled');assert.equal(reports[0].frame_id,first.id);
|
|
347
|
+
assert.equal(reports[0].perception_released,false);assert.equal(reports[0].phase,'perception');assert(c.perceptionBusy);
|
|
348
|
+
c.watchOfferPath();assert.equal(reports.length,1);assert.equal(await c.perceiveNextOrderedCapture(),false);assert.equal(f.state.detects,0);
|
|
349
|
+
finish();assert.equal(await work,true);assert.equal(f.state.detects,1);assert.equal(c.privateHealth.completed,1);assert.equal(c.perceptionBusy,false);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('queued private work reports a real stall even if the telemetry callback fails',async()=>{
|
|
353
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0];let now=Date.now(),calls=0;
|
|
354
|
+
c.realtime.now=()=>now;c.onOfferStall=()=>{calls++;throw Error('fixture telemetry unavailable');};
|
|
355
|
+
f.retain(0);c.watchOfferPath();now+=240001;f.retain(1);assert.doesNotThrow(()=>c.watchOfferPath());
|
|
356
|
+
assert.equal(calls,1);assert.equal(c.privateHealth.lastReport.phase,'awaiting_perception');
|
|
357
|
+
assert.equal(c.privateHealth.lastReport.perception_busy,false);assert.equal(c.privateHealth.stalls,1);
|
|
358
|
+
assert.equal(c.perceptionPending.size,2);assert.equal(f.state.detects,0);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('private delivery failures retain their exact saved diagnostic and are not counted as progress',async()=>{
|
|
362
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0];let now=Date.now();c.realtime.now=()=>now;
|
|
363
|
+
const row=f.retain(0);c.perceptionSink.deliver=()=>{throw Object.assign(new Error('fixture private receiver write failed'),{code:'EIO'});};
|
|
364
|
+
await assert.rejects(c.perceiveNextOrderedCapture(),/private receiver write failed/);c.watchOfferPath();now+=240001;f.retain(1);c.watchOfferPath();
|
|
365
|
+
const saved=JSON.parse(fs.readFileSync(c.file(row.id)));
|
|
366
|
+
assert.equal(saved.perceptionDeliveryFailure.error.code,'EIO');assert.equal(c.privateHealth.completed,0);
|
|
367
|
+
assert.equal(c.privateHealth.lastReport.phase,'delivery');assert.deepEqual(c.privateHealth.lastReport.saved_failure,saved.perceptionDeliveryFailure);
|
|
368
|
+
assert.equal(saved.perceptionDelivery.status,'pending');assert.equal(f.state.detects,1);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('the unregistered ordinary capture class keeps its existing offer reset',async()=>{
|
|
372
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[1],reports=[];let now=Date.now();
|
|
373
|
+
c.realtime.now=()=>now;c.onOfferStall=x=>reports.push(x);const row=f.retain(0,c);c.queued.add(row.id);
|
|
374
|
+
c.watchOfferPath();now+=240001;f.retain(1,c);c.watchOfferPath();
|
|
375
|
+
assert.equal(reports.length,1);assert.equal(reports[0].released_queued,1);assert.equal(c.queued.size,0);
|
|
376
|
+
assert.equal(c.constructor.name,'WebsiteAdmissionCaptureClient');assert.equal(c.privateHealth,undefined);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test('ordinary backlog on a private-capable camera is not hidden and cannot release private inference',async()=>{
|
|
380
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0],reports=[];let now=Date.now(),finish;
|
|
381
|
+
c.realtime.now=()=>now;c.onOfferStall=x=>reports.push(x);
|
|
382
|
+
const ordinary=await f.refresh('ordinary'),old=f.retain(0,c,ordinary);c.queued.add(old.id);c.watchOfferPath();
|
|
383
|
+
const selected=await f.refresh('theft');f.retain(1,c,selected);
|
|
384
|
+
const call=f.runtime.rpc.call;f.runtime.rpc.call=async(...args)=>{await new Promise(resolve=>finish=resolve);return call(...args);};
|
|
385
|
+
const work=c.perceiveNextOrderedCapture();await new Promise(resolve=>setImmediate(resolve));assert(finish);
|
|
386
|
+
c.phoneProofChecks.set('fixture',{});now+=240001;c.liveLookStartedAtMs=now+1000;f.retain(2,c,selected);c.watchOfferPath();
|
|
387
|
+
const normal=reports.find(x=>x.kind===undefined);assert(normal);assert.equal(normal.released_queued,1);assert.equal(normal.live_look_reset,true);
|
|
388
|
+
assert.equal(normal.perception_released,false);assert(c.perceptionBusy);assert.equal(c.phoneProofChecks.size,0);
|
|
389
|
+
assert.equal(await c.perceiveNextOrderedCapture(),false);finish();await work;assert.equal(f.state.detects,1);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('private stall reporting distinguishes a stopped capture stream from recent continued capture',async()=>{
|
|
393
|
+
const f=await fixture({positive:false}),r=await f.build(),c=r.clients[0],reports=[];let now=Date.now();
|
|
394
|
+
c.realtime.now=()=>now;c.onOfferStall=x=>reports.push(x);f.retain(0);c.watchOfferPath();now+=240001;c.watchOfferPath();
|
|
395
|
+
assert.equal(reports.length,0);f.retain(1);c.watchOfferPath();assert.equal(reports.length,1);
|
|
396
|
+
assert.equal(reports[0].kind,'private_perception_stalled');assert.equal(c.perceptionPending.size,2);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test('original private capture metadata comes from durable capture order and actual JPEG bytes',async()=>{
|
|
400
|
+
const f=await fixture({positive:false}),r=await f.build(),client=r.clients[0];
|
|
401
|
+
const first=f.retain(0),metadata=first.candidate.privateOriginalFrame;
|
|
402
|
+
assert(metadata,'Capture must persist its original metadata before perception');
|
|
403
|
+
assert.equal(first.candidate.privateOriginalFrameKind,'captured_archive_ordinal/v1');
|
|
404
|
+
assert.deepEqual(metadata,{sourceIndex:0,sourceTimeMs:null,sceneId:1,width:640,height:480,capturedAtMs:first.capturedAt,sha256:first.imageSha256});
|
|
405
|
+
const bytes=fs.readFileSync(client.image(first));
|
|
406
|
+
const actual=require('../FrameTheftRuntime.cjs').FrameTheftRuntime.prototype.describeOriginal.call(null,
|
|
407
|
+
{record:first,input:{frameId:first.id,capturedAtMs:first.capturedAt,jpeg:bytes}});
|
|
408
|
+
assert.deepEqual(actual,metadata);
|
|
409
|
+
const saved=fs.readFileSync(client.file(first.id));f.retain(0);assert.equal(client.counts.captures,1);assert.deepEqual(fs.readFileSync(client.file(first.id)),saved);
|
|
410
|
+
const second=f.retain(1);assert.equal(second.candidate.privateOriginalFrame.sourceIndex,1);
|
|
411
|
+
const restarted=await f.build(),third=f.retain(2);assert.equal(third.candidate.privateOriginalFrame.sourceIndex,2);
|
|
412
|
+
assert.deepEqual(restarted.clients[0].recordFor(first.id).candidate.privateOriginalFrame,metadata);
|
|
413
|
+
assert.equal(f.state.opens,0);assert.equal(f.state.detects,0);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('private capture refuses forged provenance and mismatched actual picture geometry',async()=>{
|
|
417
|
+
const f=await fixture(),r=await f.build(),client=r.clients[0],context=client.captureReviewContext();
|
|
418
|
+
const jpeg=Buffer.from([255,216,255,192,0,11,8,1,224,2,128,1,1,17,0,255,217]);
|
|
419
|
+
const candidate={name:client.cameraId,enqueuedAtMs:f.baseTime,jpeg,reviewContext:context};
|
|
420
|
+
assert.throws(()=>client.retainOrderedCapture({...candidate,privateOriginalFrame:{sourceIndex:99}}),/cannot supply/);
|
|
421
|
+
assert.throws(()=>client.retainOrderedCapture({...candidate,privateOriginalFrameKind:'captured_archive_ordinal/v1'}),/cannot supply/);
|
|
422
|
+
assert.throws(()=>client.retainOrderedCapture({...candidate,jpeg:Buffer.from('invalid JPEG')}),/JPEG/);
|
|
423
|
+
const wrong=Buffer.from(jpeg);wrong[9]=1;
|
|
424
|
+
assert.throws(()=>client.retainOrderedCapture({...candidate,jpeg:wrong}),/geometry/);
|
|
425
|
+
assert.equal(client.counts.captures,0);assert.equal(client.records.size,0);assert.equal(f.state.detects,0);
|
|
426
|
+
client.retainOrderedCapture({...candidate,imageWidth:1,imageHeight:1});
|
|
427
|
+
assert.deepEqual([client.previousCaptureRecord.candidate.privateOriginalFrame.width,client.previousCaptureRecord.candidate.privateOriginalFrame.height],[640,480]);
|
|
428
|
+
await f.refresh('ordinary');const ordinary=f.retain(1);assert.equal(ordinary.candidate.privateOriginalFrame,undefined);
|
|
429
|
+
assert.equal(ordinary.candidate.privateOriginalFrameKind,undefined);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
// Shared-lane tests exercise the actual manager pump, never a camera or model.
|
|
434
|
+
const settle=()=>new Promise(resolve=>setImmediate(resolve));
|
|
435
|
+
async function schedulingFixture() {
|
|
436
|
+
const f=await fixture(),r=await f.build();for(let i=0;i<13;i++)await f.capture(i);
|
|
437
|
+
const m=r.manager; m.running=true;m.startGeneration=1;
|
|
438
|
+
cleanups.push(()=>m.stop());
|
|
439
|
+
const route=r.theftRoutes.get('camera-0'),consumer=[...route.sessions.values()][0].consumer;
|
|
440
|
+
return {...f,r,m,route,consumer,pump:()=>m.pumpCandidates(m.startGeneration)};
|
|
441
|
+
}
|
|
442
|
+
test('shared optional lane automatically reviews the exact thirteen-picture alert after ordinary work',async()=>{
|
|
443
|
+
const f=await schedulingFixture();assert.equal(f.m.getOptionalReviewState().registered,1);
|
|
444
|
+
const seen=[];f.m.on('optionalReviewCompleted',e=>seen.push(e));f.pump();await settle();
|
|
445
|
+
assert.equal(f.state.reviews,1);assert.equal(f.consumer.pending.size,0);assert.equal(f.consumer.stats.alerts,1);
|
|
446
|
+
assert.equal(seen.length,1);assert.equal(seen[0].outcome.status,'completed');assert.equal(f.m.getOptionalReviewState().activeFeed,null);
|
|
447
|
+
assert.equal(f.m.reviewsInFlight.size,0);assert.equal(f.m.modelReviewsInFlight.size,0);assert.equal(f.state.opens,0);
|
|
448
|
+
});
|
|
449
|
+
test('shared optional lane pauses for camera backlog and other model work without consuming the alert',async()=>{
|
|
450
|
+
const f=await schedulingFixture();f.m.actorPerceptionBusy=true;f.pump();await settle();
|
|
451
|
+
assert.equal(f.state.reviews,0);assert.equal(f.consumer.pending.size,1);assert.equal(f.consumer.stats.alerts,1);
|
|
452
|
+
f.m.actorPerceptionBusy=false;const reservation={feed:'camera-1',use:'vlm'};f.m.modelReviewsInFlight.add(reservation);
|
|
453
|
+
f.pump();await settle();assert.equal(f.state.reviews,0);assert.equal(f.consumer.pending.size,1);f.m.modelReviewsInFlight.delete(reservation);
|
|
454
|
+
f.m.holdReviewsUntil(Date.now()+10000);f.pump();await settle();assert.equal(f.state.reviews,0);
|
|
455
|
+
f.m.holdReviewsUntil(null);f.pump();await settle();assert.equal(f.state.reviews,1);assert.equal(f.consumer.pending.size,0);
|
|
456
|
+
});
|
|
457
|
+
test('shared optional physical reservation survives stop and prevents a competing ordinary review',async()=>{
|
|
458
|
+
const f=await schedulingFixture();let finish;const review=f.runtime.reviewer.review;
|
|
459
|
+
f.runtime.reviewer.review=async(...args)=>{await new Promise(resolve=>finish=resolve);return review(...args);};
|
|
460
|
+
f.pump();await settle();assert(finish);const original=f.m.optionalReviewInFlight;
|
|
461
|
+
assert.equal(f.m.reviewsInFlight.size,1);assert.equal(f.m.modelReviewsInFlight.size,1);
|
|
462
|
+
await f.m.stop();assert.equal(f.m.optionalReviewInFlight,original);f.m.candidates.startRun();f.m.running=true;f.m.startGeneration++;
|
|
463
|
+
let ordinary=0;f.m.serveCandidate=async()=>{ordinary++;};f.retain(0,f.r.clients[1]);f.m.orderedDirty.add('camera-1');
|
|
464
|
+
f.pump();await settle();assert.equal(ordinary,0);assert.equal(f.state.reviews,0);assert.equal(f.m.optionalReviewInFlight,original);
|
|
465
|
+
finish();await settle();await settle();assert.equal(f.state.reviews,1);assert.equal(f.m.optionalReviewInFlight,null);
|
|
466
|
+
f.pump();await settle();assert.equal(ordinary,1);assert.equal(f.m.modelReviewsInFlight.size,0);
|
|
467
|
+
});
|
|
468
|
+
test('shared optional queue expires during camera backlog without sending any pictures to the reviewer',async()=>{
|
|
469
|
+
const f=await schedulingFixture();const packet=[...f.consumer.pending.values()][0];f.consumer.now=()=>packet.receipt.deadlineMs;
|
|
470
|
+
f.m.actorPerceptionBusy=true;f.pump();await settle();assert.equal(f.state.reviews,0);assert.equal(f.consumer.pending.size,0);
|
|
471
|
+
assert.equal(f.consumer.stats.alerts,1);assert.equal(f.consumer.stats.opinion.expired,1);assert.equal(f.consumer.rows.length,13);
|
|
472
|
+
});
|
|
473
|
+
test('shared optional reviewer engineering failure is saved and retires the source without retrying',async()=>{
|
|
474
|
+
const f=await schedulingFixture();let calls=0;const events=[];f.m.on('optionalReviewError',event=>events.push(event));
|
|
475
|
+
f.runtime.reviewer.review=async()=>{calls++;throw Object.assign(Error('fixture owned reviewer failed'),{code:'EIO'});};
|
|
476
|
+
f.pump();await settle();assert.equal(calls,1);assert.equal(events.length,1);
|
|
477
|
+
assert.equal(events[0].outcome.diagnostics.primary.message,'fixture owned reviewer failed');
|
|
478
|
+
assert.equal(events[0].outcome.diagnostics.primary.code,'EIO');assert(events[0].outcome.diagnostics.primary.stack);
|
|
479
|
+
assert.equal(f.m.getOptionalReviewState().failedSources[0].name,'camera-0');assert.equal(f.consumer.stats.alerts,1);
|
|
480
|
+
assert.equal(f.consumer.stats.opinion.unavailable,1);assert.equal(f.consumer.pending.size,0);
|
|
481
|
+
f.pump();await settle();assert.equal(calls,1);assert.equal(events.length,1);assert.equal(f.m.reviewsInFlight.size,0);
|
|
482
|
+
});
|
|
483
|
+
test('shared optional source registration is explicit and ordinary managers have no optional work',async()=>{
|
|
484
|
+
const f=await fixture({enabled:false}),r=await f.build(),m=r.manager;
|
|
485
|
+
assert.deepEqual(m.getOptionalReviewState(),{registered:0,activeFeed:null,failedSources:[]});
|
|
486
|
+
assert.throws(()=>m.registerOptionalReviewSource({name:'unknown',hasPending:()=>true,reviewOne:async()=>null}),/known feed/);
|
|
487
|
+
m.registerOptionalReviewSource({name:'camera-0',hasPending:()=>false,reviewOne:async()=>null});
|
|
488
|
+
assert.throws(()=>m.registerOptionalReviewSource({name:'camera-0',hasPending:()=>false,reviewOne:async()=>null}),/duplicate/);
|
|
489
|
+
assert.equal(f.state.detects,0);assert.equal(f.state.opens,0);
|
|
490
|
+
});
|
|
491
|
+
test('shared optional scheduling errors retain the exact error and retire only the affected source',async()=>{
|
|
492
|
+
const f=await fixture({enabled:false}),r=await f.build(),m=r.manager;const failure=Object.assign(Error('fixture pending lookup failed'),{code:'EACCES'});
|
|
493
|
+
let calls=0;const errors=[];m.on('optionalReviewError',e=>errors.push(e));
|
|
494
|
+
m.registerOptionalReviewSource({name:'camera-0',hasPending(){calls++;throw failure;},reviewOne:async()=>null});
|
|
495
|
+
m.running=true;m.startGeneration=1;cleanups.push(()=>m.stop());m.pumpCandidates(1);await settle();m.pumpCandidates(1);await settle();
|
|
496
|
+
assert.equal(calls,1);assert.equal(errors.length,1);assert.equal(errors[0].error,failure);
|
|
497
|
+
assert.equal(m.getOptionalReviewState().failedSources[0].error.code,'EACCES');assert.equal(m.reviewsInFlight.size,0);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('shared optional dispatch rechecks a stop before entering the reviewer',async()=>{
|
|
501
|
+
const f=await schedulingFixture();f.pump();await f.m.stop();await settle();
|
|
502
|
+
assert.equal(f.state.reviews,0);assert.equal(f.consumer.pending.size,1);assert.equal(f.consumer.stats.alerts,1);
|
|
503
|
+
assert.equal(f.m.reviewsInFlight.size,0);assert.equal(f.m.modelReviewsInFlight.size,0);
|
|
504
|
+
});
|
|
505
|
+
test('shared optional dispatch rechecks camera backlog arriving after reservation',async()=>{
|
|
506
|
+
const f=await schedulingFixture();f.pump();f.m.actorPerceptionBusy=true;await settle();
|
|
507
|
+
assert.equal(f.state.reviews,0);assert.equal(f.consumer.pending.size,1);
|
|
508
|
+
f.m.actorPerceptionBusy=false;f.pump();await settle();assert.equal(f.state.reviews,1);assert.equal(f.consumer.pending.size,0);
|
|
509
|
+
});
|