feat(ui): add tracker provisioning, SIM policies, command history and firmware archive

This commit is contained in:
DCCONSTRUCTIONS
2026-09-28 18:44:18 +03:00
parent f3a7592d90
commit 031e01a99b
24 changed files with 929 additions and 4 deletions
@@ -0,0 +1,54 @@
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import test from 'node:test';
import ts from 'typescript';
const code=ts.transpileModule(readFileSync(new URL('../src/core/fleet/commandRuntime.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText;
const {mergeCommands,commandPending,commandTracked,commandStatus,commandTone,commandDate,commandDuration,commandReceipt,commandEntryStatus}=await import('data:text/javascript;base64,'+Buffer.from(code).toString('base64'));
test('runtime retains loaded history and merges a changing operation by immutable id',()=>{
const a={id:'a',sequence:10,state:'waiting'},b={id:'b',sequence:9,state:'device_confirmed'};
const entries=mergeCommands([a,b],[{...a,state:'dispatched'},{id:'c',sequence:11,state:'queued'}]);
assert.deepEqual(entries.map(x=>[x.id,x.state]),[['c','queued'],['a','dispatched'],['b','device_confirmed']]);
assert.equal(a.state,'waiting');
});
test('a delayed polling response cannot roll a completed command back to pending',()=>{
const current={id:'a',sequence:10,state:'device_confirmed',updated_at:20};
assert.equal(mergeCommands([current],[{...current,state:'dispatched',updated_at:10}])[0].state,'device_confirmed');
});
test('runtime makes expiry, no confirmation and receipt distinct; none claim actuator execution',()=>{
for(const state of ['waiting','submitting','queued','dispatched'])assert.equal(commandPending(state),true);
for(const state of ['expired','cancelled','unconfirmed','uncertain','device_confirmed'])assert.equal(commandPending(state),false);
assert.equal(commandTone('device_confirmed'),'success');
assert.equal(commandTone('unconfirmed'),'warning');
assert.notEqual(commandStatus('expired'),commandStatus('unconfirmed'));
assert.doesNotMatch(commandStatus('device_confirmed'),/исполнено|выполнено/i);
assert.equal(commandDuration(undefined),'—');assert.equal(commandDuration(0.01234),'0.012 с');assert.equal(commandDate(undefined),'—');
});
test('unresolved results remain tracked after timeout without blocking the command queue',()=>{
const unknown={id:'a',sequence:1,state:'uncertain',reconcile_pending:true,updated_at:10};
assert.equal(commandPending(unknown.state),false);
assert.equal(commandTracked(unknown),true);
const final={...unknown,state:'device_confirmed',reconcile_pending:false,updated_at:20};
assert.equal(commandTracked(final),false);
assert.deepEqual(mergeCommands([unknown],[final]),[final]);
});
test('tracker ACK is visible without pretending that execution finished',()=>{
const ack={state:'dispatched',device_code:6,device_accepted_at:10};
assert.equal(commandPending(ack.state),true);
assert.equal(commandEntryStatus(ack),'Принято B2, выполняется');
assert.equal(commandReceipt(ack),'B2 принял команду; требуется время на выполнение');
assert.equal(commandReceipt({device_code:0,kind:'restart'}),'B2 принял команду перезапуска');
assert.equal(commandEntryStatus({...ack,state:'device_confirmed'}),'Подтверждено B2');
assert.equal(commandReceipt({device_code:5}),'B2 сообщил об ошибке выполнения');
assert.equal(commandReceipt({device_code:7}),'Очередь команд B2 заполнена');
});
test('durable jobs show recovery independently of a single attempt and stop request',()=>{
const entry={state:'queued',durable:true,device_accepted_at:10};
assert.equal(commandEntryStatus({...entry,runtime_phase:'retry-wait'}),'Ожидает следующей попытки');
assert.equal(commandEntryStatus({...entry,runtime_phase:'reconciling'}),'Уточнение результата у VPS');
assert.equal(commandEntryStatus({...entry,stop_requested:true}),'Остановка повторов');
assert.equal(commandPending('accepted'),false);
assert.equal(commandPending('stopped'),false);
});