@@ -6,10 +6,13 @@ import {
66 ProviderInstanceId ,
77 SecretProviderId ,
88 SecretProviderKind ,
9+ ServerSettings ,
10+ ServerSettingsPatch ,
911 UsageLimitSourceId ,
1012 type ServerProvider ,
1113} from "@t3tools/contracts" ;
1214import * as Duration from "effect/Duration" ;
15+ import * as Schema from "effect/Schema" ;
1316import { describe , expect , it } from "vite-plus/test" ;
1417import { resolveServerBackgroundActivitySettings } from "./backgroundActivitySettings.ts" ;
1518import { createModelSelection } from "./model.ts" ;
@@ -24,6 +27,9 @@ import {
2427 resolveSourceControlWriterModelSelection ,
2528} from "./serverSettings.ts" ;
2629
30+ const decodeServerSettings = Schema . decodeUnknownSync ( ServerSettings ) ;
31+ const decodeServerSettingsPatch = Schema . decodeUnknownSync ( ServerSettingsPatch ) ;
32+
2733const FOLDED_SERVER_SETTINGS = { ...DEFAULT_SERVER_SETTINGS , projectSettingsFolded : true } ;
2834
2935describe ( "fallbackTextGenerationModelSelection" , ( ) => {
@@ -499,6 +505,37 @@ describe("serverSettings helpers", () => {
499505 } ) ;
500506 } ) ;
501507
508+ // regression: #18334 a newer client must still see this server drop a key it does not know
509+ it ( "drops an override key this server does not know from a patch and keeps one it stored" , ( ) => {
510+ const projectId = ProjectId . make ( "project-a" ) ;
511+ const current = decodeServerSettings ( {
512+ projectSettingsFolded : true ,
513+ projectSettingsOverrides : {
514+ [ projectId ] : { defaultAutoPull : true , addedByNewerServer : 3 } ,
515+ } ,
516+ } ) ;
517+ const patch = decodeServerSettingsPatch ( {
518+ projectSettingsOverrides : {
519+ [ projectId ] : { defaultAutoPull : false , addedByNewerServer : 4 , addedByNewerClient : "x" } ,
520+ } ,
521+ } ) ;
522+
523+ const updated = applyServerSettingsPatch ( current , patch ) ;
524+ expect ( updated . projectSettingsOverrides [ projectId ] ) . toEqual ( {
525+ defaultAutoPull : false ,
526+ addedByNewerServer : 3 ,
527+ } ) ;
528+ const reset = applyServerSettingsPatch ( updated , {
529+ projectSettingsOverrides : { [ projectId ] : { } } ,
530+ } ) ;
531+ expect ( reset . projectSettingsOverrides [ projectId ] ) . toEqual ( { addedByNewerServer : 3 } ) ;
532+ expect (
533+ applyServerSettingsPatch ( reset , {
534+ projectSettingsOverrides : { [ projectId ] : null } ,
535+ } ) . projectSettingsOverrides [ projectId ] ,
536+ ) . toBeUndefined ( ) ;
537+ } ) ;
538+
502539 it ( "clears a project's providerInstances override when a patch entry sends an empty map" , ( ) => {
503540 const instanceId = ProviderInstanceId . make ( "codex_work" ) ;
504541 const projectId = ProjectId . make ( "project-a" ) ;
0 commit comments