@@ -2,6 +2,8 @@ import { mkdtemp, readFile, stat, writeFile } from "node:fs/promises";
22import { tmpdir } from "node:os" ;
33import { join } from "node:path" ;
44
5+ import * as FileSystem from "effect/FileSystem" ;
6+ import * as PlatformError from "effect/PlatformError" ;
57import { Cause , ConfigProvider , Effect , Exit , Option } from "effect" ;
68import { describe , expect , it } from "vite-plus/test" ;
79
@@ -98,6 +100,47 @@ describe("resolveConfigPath", () => {
98100 expect ( contents . auth_token ) . toBe ( "dummy-token" ) ;
99101 } ) ;
100102
103+ it ( "creates config files with private permissions before chmod" , async ( ) => {
104+ const writeModes : Array < number | undefined > = [ ] ;
105+ const chmodModes : Array < number > = [ ] ;
106+ const fileSystem = FileSystem . makeNoop ( {
107+ chmod : ( _path , mode ) =>
108+ Effect . sync ( ( ) => {
109+ chmodModes . push ( mode ) ;
110+ } ) ,
111+ makeDirectory : ( ) => Effect . void ,
112+ readFileString : ( path ) =>
113+ Effect . fail (
114+ PlatformError . systemError ( {
115+ _tag : "NotFound" ,
116+ module : "FileSystem" ,
117+ method : "readFileString" ,
118+ pathOrDescriptor : path ,
119+ } ) ,
120+ ) ,
121+ writeFileString : ( _path , _data , options ) =>
122+ Effect . sync ( ( ) => {
123+ writeModes . push ( options ?. mode ) ;
124+ } ) ,
125+ } ) ;
126+
127+ await Effect . runPromise (
128+ savePersistedState (
129+ {
130+ token : "dummy-token" ,
131+ apiBaseUrl : "https://api.put.io" ,
132+ } ,
133+ "/tmp/putio-cli/config.json" ,
134+ ) . pipe (
135+ Effect . provideService ( FileSystem . FileSystem , fileSystem ) ,
136+ Effect . provide ( makeCliAppLayer ( makeCliRuntime ( ) ) ) ,
137+ ) ,
138+ ) ;
139+
140+ expect ( writeModes ) . toEqual ( [ 0o600 ] ) ;
141+ expect ( chmodModes ) . toEqual ( [ 0o600 ] ) ;
142+ } ) ;
143+
101144 it ( "exposes persisted-state operations through the CliState service" , async ( ) => {
102145 const dir = await mkdtemp ( join ( tmpdir ( ) , "putio-cli-" ) ) ;
103146 const configPath = join ( dir , "config.json" ) ;
0 commit comments