@@ -2,6 +2,7 @@ import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";
22import { describe , expect , it } from "@effect/vitest" ;
33
44import {
5+ filterSharedServerPatch ,
56 findSharedSettingsMismatches ,
67 pickSharedServerSettings ,
78 splitSharedServerPatch ,
@@ -11,6 +12,7 @@ import {
1112const primaryId = EnvironmentId . make ( "env-primary" ) ;
1213const laptopId = EnvironmentId . make ( "env-laptop" ) ;
1314const boxId = EnvironmentId . make ( "env-box" ) ;
15+ const restartCapabilities = { threadRestartContinuation : true } ;
1416
1517describe ( "supportsSharedSettingsSync" , ( ) => {
1618 it ( "accepts only connected servers that advertise the shared-settings capability" , ( ) => {
@@ -40,16 +42,24 @@ describe("splitSharedServerPatch", () => {
4042 const { sharedPatch, localPatch } = splitSharedServerPatch ( {
4143 sidebarAutoSettleAfterDays : 7 ,
4244 sidebarAutoSettleOnMerge : false ,
45+ continueThreadsAfterServerUpdate : true ,
4346 enableAgentBrowserAccess : false ,
4447 } ) ;
45- expect ( sharedPatch ) . toEqual ( { sidebarAutoSettleAfterDays : 7 , sidebarAutoSettleOnMerge : false } ) ;
48+ expect ( sharedPatch ) . toEqual ( {
49+ sidebarAutoSettleAfterDays : 7 ,
50+ sidebarAutoSettleOnMerge : false ,
51+ continueThreadsAfterServerUpdate : true ,
52+ } ) ;
4653 expect ( localPatch ) . toEqual ( { enableAgentBrowserAccess : false } ) ;
4754 } ) ;
4855} ) ;
4956
5057describe ( "pickSharedServerSettings" , ( ) => {
5158 it ( "returns only the shared keys" , ( ) => {
52- expect ( Object . keys ( pickSharedServerSettings ( DEFAULT_SERVER_SETTINGS ) ) . sort ( ) ) . toEqual ( [
59+ expect (
60+ Object . keys ( pickSharedServerSettings ( DEFAULT_SERVER_SETTINGS , restartCapabilities ) ) . sort ( ) ,
61+ ) . toEqual ( [
62+ "continueThreadsAfterServerUpdate" ,
5363 "defaultThreadEnvMode" ,
5464 "newWorktreesStartFromOrigin" ,
5565 "sidebarAutoSettleAfterDays" ,
@@ -59,9 +69,106 @@ describe("pickSharedServerSettings", () => {
5969 } ) ;
6070} ) ;
6171
72+ describe ( "filterSharedServerPatch" , ( ) => {
73+ it . each ( [ true , false ] ) ( "preserves supported restart preference %s" , ( enabled ) => {
74+ const patch = { continueThreadsAfterServerUpdate : enabled , sidebarAutoSettleAfterDays : 7 } ;
75+ expect ( filterSharedServerPatch ( patch , restartCapabilities ) ) . toEqual ( patch ) ;
76+ } ) ;
77+
78+ it . each ( [ undefined , { } , { threadRestartContinuation : false } ] ) (
79+ "omits only the unsupported restart preference with capabilities %j" ,
80+ ( capabilities ) => {
81+ expect (
82+ filterSharedServerPatch (
83+ { continueThreadsAfterServerUpdate : true , sidebarAutoSettleAfterDays : 7 } ,
84+ capabilities ,
85+ ) ,
86+ ) . toEqual ( { sidebarAutoSettleAfterDays : 7 } ) ;
87+ expect ( pickSharedServerSettings ( DEFAULT_SERVER_SETTINGS , capabilities ) ) . not . toHaveProperty (
88+ "continueThreadsAfterServerUpdate" ,
89+ ) ;
90+ } ,
91+ ) ;
92+ } ) ;
93+
6294describe ( "findSharedSettingsMismatches" , ( ) => {
6395 const primarySettings = { ...DEFAULT_SERVER_SETTINGS , sidebarAutoSettleAfterDays : 7 } ;
6496
97+ it . each ( [ true , false ] ) (
98+ "detects remote restart continuation drift when the preference is %s" ,
99+ ( enabled ) => {
100+ const settings = { ...primarySettings , continueThreadsAfterServerUpdate : enabled } ;
101+ const remoteSettings = { ...settings , continueThreadsAfterServerUpdate : ! enabled } ;
102+ const environment = {
103+ environmentId : boxId ,
104+ label : "Remote Box" ,
105+ syncEligible : true ,
106+ settings : remoteSettings ,
107+ capabilities : restartCapabilities ,
108+ } ;
109+ expect (
110+ findSharedSettingsMismatches ( {
111+ primaryEnvironmentId : primaryId ,
112+ primarySettings : settings ,
113+ primaryCapabilities : restartCapabilities ,
114+ environments : [ environment ] ,
115+ } ) ,
116+ ) . toEqual ( [ { environmentId : boxId , label : "Remote Box" } ] ) ;
117+ expect (
118+ findSharedSettingsMismatches ( {
119+ primaryEnvironmentId : primaryId ,
120+ primarySettings : settings ,
121+ primaryCapabilities : restartCapabilities ,
122+ environments : [
123+ {
124+ ...environment ,
125+ settings : Object . assign (
126+ { } ,
127+ remoteSettings ,
128+ pickSharedServerSettings ( settings , restartCapabilities ) ,
129+ ) ,
130+ } ,
131+ ] ,
132+ } ) ,
133+ ) . toEqual ( [ ] ) ;
134+ } ,
135+ ) ;
136+
137+ it . each ( [
138+ [ undefined , restartCapabilities ] ,
139+ [ restartCapabilities , undefined ] ,
140+ [ undefined , undefined ] ,
141+ ] ) (
142+ "ignores restart drift unless both servers support it (%j, %j)" ,
143+ ( primaryCapabilities , capabilities ) => {
144+ const environment = {
145+ environmentId : boxId ,
146+ label : "Remote Box" ,
147+ syncEligible : true ,
148+ capabilities,
149+ settings : { ...primarySettings , continueThreadsAfterServerUpdate : true } ,
150+ } ;
151+ const input = {
152+ primaryEnvironmentId : primaryId ,
153+ primarySettings,
154+ primaryCapabilities,
155+ environments : [ environment ] ,
156+ } ;
157+ expect ( findSharedSettingsMismatches ( input ) ) . toEqual ( [ ] ) ;
158+ expect (
159+ findSharedSettingsMismatches ( {
160+ ...input ,
161+ environments : [
162+ {
163+ ...environment ,
164+ settings : { ...environment . settings , sidebarAutoSettleAfterDays : 14 } ,
165+ } ,
166+ ] ,
167+ } ) ,
168+ ) . toEqual ( [ { environmentId : boxId , label : "Remote Box" } ] ) ;
169+ } ,
170+ ) ;
171+
65172 it ( "lists sync-eligible environments whose shared settings differ" , ( ) => {
66173 const mismatches = findSharedSettingsMismatches ( {
67174 primaryEnvironmentId : primaryId ,
0 commit comments