@@ -19,8 +19,11 @@ import {
1919 planScopedSettingsClear ,
2020 planScopedSettingsPatch ,
2121 resolveScopedSettingsTargets ,
22+ resolveUnsupportedSettingKeys ,
23+ scopedDisplaySettings ,
2224 scopedSettingsAreMixed ,
2325 scopedSettingsSource ,
26+ scopedSettingsUnsupportedTargets ,
2427 selectScopedSettingsEnvironments ,
2528} from "./scopedSettings" ;
2629import { resolveSettingsScope } from "./settingsScope" ;
@@ -750,3 +753,103 @@ it("routes legacy model preference keys exclusively to the selected environment"
750753 } ,
751754 ] ) ;
752755} ) ;
756+
757+ describe ( "environments that cannot store a setting" , ( ) => {
758+ const enabledLaptop = environment ( "Laptop" , { settings : { reviewGuidesEnabled : true } } ) ;
759+ const outdatedServer = {
760+ ...server ,
761+ unsupportedSettingKeys : new Set ( [ "reviewGuidesEnabled" , "defaultAutoPull" ] ) ,
762+ } ;
763+ const pair = [ enabledLaptop , outdatedServer ] ;
764+ const pairScope = resolveSettingsScope ( { } , [ ] , pair ) ;
765+ const targets = resolveScopedSettingsTargets ( pairScope , pair ) ;
766+
767+ it ( "reads unsupported keys from the advertised list, else from dropped writes" , ( ) => {
768+ const advertised = Object . keys ( DEFAULT_SERVER_SETTINGS ) . filter (
769+ ( key ) => key !== "reviewGuidesEnabled" ,
770+ ) ;
771+ expect ( [ ...resolveUnsupportedSettingKeys ( advertised , new Set ( [ "branchNamePrefix" ] ) ) ] ) . toEqual ( [
772+ "reviewGuidesEnabled" ,
773+ ] ) ;
774+ expect ( [ ...resolveUnsupportedSettingKeys ( undefined , new Set ( [ "reviewGuidesEnabled" ] ) ) ] ) . toEqual (
775+ [ "reviewGuidesEnabled" ] ,
776+ ) ;
777+ expect ( resolveUnsupportedSettingKeys ( undefined , undefined ) . size ) . toBe ( 0 ) ;
778+ } ) ;
779+
780+ it ( "leaves them out of the mixed state and shows the value where it is stored" , ( ) => {
781+ expect ( scopedSettingsAreMixed ( targets , [ "reviewGuidesEnabled" ] ) ) . toBe ( false ) ;
782+ expect ( scopedSettingsUnsupportedTargets ( targets , [ "reviewGuidesEnabled" ] ) ) . toEqual ( [
783+ targets [ 1 ] ,
784+ ] ) ;
785+ expect ( scopedDisplaySettings ( targets [ 1 ] ! , targets ) . reviewGuidesEnabled ) . toBe ( true ) ;
786+ // Keys the outdated environment does store still compare across both.
787+ expect (
788+ scopedSettingsAreMixed (
789+ [
790+ targets [ 0 ] ! ,
791+ { ...targets [ 1 ] ! , settings : { ...targets [ 1 ] ! . settings , branchNamePrefix : "x" } } ,
792+ ] ,
793+ [ "branchNamePrefix" ] ,
794+ ) ,
795+ ) . toBe ( true ) ;
796+ } ) ;
797+
798+ it ( "writes only where the setting can be stored" , ( ) => {
799+ const plan = planScopedSettingsPatch ( pairScope , pair , {
800+ reviewGuidesEnabled : false ,
801+ branchNamePrefix : "feat" ,
802+ } ) ;
803+ expect ( plan . serverWrites . map ( ( { environmentId, patch } ) => ( { environmentId, patch } ) ) ) . toEqual (
804+ [
805+ {
806+ environmentId : enabledLaptop . environmentId ,
807+ patch : { reviewGuidesEnabled : false , branchNamePrefix : "feat" } ,
808+ } ,
809+ { environmentId : server . environmentId , patch : { branchNamePrefix : "feat" } } ,
810+ ] ,
811+ ) ;
812+ } ) ;
813+
814+ it ( "names the environments to update when none can store the setting" , ( ) => {
815+ const plan = planScopedSettingsPatch (
816+ resolveSettingsScope ( { machine : server . environmentId } , [ ] , pair ) ,
817+ pair ,
818+ { reviewGuidesEnabled : true } ,
819+ ) ;
820+ expect ( plan . serverWrites ) . toEqual ( [ ] ) ;
821+ expect ( plan . unavailableReason ) . toBe ( "Update T3 Code on Server to use this setting." ) ;
822+ } ) ;
823+
824+ it ( "skips project override writes for keys the environment cannot store" , ( ) => {
825+ const plan = planScopedSettingsPatch ( project , [ laptop , outdatedServer ] , {
826+ defaultAutoPull : true ,
827+ } ) ;
828+ expect ( plan . serverWrites . map ( ( { environmentId } ) => environmentId ) ) . toEqual ( [
829+ laptop . environmentId ,
830+ ] ) ;
831+ } ) ;
832+
833+ it ( "reports the setting keys an environment dropped, including inside project overrides" , async ( ) => {
834+ const result = await persistScopedSettingsPatch (
835+ planScopedSettingsPatch ( project , environments , {
836+ defaultAutoPull : true ,
837+ enableAgentBrowserAccess : false ,
838+ } ) ,
839+ async ( { environmentId } ) => ( {
840+ _tag : "Success" as const ,
841+ value : {
842+ ...DEFAULT_SERVER_SETTINGS ,
843+ projectSettingsOverrides :
844+ environmentId === laptop . environmentId
845+ ? { [ laptopProjectId ] : { defaultAutoPull : true , enableAgentBrowserAccess : false } }
846+ : { [ projectId ] : { defaultAutoPull : true } } ,
847+ } ,
848+ } ) ,
849+ vi . fn ( ) ,
850+ ) ;
851+ expect (
852+ result . failedEnvironments . map ( ( { label, droppedKeys } ) => ( { label, droppedKeys } ) ) ,
853+ ) . toEqual ( [ { label : server . label , droppedKeys : [ "enableAgentBrowserAccess" ] } ] ) ;
854+ } ) ;
855+ } ) ;
0 commit comments