@@ -14,35 +14,67 @@ import * as DesktopUpdates from "./DesktopUpdates.ts";
1414import { flushCallbacks , makeHarness } from "./updatesTestHarness.ts" ;
1515
1616describe ( "DesktopUpdates" , ( ) => {
17- it . effect ( "keeps windows and restarts backends when quitAndInstall fails" , ( ) => {
18- const harness = makeHarness ( {
19- quitAndInstall : Effect . fail (
20- new ElectronUpdater . ElectronUpdaterQuitAndInstallError ( {
21- channel : "latest" ,
22- isSilent : true ,
23- isForceRunAfter : true ,
24- cause : new Error ( "installer refused" ) ,
17+ it . effect . each ( [ "ordinary" , "confirmed" , "unconfirmed" , "mixed" , "interrupted" ] as const ) (
18+ "handles %s installer termination without unsafe recovery" ,
19+ ( mode ) => {
20+ const unsafe = ! [ "ordinary" , "confirmed" ] . includes ( mode ) ;
21+ const ordinary = new ElectronUpdater . ElectronUpdaterQuitAndInstallError ( {
22+ channel : "latest" ,
23+ isSilent : true ,
24+ isForceRunAfter : true ,
25+ cause : new Error ( "installer refused" ) ,
26+ } ) ;
27+ const error = new ElectronUpdater . ElectronUpdaterQuitAndInstallError ( {
28+ channel : "latest" ,
29+ isSilent : true ,
30+ isForceRunAfter : true ,
31+ terminationConfirmed : ! unsafe ,
32+ cause : new Error ( "helper exit unconfirmed" ) ,
33+ } ) ;
34+ const failure =
35+ mode === "ordinary"
36+ ? Effect . fail ( ordinary )
37+ : mode === "confirmed"
38+ ? Effect . fail ( error )
39+ : mode === "unconfirmed"
40+ ? Effect . die ( error )
41+ : ( mode === "mixed" ? Effect . fail ( ordinary ) : Effect . interrupt ) . pipe (
42+ Effect . ensuring ( Effect . die ( error ) ) ,
43+ ) ;
44+ const harness = makeHarness ( { quitAndInstall : failure } ) ;
45+ return Effect . scoped (
46+ Effect . gen ( function * ( ) {
47+ const desktopState = yield * DesktopState . DesktopState ;
48+ const updates = yield * DesktopUpdates . DesktopUpdates ;
49+ yield * updates . configure ;
50+ harness . emit ( "update-downloaded" , { version : "1.2.4" } ) ;
51+ yield * flushCallbacks ;
52+ const result = yield * updates . install ;
53+ assert . isTrue ( result . accepted ) ;
54+ assert . isFalse ( yield * Ref . get ( desktopState . quitting ) ) ;
55+ assert . deepEqual (
56+ harness . installSteps ,
57+ unsafe ? [ "quitAndInstall" ] : [ "quitAndInstall" , "startBackend" ] ,
58+ ) ;
59+ assert . equal ( harness . updateRestartMarkers . size , unsafe ? 1 : 0 ) ;
60+ assert . equal ( harness . installRecords . size , unsafe ? 1 : 0 ) ;
61+ if ( unsafe ) {
62+ const state = yield * updates . getState ;
63+ assert . equal ( state . status , "error" ) ;
64+ assert . equal ( state . canRetry , false ) ;
65+ assert . include ( state . message ?? "" , "recovery" ) ;
66+ harness . emit ( "error" , new Error ( "late updater error" ) ) ;
67+ yield * flushCallbacks ;
68+ assert . isFalse ( ( yield * updates . install ) . accepted ) ;
69+ assert . equal ( harness . quitAndInstalls ( ) , 1 ) ;
70+ assert . deepEqual ( harness . installSteps , [ "quitAndInstall" ] ) ;
71+ assert . equal ( harness . updateRestartMarkers . size , 1 ) ;
72+ assert . equal ( harness . installRecords . size , 1 ) ;
73+ }
2574 } ) ,
26- ) ,
27- } ) ;
28-
29- return Effect . scoped (
30- Effect . gen ( function * ( ) {
31- const desktopState = yield * DesktopState . DesktopState ;
32- const updates = yield * DesktopUpdates . DesktopUpdates ;
33- yield * updates . configure ;
34- harness . emit ( "update-downloaded" , { version : "1.2.4" } ) ;
35- yield * flushCallbacks ;
36-
37- const result = yield * updates . install ;
38- assert . isTrue ( result . accepted ) ;
39- assert . isFalse ( yield * Ref . get ( desktopState . quitting ) ) ;
40- assert . deepEqual ( harness . installSteps , [ "quitAndInstall" , "startBackend" ] ) ;
41- assert . equal ( harness . updateRestartMarkers . size , 0 ) ;
42- assert . equal ( harness . installRecords . size , 0 ) ;
43- } ) ,
44- ) . pipe ( Effect . provide ( Layer . merge ( TestClock . layer ( ) , harness . layer ) ) ) ;
45- } ) ;
75+ ) . pipe ( Effect . provide ( Layer . merge ( TestClock . layer ( ) , harness . layer ) ) ) ;
76+ } ,
77+ ) ;
4678
4779 it . effect ( "keeps the disabled primary stopped when quitAndInstall fails" , ( ) => {
4880 const harness = makeHarness ( {
0 commit comments