@@ -150,6 +150,9 @@ describe("Grok orphan adoption (#511)", () => {
150150 "[models]" ,
151151 'default = "ocx-retired"' ,
152152 "" ,
153+ "[ui]" ,
154+ 'fork_secondary_model = "ocx-retired"' ,
155+ "" ,
153156 "[model.ocx-retired]" ,
154157 'model = "retired/model"' ,
155158 'base_url = "http://127.0.0.1:10100/v1"' ,
@@ -160,6 +163,37 @@ describe("Grok orphan adoption (#511)", () => {
160163 injectGrokConfig ( 10100 , MODELS , { grokHome } ) ;
161164 const content = readFileSync ( configPath , "utf8" ) ;
162165 expect ( content ) . toContain ( 'default = "ocx-retired"' ) ;
166+ expect ( content ) . toContain ( 'fork_secondary_model = "ocx-retired"' ) ;
167+ expect ( content ) . toContain ( "[model.ocx-retired]" ) ;
168+ expect ( content ) . toContain ( 'model = "retired/model"' ) ;
169+
170+ const second = injectGrokConfig ( 10100 , MODELS , { grokHome } ) ;
171+ expect ( second ) . toMatchObject ( { ok : true , changed : false } ) ;
172+ expect ( readFileSync ( configPath , "utf8" ) ) . toBe ( content ) ;
173+ } ) ;
174+
175+ test ( "keeps an owned-looking orphan whose model id is missing" , ( ) => {
176+ writeFileSync ( configPath , [
177+ "[model.ocx-unknown]" ,
178+ 'base_url = "http://127.0.0.1:10100/v1"' ,
179+ 'api_key = "opencodex-loopback"' ,
180+ "" ,
181+ ] . join ( "\n" ) ) ;
182+
183+ injectGrokConfig ( 10100 , MODELS , { grokHome } ) ;
184+ const content = readFileSync ( configPath , "utf8" ) ;
185+ expect ( content ) . toContain ( "[model.ocx-unknown]" ) ;
186+ expect ( content ) . toContain ( 'api_key = "opencodex-loopback"' ) ;
187+ } ) ;
188+
189+ test ( "still removes a catalog orphan when that model is excluded" , ( ) => {
190+ writeOrphanedConfig ( ) ;
191+
192+ injectGrokConfig ( 10100 , MODELS , {
193+ grokHome,
194+ excluded : new Set ( [ "gpt-5.6-sol" ] ) ,
195+ } ) ;
196+ expect ( modelTables ( readFileSync ( configPath , "utf8" ) ) ) . toEqual ( [ ] ) ;
163197 } ) ;
164198
165199 // F7: the sweep must converge, or `changed` is meaningless to callers.
0 commit comments