@@ -95,12 +95,11 @@ describe("Codex runtime plugin install repair", () => {
9595 } ) ;
9696
9797 expect ( result ) . toMatchObject ( {
98- cfg,
99- required : true ,
100- installed : false ,
98+ ok : false ,
10199 status : "failed" ,
100+ message : expect . stringContaining ( "Codex runtime is required but unavailable" ) ,
102101 } ) ;
103- expect ( result . reason ) . toBeTruthy ( ) ;
102+ expect ( "cfg" in result ) . toBe ( false ) ;
104103 } ) ;
105104
106105 it ( "enables an allowed existing Codex install" , async ( ) => {
@@ -124,9 +123,8 @@ describe("Codex runtime plugin install repair", () => {
124123 } ) ;
125124
126125 expect ( result ) . toMatchObject ( {
126+ ok : true ,
127127 required : true ,
128- installed : true ,
129- status : "installed" ,
130128 cfg : { plugins : { entries : { codex : { enabled : true } } } } ,
131129 } ) ;
132130 } ) ;
@@ -150,13 +148,75 @@ describe("Codex runtime plugin install repair", () => {
150148 } ) ;
151149
152150 expect ( result ) . toMatchObject ( {
153- required : true ,
154- installed : false ,
151+ ok : false ,
155152 status : "failed" ,
156- reason : "npm registry returned EAI_AGAIN while fetching @openclaw/codex" ,
153+ message : expect . stringContaining (
154+ "npm registry returned EAI_AGAIN while fetching @openclaw/codex" ,
155+ ) ,
157156 } ) ;
158157 } ) ;
159158
159+ const sensitiveFixture = [ "fixture" , "credential" ] . join ( "-" ) ;
160+ it . each ( [
161+ {
162+ status : "failed" as const ,
163+ error : `Install failed: https://user:${ sensitiveFixture } @registry.example.test/pkg?token=${ sensitiveFixture } \u001b[2K` ,
164+ } ,
165+ {
166+ status : "timed_out" as const ,
167+ error : undefined ,
168+ } ,
169+ ] ) ( "formats a sanitized actionable $status failure for required Codex" , async ( failure ) => {
170+ mocks . ensureOnboardingPluginInstalled . mockResolvedValueOnce ( {
171+ cfg : { } ,
172+ installed : false ,
173+ pluginId : "codex" ,
174+ status : failure . status ,
175+ ...( failure . error ? { error : failure . error } : { } ) ,
176+ } ) ;
177+ const { ensureCodexRuntimePluginForModelSelection } =
178+ await import ( "./codex-runtime-plugin-install.js" ) ;
179+
180+ const result = await ensureCodexRuntimePluginForModelSelection ( {
181+ cfg : { } ,
182+ model : "openai/gpt-5.5" ,
183+ prompter : { } as never ,
184+ runtime : { } as never ,
185+ } ) ;
186+
187+ expect ( result . ok ) . toBe ( false ) ;
188+ if ( result . ok ) {
189+ throw new Error ( "expected required runtime failure" ) ;
190+ }
191+ expect ( result . message ) . toContain ( `Codex runtime is required but unavailable` ) ;
192+ expect ( result . message ) . toContain ( `status: ${ failure . status } ` ) ;
193+ expect ( result . message ) . toContain ( "Retry setup" ) ;
194+ expect ( result . message ) . toContain ( "npm" ) ;
195+ expect ( result . message ) . toContain ( "registry" ) ;
196+ expect ( result . message ) . not . toContain ( sensitiveFixture ) ;
197+ expect ( result . message ) . not . toContain ( "\u001b" ) ;
198+ expect ( result ) . not . toHaveProperty ( "cfg" ) ;
199+ } ) ;
200+
201+ it ( "keeps an optional Codex runtime selection as a successful no-op" , async ( ) => {
202+ const { ensureCodexRuntimePluginForModelSelection } =
203+ await import ( "./codex-runtime-plugin-install.js" ) ;
204+
205+ const result = await ensureCodexRuntimePluginForModelSelection ( {
206+ cfg : { } ,
207+ model : "anthropic/claude-sonnet-4-6" ,
208+ prompter : { } as never ,
209+ runtime : { } as never ,
210+ } ) ;
211+
212+ expect ( result ) . toEqual ( {
213+ ok : true ,
214+ cfg : { } ,
215+ required : false ,
216+ } ) ;
217+ expect ( mocks . ensureOnboardingPluginInstalled ) . not . toHaveBeenCalled ( ) ;
218+ } ) ;
219+
160220 it ( "allows source checkouts to use the matching bundled Codex plugin" , async ( ) => {
161221 const { ensureCodexRuntimePluginForModelSelection } =
162222 await import ( "./codex-runtime-plugin-install.js" ) ;
@@ -214,9 +274,128 @@ describe("Codex runtime plugin install repair", () => {
214274 } ) ;
215275
216276 expect ( result ) . toMatchObject ( {
277+ ok : true ,
217278 required : true ,
279+ } ) ;
280+ } ) ;
281+
282+ it ( "stops the aggregate after a required Codex failure with no config result" , async ( ) => {
283+ mocks . ensureOnboardingPluginInstalled . mockResolvedValueOnce ( {
284+ cfg : { plugins : { entries : { codex : { enabled : false } } } } ,
285+ installed : false ,
286+ pluginId : "codex" ,
287+ status : "failed" ,
288+ error : "registry unavailable" ,
289+ } ) ;
290+ const { ensureModelSelectionRuntimePlugins } = await import ( "./runtime-plugin-install.js" ) ;
291+
292+ const result = await ensureModelSelectionRuntimePlugins ( {
293+ cfg : { } ,
294+ model : "openai/gpt-5.5" ,
295+ prompter : { } as never ,
296+ runtime : { } as never ,
297+ } ) ;
298+
299+ expect ( result ) . toEqual ( {
300+ ok : false ,
301+ message : expect . stringContaining ( "registry unavailable" ) ,
302+ } ) ;
303+ expect ( result ) . not . toHaveProperty ( "cfg" ) ;
304+ expect ( mocks . ensureOnboardingPluginInstalled ) . toHaveBeenCalledOnce ( ) ;
305+ } ) ;
306+
307+ it ( "evaluates Copilot after optional Codex and returns the closed success shape" , async ( ) => {
308+ const installedConfig = { plugins : { entries : { copilot : { enabled : true } } } } ;
309+ mocks . ensureOnboardingPluginInstalled . mockResolvedValueOnce ( {
310+ cfg : installedConfig ,
218311 installed : true ,
312+ pluginId : "copilot" ,
219313 status : "installed" ,
220314 } ) ;
315+ const { ensureModelSelectionRuntimePlugins } = await import ( "./runtime-plugin-install.js" ) ;
316+
317+ const result = await ensureModelSelectionRuntimePlugins ( {
318+ cfg : {
319+ models : {
320+ providers : {
321+ "github-copilot" : {
322+ baseUrl : "https://api.githubcopilot.com" ,
323+ models : [ ] ,
324+ agentRuntime : { id : "copilot" } ,
325+ } ,
326+ } ,
327+ } ,
328+ } ,
329+ model : "github-copilot/gpt-5.5" ,
330+ prompter : { } as never ,
331+ runtime : { } as never ,
332+ } ) ;
333+
334+ expect ( result ) . toEqual ( { ok : true , cfg : installedConfig , codexInstalled : false } ) ;
335+ expect ( mocks . ensureOnboardingPluginInstalled ) . toHaveBeenCalledOnce ( ) ;
336+ expect ( mocks . ensureOnboardingPluginInstalled ) . toHaveBeenCalledWith (
337+ expect . objectContaining ( { entry : expect . objectContaining ( { pluginId : "copilot" } ) } ) ,
338+ ) ;
339+ } ) ;
340+
341+ it ( "silences installer output and rejects prompts in non-interactive mode" , async ( ) => {
342+ const note = vi . fn ( async ( ) => { } ) ;
343+ const log = vi . fn ( ) ;
344+ const error = vi . fn ( ) ;
345+ mocks . ensureOnboardingPluginInstalled . mockImplementationOnce ( async ( params ) => {
346+ await params . prompter . note ( "installer note" ) ;
347+ params . prompter . progress ( "installing" ) . update ( "downloading" ) ;
348+ params . runtime . log ( "installer log" ) ;
349+ params . runtime . error ( "installer error" ) ;
350+ await expect ( params . prompter . confirm ( { message : "fallback?" } ) ) . rejects . toThrow (
351+ "Runtime plugin install unexpectedly prompted" ,
352+ ) ;
353+ return {
354+ cfg : { } ,
355+ installed : false ,
356+ pluginId : "codex" ,
357+ status : "timed_out" ,
358+ } ;
359+ } ) ;
360+ const { ensureModelSelectionRuntimePlugins } = await import ( "./runtime-plugin-install.js" ) ;
361+
362+ await ensureModelSelectionRuntimePlugins ( {
363+ cfg : { } ,
364+ model : "openai/gpt-5.5" ,
365+ prompter : { note } as never ,
366+ runtime : { log, error, exit : vi . fn ( ) } ,
367+ output : "silent" ,
368+ } ) ;
369+
370+ expect ( note ) . not . toHaveBeenCalled ( ) ;
371+ expect ( log ) . not . toHaveBeenCalled ( ) ;
372+ expect ( error ) . not . toHaveBeenCalled ( ) ;
373+ } ) ;
374+
375+ it ( "suppresses installer terminal failure presentation in interactive mode" , async ( ) => {
376+ const note = vi . fn ( async ( ) => { } ) ;
377+ const error = vi . fn ( ) ;
378+ mocks . ensureOnboardingPluginInstalled . mockImplementationOnce ( async ( params ) => {
379+ await params . prompter . note ( "installer failure" ) ;
380+ params . runtime . error ( "installer failure" ) ;
381+ return {
382+ cfg : { } ,
383+ installed : false ,
384+ pluginId : "codex" ,
385+ status : "failed" ,
386+ } ;
387+ } ) ;
388+ const { ensureCodexRuntimePluginForModelSelection } =
389+ await import ( "./codex-runtime-plugin-install.js" ) ;
390+
391+ await ensureCodexRuntimePluginForModelSelection ( {
392+ cfg : { } ,
393+ model : "openai/gpt-5.5" ,
394+ prompter : { note } as never ,
395+ runtime : { log : vi . fn ( ) , error, exit : vi . fn ( ) } ,
396+ } ) ;
397+
398+ expect ( note ) . not . toHaveBeenCalled ( ) ;
399+ expect ( error ) . not . toHaveBeenCalled ( ) ;
221400 } ) ;
222401} ) ;
0 commit comments