@@ -44,6 +44,7 @@ const clientSettings: ClientSettings = {
4444 fontSizeTerminal : 12 ,
4545 fontSmoothing : true ,
4646 glassOpacity : 80 ,
47+ onboardingCompletedAt : null ,
4748 panelAnimationDurationMs : 0 ,
4849 planModeEnabled : false ,
4950 proactivePanelsEnabled : true ,
@@ -136,6 +137,59 @@ describe("DesktopClientSettings", () => {
136137 ) ,
137138 ) ;
138139
140+ for ( const failure of [
141+ { label : "permission" , reason : "PermissionDenied" } ,
142+ { label : "I/O" , reason : "Unknown" } ,
143+ ] as const ) {
144+ it . effect ( `preserves saved preferences across ${ failure . label } read failures and retries` , ( ) =>
145+ withClientSettings (
146+ Effect . gen ( function * ( ) {
147+ const environment = yield * DesktopEnvironment . DesktopEnvironment ;
148+ const fileSystem = yield * FileSystem . FileSystem ;
149+ const settings = yield * DesktopClientSettings . DesktopClientSettings ;
150+ const savedSettings = {
151+ ...clientSettings ,
152+ onboardingCompletedAt : "2026-09-05T12:00:00.000Z" ,
153+ } ;
154+ yield * settings . set ( savedSettings ) ;
155+ const savedContents = yield * fileSystem . readFileString ( environment . clientSettingsPath ) ;
156+ const cause = PlatformError . systemError ( {
157+ _tag : failure . reason ,
158+ module : "FileSystem" ,
159+ method : "readFileString" ,
160+ pathOrDescriptor : environment . clientSettingsPath ,
161+ } ) ;
162+ let failRead = true ;
163+ const retryableSettings = yield * DesktopClientSettings . make . pipe (
164+ Effect . provideService (
165+ FileSystem . FileSystem ,
166+ FileSystem . FileSystem . of ( {
167+ ...fileSystem ,
168+ readFileString : ( path ) =>
169+ Effect . suspend ( ( ) =>
170+ failRead ? Effect . fail ( cause ) : fileSystem . readFileString ( path ) ,
171+ ) ,
172+ } ) ,
173+ ) ,
174+ ) ;
175+
176+ const error = yield * retryableSettings . get . pipe ( Effect . flip ) ;
177+ assert . instanceOf ( error , DesktopClientSettings . DesktopClientSettingsReadError ) ;
178+ assert . equal ( error . operation , "read-file" ) ;
179+ assert . equal ( error . path , environment . clientSettingsPath ) ;
180+ assert . strictEqual ( error . cause , cause ) ;
181+ assert . equal (
182+ yield * fileSystem . readFileString ( environment . clientSettingsPath ) ,
183+ savedContents ,
184+ ) ;
185+
186+ failRead = false ;
187+ assert . deepEqual ( yield * retryableSettings . get , Option . some ( savedSettings ) ) ;
188+ } ) ,
189+ ) ,
190+ ) ;
191+ }
192+
139193 it . effect ( "reports the failed client settings write operation and path" , ( ) =>
140194 withClientSettings (
141195 Effect . gen ( function * ( ) {
@@ -222,17 +276,31 @@ describe("DesktopClientSettings", () => {
222276 ) ,
223277 ) ;
224278
225- it . effect ( "treats malformed client settings documents as absent" , ( ) =>
226- withClientSettings (
227- Effect . gen ( function * ( ) {
228- const environment = yield * DesktopEnvironment . DesktopEnvironment ;
229- const fileSystem = yield * FileSystem . FileSystem ;
230- const settings = yield * DesktopClientSettings . DesktopClientSettings ;
231- yield * fileSystem . makeDirectory ( environment . stateDir , { recursive : true } ) ;
232- yield * fileSystem . writeFileString ( environment . clientSettingsPath , "{not-json" ) ;
279+ for ( const document of [
280+ { label : "malformed JSON" , contents : "{not-json" } ,
281+ { label : "invalid direct settings" , contents : '{"fontSizeCode":"large"}' } ,
282+ { label : "invalid legacy settings" , contents : '{"settings":{"fontSizeCode":"large"}}' } ,
283+ ] ) {
284+ it . effect ( `reports ${ document . label } without treating the settings file as absent` , ( ) =>
285+ withClientSettings (
286+ Effect . gen ( function * ( ) {
287+ const environment = yield * DesktopEnvironment . DesktopEnvironment ;
288+ const fileSystem = yield * FileSystem . FileSystem ;
289+ const settings = yield * DesktopClientSettings . DesktopClientSettings ;
290+ yield * fileSystem . makeDirectory ( environment . stateDir , { recursive : true } ) ;
291+ yield * fileSystem . writeFileString ( environment . clientSettingsPath , document . contents ) ;
233292
234- assert . isTrue ( Option . isNone ( yield * settings . get ) ) ;
235- } ) ,
236- ) ,
237- ) ;
293+ const error = yield * settings . get . pipe ( Effect . flip ) ;
294+ assert . instanceOf ( error , DesktopClientSettings . DesktopClientSettingsReadError ) ;
295+ assert . equal ( error . operation , "decode-document" ) ;
296+ assert . equal ( error . path , environment . clientSettingsPath ) ;
297+ assert . instanceOf ( error . cause , Schema . SchemaError ) ;
298+ assert . equal (
299+ yield * fileSystem . readFileString ( environment . clientSettingsPath ) ,
300+ document . contents ,
301+ ) ;
302+ } ) ,
303+ ) ,
304+ ) ;
305+ }
238306} ) ;
0 commit comments