feat(k1): add USB networking, device management and acquisition recovery
This commit is contained in:
@@ -232,3 +232,74 @@ test('legacy resolution failure invalidates the form before a second stale submi
|
||||
assert.equal(api.enrollmentBluetoothFailure(state),true);
|
||||
assert.match(api.enrollmentNotice(state),/Найдите K1 ещё раз/);
|
||||
});
|
||||
|
||||
test('saved Bridge recovery needs no BLE candidate and dispatches exactly one existing Verify',async()=>{
|
||||
const before={...initial,selected_device_id:null,candidates:[],discovery_generation:0,mode_revision:3,
|
||||
reconnect_target:{device_id:'saved-k1',source:'durable-configured-state'},
|
||||
allowed_actions:['observe-configured-device-network'],acquisition_recovery:{state:'active'}};
|
||||
const commands=[];
|
||||
const transport={submit:async command=>{commands.push(command);return {state:'complete',operation_id:command.operation_id,
|
||||
result:{...before,snapshot_revision:2,selected_device_id:'saved-k1',connected:true,
|
||||
device_session:{device_id:'saved-k1',device_session_id:'new-live-session'},
|
||||
command_result:{operation_id:command.operation_id,status:'succeeded',action:'verify'}}};}};
|
||||
const result=await api.enroll(transport,before,'verify',{device_id:before.reconnect_target.device_id,discovery_generation:0,mode_revision:3});
|
||||
assert.equal(api.enrollmentAllowed(before,'verify'),true);
|
||||
assert.equal(api.enrollmentAllowed(before,'connect'),false);
|
||||
assert.equal(commands.length,1);assert.equal(commands[0].action,'verify');
|
||||
assert.deepEqual(commands[0].parameters,{device_id:'saved-k1',discovery_generation:0,mode_revision:3});
|
||||
assert.equal(api.enrollmentProof(result,'saved-k1').session,'new-live-session');
|
||||
});
|
||||
|
||||
test('unreachable K1 reports power and network checks without claiming power-off or live scanning',()=>{
|
||||
const before={...initial,connected:false,acquisition_recovery:{state:'active'}};
|
||||
assert.match(api.enrollmentRecoveryNotice(before),/не подтверждена/);
|
||||
for(const code of ['connection-verify-device-not-rediscovered','connection-verify-mqtt-unreachable','connection-verify-status-read-timeout']){
|
||||
const value={...before,verification:{status:'failed',error_code:code}};
|
||||
const message=api.enrollmentRecoveryNotice(value);
|
||||
assert.match(message,/Проверьте питание/);assert.match(message,/сети/);
|
||||
assert.doesNotMatch(message,/K1 выключен|съёмка продолжается|съёмка завершена/);
|
||||
assert.equal(api.enrollmentRecoveryNotice(JSON.parse(JSON.stringify(value))),message);
|
||||
}
|
||||
assert.match(api.enrollmentRecoveryNotice({...before,connected:true,acquisition_recovery:{state:'ceased'}}),/Предыдущая съёмка завершена/);
|
||||
assert.match(api.enrollmentRecoveryNotice({...before,fresh:false}),/Нет свежих сведений с БК/);
|
||||
});
|
||||
|
||||
test('onboard reset uses the existing CAS outcome without automatic Scan, Verify or provisioning',async()=>{
|
||||
const before={...initial,can_reset:true,supported_actions:['reset'],mode_revision:4};const commands=[];
|
||||
assert.equal(api.enrollmentAllowed(before,'reset'),true);
|
||||
assert.equal(api.enrollmentAllowed({...before,supported_actions:undefined},'reset'),false);
|
||||
assert.equal(api.enrollmentAllowed({...before,can_reset:undefined},'reset'),false);
|
||||
const transport={submit:async command=>{commands.push(command);return {state:'complete',operation_id:command.operation_id,result:{...before,mode_revision:5,snapshot_revision:2,connected:false,command_result:{operation_id:command.operation_id,action:'reset',status:'succeeded'}}};}};
|
||||
const result=await api.enroll(transport,before,'reset',{mode_revision:4});
|
||||
assert.equal(result.mode_revision,5);assert.equal(commands.length,1);assert.equal(commands[0].action,'reset');
|
||||
assert.deepEqual(commands[0].parameters,{mode_revision:4});
|
||||
transport.submit=async command=>({state:'complete',operation_id:command.operation_id,result:before});
|
||||
await assert.rejects(api.enroll(transport,before,'reset',{mode_revision:4}),/не подтверждён/);
|
||||
});
|
||||
|
||||
test('terminal enrollment without a driver result releases the observer without waiting or replay',async()=>{
|
||||
for(const action of ['connect','verify']){
|
||||
for(const state of ['unknown','failed','rejected']){
|
||||
let posts=0,reads=0,pauses=0,clock=Date.now();
|
||||
const transport={
|
||||
submit:async command=>{posts++;return {operation_id:command.operation_id,state,error:'Действие K1 не подтверждено.'};},
|
||||
operation:async()=>{throw new Error('terminal delivery must not be polled again');},
|
||||
state:async()=>{reads++;return {...initial,connected:true};},
|
||||
};
|
||||
const parameters={device_id:'synthetic-ble',...(action==='connect'?{password:crypto.randomUUID()}: {})};
|
||||
await assert.rejects(api.enroll(transport,initial,action,parameters,{
|
||||
now:()=>clock,pause:async()=>{pauses++;clock+=100000;},
|
||||
}),/Действие K1 не подтверждено/);
|
||||
assert.deepEqual({posts,reads,pauses},{posts:1,reads:0,pauses:0});
|
||||
assert.equal('password' in parameters,false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('unknown delivery with a correlated running result still observes the owned bootstrap',async()=>{
|
||||
const f=fixture(),submit=f.transport.submit;
|
||||
f.transport.submit=async command=>({...await submit(command),state:'unknown'});
|
||||
const result=await api.enroll(f.transport,initial,'connect',f.parameters,f.observer);
|
||||
assert.equal(result.connected,true);
|
||||
assert.deepEqual(f.counts(),{posts:1,reads:1});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user