@@ -191,6 +191,97 @@ describe("GUI/CLI Codex sync backend", () => {
191191 expect ( errors ) . toEqual ( [ refusal ] ) ;
192192 } ) ;
193193
194+ test ( "an explicit sync refreshes the catalog when paginated history refuses injection" , async ( ) => {
195+ let refreshCalls = 0 ;
196+ const errors : string [ ] = [ ] ;
197+
198+ const result = await syncModelsToCodex ( 12345 , config , { log : ( ) => { } , error : line => errors . push ( String ( line ) ) } , {
199+ admitCodexWrite : admittedSync ,
200+ refreshCodexModelCatalog : async ( ) => {
201+ refreshCalls ++ ;
202+ return {
203+ added : 2 ,
204+ path : "/tmp/opencodex-catalog.json" ,
205+ catalogExists : true ,
206+ catalogWritten : true ,
207+ cacheSynced : true ,
208+ comboOmissions : [ ] ,
209+ refreshOutcome : "committed" as const ,
210+ } ;
211+ } ,
212+ injectCodexConfig : async ( ) => ( {
213+ success : false ,
214+ historyPreflightFailureReason : "history_paginated_requires_native_writer" ,
215+ message : "Codex config injection refused: history_paginated_requires_native_writer." ,
216+ } ) ,
217+ currentExternalCodexModelProvider : ( ) => null ,
218+ collectCodexHomeDiagnostic : ( ) => homeDiagnostic ( ) ,
219+ } , { catalogEvenWhenNotInjected : true } ) ;
220+
221+ // The refusal is the injector's, and it stands: only the catalog owner publishes.
222+ expect ( refreshCalls ) . toBe ( 1 ) ;
223+ expect ( result . status ) . toBe ( "catalog-only" ) ;
224+ expect ( result . ok ) . toBe ( true ) ;
225+ expect ( result . added ) . toBe ( 2 ) ;
226+ expect ( result . catalogWritten ) . toBe ( true ) ;
227+ expect ( result . message ) . toContain ( "paginated history requires its native writer" ) ;
228+ expect ( errors ) . toEqual ( [ ] ) ;
229+ } ) ;
230+
231+ test ( "a refused catalog refresh keeps an explicit history-blocked sync unsuccessful" , async ( ) => {
232+ const result = await syncModelsToCodex ( 12345 , config , null , {
233+ admitCodexWrite : admittedSync ,
234+ refreshCodexModelCatalog : async ( ) => ( {
235+ added : 0 ,
236+ path : "/tmp/opencodex-catalog.json" ,
237+ catalogExists : true ,
238+ catalogWritten : false ,
239+ cacheSynced : false ,
240+ comboOmissions : [ ] ,
241+ refreshOutcome : "refused" as const ,
242+ } ) ,
243+ injectCodexConfig : async ( ) => ( {
244+ success : false ,
245+ historyPreflightFailureReason : "history_paginated_requires_native_writer" ,
246+ message : "Codex config injection refused: history_paginated_requires_native_writer." ,
247+ } ) ,
248+ currentExternalCodexModelProvider : ( ) => null ,
249+ collectCodexHomeDiagnostic : ( ) => homeDiagnostic ( ) ,
250+ } , { catalogEvenWhenNotInjected : true } ) ;
251+
252+ expect ( result . status ) . toBe ( "catalog-only" ) ;
253+ expect ( result . ok ) . toBe ( false ) ;
254+ expect ( result . cacheSynced ) . toBe ( false ) ;
255+ expect ( result . message ) . toContain ( "did not complete" ) ;
256+ } ) ;
257+
258+ test ( "an unattended sync keeps the hard failure on the same history refusal" , async ( ) => {
259+ let refreshCalls = 0 ;
260+ const errors : string [ ] = [ ] ;
261+ const refusal = "Codex config injection refused: history_paginated_requires_native_writer." ;
262+
263+ const result = await syncModelsToCodex ( 12345 , config , { log : ( ) => { } , error : line => errors . push ( String ( line ) ) } , {
264+ admitCodexWrite : admittedSync ,
265+ refreshCodexModelCatalog : async ( ) => {
266+ refreshCalls ++ ;
267+ throw new Error ( "catalog refresh must not run for an unattended sync" ) ;
268+ } ,
269+ injectCodexConfig : async ( ) => ( {
270+ success : false ,
271+ historyPreflightFailureReason : "history_paginated_requires_native_writer" ,
272+ message : refusal ,
273+ } ) ,
274+ currentExternalCodexModelProvider : ( ) => null ,
275+ collectCodexHomeDiagnostic : ( ) => homeDiagnostic ( ) ,
276+ } ) ;
277+
278+ expect ( refreshCalls ) . toBe ( 0 ) ;
279+ expect ( result . ok ) . toBe ( false ) ;
280+ expect ( result . catalogWritten ) . toBe ( false ) ;
281+ expect ( result . message ) . toBe ( refusal ) ;
282+ expect ( errors ) . toEqual ( [ refusal ] ) ;
283+ } ) ;
284+
194285 test ( "the real successful injection preflight writes no Codex artifacts" , ( ) => {
195286 const configPath = join ( TEST_CODEX_HOME , "config.toml" ) ;
196287 const profilePath = join ( TEST_CODEX_HOME , "opencodex.config.toml" ) ;
0 commit comments