okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e17efa53c
main
1/** Ported from #3578 (medking82): a later finished update of the same component settles a restart interruption; the alert stays red. */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { build } from 'esbuild' ; 5import { fileURLToPath } from 'node:url' ; 6 7const out = await build ({ entryPoints :[ fileURLToPath ( new URL ( '../src/lib/native-job-diagnostics.ts' , import . meta. url ))], bundle :true , format :'esm' , platform :'node' , write :false , logLevel :'silent' }); 8const { recoveredInterruptions, jobErrorText, INTERRUPTED } = await import ( `data:text/javascript;base64, ${ Buffer . from ( out . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 9const failed = { id :'a' , kind :'update-strata' , state :'error' , summary :'Interrupted operation' , error :INTERRUPTED , startedAt :'2026-10-20T11:41:02.916Z' }; 10const done = { id :'b' , kind :'update-strata' , state :'done' , summary :'Complete' , error :null , startedAt :'2026-10-20T23:11:18.883Z' }; 11 12test ( 'a later finished update of the same component settles the interruption, in any array order, and the records are untouched' , () => { 13const jobs = structuredClone ([ failed , done ]), before = JSON . stringify ( jobs ); 14assert . deepEqual ([ ...recoveredInterruptions ( jobs )], [ 'a' ]); 15assert . deepEqual ([ ...recoveredInterruptions ([ done , failed ])], [ 'a' ]); 16assert . equal ( JSON . stringify ( jobs ), before ); 17assert . match ( jobErrorText ( jobs [ 0 ], jobs ), / A later update finished, so nothing needs doing / ); 18}); 19 20for ( const [ name , other ] of [[ 'no retry' , null ], [ 'running retry' , { ...done , state :'running' }], [ 'cancelled retry' , { ...done , state :'cancelled' }], 21[ 'success before the interruption' , { ...done , startedAt :'2026-10-19T00:00:00.000Z' }], [ 'same time' , { ...done , startedAt :failed . startedAt }], 22[ 'invalid time' , { ...done , startedAt :'unknown' }], [ 'other component' , { ...done , kind :'update-engine' }]]) { 23test ( ` ${ name } : the interruption stays an ordinary failure` , () => { 24const jobs = other ?[ failed , other ] :[ failed ]; 25assert . equal ( recoveredInterruptions ( jobs ). size , 0 ); 26assert . equal ( jobErrorText ( failed , jobs ), INTERRUPTED ); 27}); 28} 29 30test ( 'an ordinary failure is never settled, and an invalid interruption time stays a failure' , () => { 31const other = { ...failed , id :'c' , error :'Installer Failed' }; 32assert . equal ( jobErrorText ( other , [ other , done ]), 'Installer Failed' ); 33assert . equal ( recoveredInterruptions ([{ ...failed , startedAt :'unknown' }, done ]). size , 0 ); 34});