@@ -15,6 +15,7 @@ const {
1515 writeFileSyncMock,
1616 copyFileSyncMock,
1717 execFileSyncMock,
18+ readFileSyncMock,
1819} = vi . hoisted ( ( ) => ( {
1920 appendSwitchMock : vi . fn ( ) ,
2021 getSwitchValueMock : vi . fn ( ) ,
@@ -25,6 +26,7 @@ const {
2526 writeFileSyncMock : vi . fn ( ) ,
2627 copyFileSyncMock : vi . fn ( ) ,
2728 execFileSyncMock : vi . fn ( ) ,
29+ readFileSyncMock : vi . fn ( ) ,
2830} ) ) ;
2931
3032vi . mock ( "electron" , ( ) => ( {
@@ -45,7 +47,7 @@ vi.mock("electron", () => ({
4547} ) ) ;
4648
4749vi . mock ( "node:fs" , ( ) => ( {
48- readFileSync : ( ) => "{}" ,
50+ readFileSync : readFileSyncMock ,
4951 mkdirSync : mkdirSyncMock ,
5052 writeFileSync : writeFileSyncMock ,
5153 copyFileSync : copyFileSyncMock ,
@@ -68,6 +70,66 @@ describe("DesktopPreReadyPlatform", () => {
6870 writeFileSyncMock . mockReset ( ) ;
6971 copyFileSyncMock . mockReset ( ) ;
7072 execFileSyncMock . mockReset ( ) ;
73+ readFileSyncMock . mockReset ( ) . mockReturnValue ( "{}" ) ;
74+ } ) ;
75+
76+ it . effect ( "persists Linux scaling synchronously across relaunches and settings rewrites" , ( ) => {
77+ vi . stubEnv ( "T3CODE_HOME" , "/isolated" ) ;
78+ vi . stubEnv ( "VITE_DEV_SERVER_URL" , "" ) ;
79+ const settingsPath = "/isolated/userdata/desktop-settings.json" ;
80+ const files = new Map ( [ [ settingsPath , "{}" ] ] ) ;
81+ const commandLine = new Map < string , string > ( ) ;
82+ readFileSyncMock . mockImplementation ( ( path : string ) => {
83+ const contents = files . get ( path ) ;
84+ if ( contents === undefined ) throw new Error ( "ENOENT" ) ;
85+ return contents ;
86+ } ) ;
87+ writeFileSyncMock . mockImplementation ( ( path : string , contents : string ) => {
88+ files . set ( path , contents ) ;
89+ } ) ;
90+ hasSwitchMock . mockImplementation ( ( name : string ) => commandLine . has ( name ) ) ;
91+ getSwitchValueMock . mockImplementation ( ( name : string ) => commandLine . get ( name ) ?? "" ) ;
92+ appendSwitchMock . mockImplementation ( ( name : string , value : string ) => {
93+ commandLine . set ( name , value ) ;
94+ } ) ;
95+ const launch = Effect . gen ( function * ( ) {
96+ const startup = Promise . resolve ( ) . then ( ( ) => commandLine . get ( "force-device-scale-factor" ) ) ;
97+ yield * DesktopPreReadyPlatform . make ;
98+ return yield * Effect . promise ( ( ) => startup ) ;
99+ } ) ;
100+
101+ return Effect . gen ( function * ( ) {
102+ for ( const explicitScale of [ "1.75" , "1" ] ) {
103+ commandLine . clear ( ) ;
104+ commandLine . set ( "force-device-scale-factor" , explicitScale ) ;
105+ appendSwitchMock . mockClear ( ) ;
106+ assert . equal ( yield * launch , explicitScale ) ;
107+ assert . isFalse (
108+ appendSwitchMock . mock . calls . some ( ( [ name ] ) => name === "force-device-scale-factor" ) ,
109+ ) ;
110+
111+ // The settings service discards fields it does not own when rewriting its document.
112+ files . set ( settingsPath , JSON . stringify ( { linuxPasswordStore : "basic" } ) ) ;
113+ commandLine . clear ( ) ;
114+ assert . equal ( yield * launch , explicitScale ) ;
115+ }
116+ } ) . pipe (
117+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
118+ Effect . ensuring ( Effect . sync ( ( ) => vi . unstubAllEnvs ( ) ) ) ,
119+ ) ;
120+ } ) ;
121+
122+ it . effect . each ( [ "darwin" , "win32" ] as const ) ( "leaves device scaling alone on %s" , ( platform ) => {
123+ readFileSyncMock . mockReturnValue ( "1.75" ) ;
124+ hasSwitchMock . mockImplementation ( ( name : string ) => name === "force-device-scale-factor" ) ;
125+ getSwitchValueMock . mockReturnValue ( "2" ) ;
126+
127+ return Effect . gen ( function * ( ) {
128+ yield * DesktopPreReadyPlatform . make ;
129+ assert . deepEqual ( readFileSyncMock . mock . calls , [ ] ) ;
130+ assert . deepEqual ( writeFileSyncMock . mock . calls , [ ] ) ;
131+ assert . deepEqual ( appendSwitchMock . mock . calls , [ ] ) ;
132+ } ) . pipe ( Effect . provideService ( HostProcess . Platform , platform ) ) ;
71133 } ) ;
72134
73135 it . effect ( "preserves an explicit Linux password-store switch" , ( ) => {
0 commit comments