@@ -23,10 +23,12 @@ import * as Path from "effect/Path";
2323import * as PlatformError from "effect/PlatformError" ;
2424import * as Schema from "effect/Schema" ;
2525import * as Stream from "effect/Stream" ;
26+ import * as TestClock from "effect/testing/TestClock" ;
2627import * as SqlClient from "effect/unstable/sql/SqlClient" ;
2728import * as ServerSecretStore from "./auth/ServerSecretStore.ts" ;
2829import * as ServerConfig from "./config.ts" ;
2930import { SqlitePersistenceMemory } from "./persistence/Layers/Sqlite.ts" ;
31+ import { writeFileStringAtomically } from "./atomicWrite.ts" ;
3032import * as ServerSettingsModule from "./serverSettings.ts" ;
3133import { resolveProviderInstanceTerminalEnvironment } from "./terminal/Manager.ts" ;
3234
@@ -131,6 +133,79 @@ it.layer(NodeServices.layer)("server settings", (it) => {
131133 } ) . pipe ( Effect . provide ( makeServerSettingsLayer ( ) ) ) ,
132134 ) ;
133135
136+ it . effect ( "saves through a symlinked settings file without replacing the link" , ( ) =>
137+ Effect . gen ( function * ( ) {
138+ const config = yield * ServerConfig . ServerConfig ;
139+ const fs = yield * FileSystem . FileSystem ;
140+ const path = yield * Path . Path ;
141+ const service = yield * ServerSettingsModule . ServerSettingsService ;
142+ const dotfiles = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-settings-dotfiles-" } ) ;
143+ const linkedSettingsPath = path . join ( dotfiles , "settings.json" ) ;
144+ yield * fs . writeFileString ( linkedSettingsPath , `{ "responseStreamingMode": "turn" }` ) ;
145+ yield * fs . remove ( config . settingsPath , { force : true } ) ;
146+ yield * fs . symlink ( linkedSettingsPath , config . settingsPath ) ;
147+
148+ yield * service . updateSettings ( { responseStreamingMode : "paragraph" } ) ;
149+
150+ assert . equal ( yield * fs . readLink ( config . settingsPath ) , linkedSettingsPath ) ;
151+ const persisted = yield * decodeServerSettingsJson (
152+ yield * fs . readFileString ( linkedSettingsPath ) ,
153+ ) ;
154+ assert . equal ( persisted . responseStreamingMode , "paragraph" ) ;
155+ } ) . pipe ( Effect . provide ( makeServerSettingsLayer ( ) ) ) ,
156+ ) ;
157+
158+ it . effect ( "reloads when the destination of a symlinked settings file changes" , ( ) =>
159+ Effect . scoped (
160+ Effect . gen ( function * ( ) {
161+ const config = yield * ServerConfig . ServerConfig ;
162+ const fs = yield * FileSystem . FileSystem ;
163+ const path = yield * Path . Path ;
164+ const service = yield * ServerSettingsModule . ServerSettingsService ;
165+ const dotfiles = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-settings-dotfiles-" } ) ;
166+ const linkedSettingsPath = path . join ( dotfiles , "settings.json" ) ;
167+ yield * fs . writeFileString ( linkedSettingsPath , `{ "responseStreamingMode": "turn" }` ) ;
168+ yield * fs . remove ( config . settingsPath , { force : true } ) ;
169+ yield * fs . symlink ( linkedSettingsPath , config . settingsPath ) ;
170+ yield * service . start ;
171+ const changes = yield * service . subscribeChanges ;
172+
173+ yield * writeFileStringAtomically ( {
174+ filePath : linkedSettingsPath ,
175+ contents : `{ "responseStreamingMode": "paragraph" }` ,
176+ } ) ;
177+
178+ const change = yield * changes . pipe ( Stream . runHead , Effect . timeout ( "2 seconds" ) ) ;
179+ assert . equal ( Option . getOrUndefined ( change ) ?. responseStreamingMode , "paragraph" ) ;
180+ } ) ,
181+ ) . pipe ( TestClock . withLive , Effect . provide ( makeServerSettingsLayer ( ) ) ) ,
182+ ) ;
183+
184+ it . effect ( "reloads when a dangling settings link gets its destination" , ( ) =>
185+ Effect . scoped (
186+ Effect . gen ( function * ( ) {
187+ const config = yield * ServerConfig . ServerConfig ;
188+ const fs = yield * FileSystem . FileSystem ;
189+ const path = yield * Path . Path ;
190+ const service = yield * ServerSettingsModule . ServerSettingsService ;
191+ const dotfiles = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-settings-dotfiles-" } ) ;
192+ const linkedSettingsPath = path . join ( dotfiles , "not-yet" , "settings.json" ) ;
193+ yield * fs . remove ( config . settingsPath , { force : true } ) ;
194+ yield * fs . symlink ( linkedSettingsPath , config . settingsPath ) ;
195+ yield * service . start ;
196+ const changes = yield * service . subscribeChanges ;
197+
198+ yield * writeFileStringAtomically ( {
199+ filePath : linkedSettingsPath ,
200+ contents : `{ "responseStreamingMode": "paragraph" }` ,
201+ } ) ;
202+
203+ const change = yield * changes . pipe ( Stream . runHead , Effect . timeout ( "2 seconds" ) ) ;
204+ assert . equal ( Option . getOrUndefined ( change ) ?. responseStreamingMode , "paragraph" ) ;
205+ } ) ,
206+ ) . pipe ( TestClock . withLive , Effect . provide ( makeServerSettingsLayer ( ) ) ) ,
207+ ) ;
208+
134209 it . effect ( "preserves context when reading a provider environment secret fails" , ( ) => {
135210 const platformCause = PlatformError . systemError ( {
136211 _tag : "PermissionDenied" ,
0 commit comments