@@ -277,11 +277,60 @@ describe("runIsolatedCompletion", () => {
277277 } ) ;
278278 } ) ;
279279
280+ it . each ( [ "error" , "aborted" ] as const ) (
281+ "rejects %s harness output before usage reaches the runtime finalizer" ,
282+ async ( stopReason ) => {
283+ mocks . getRegisteredAgentHarness . mockReturnValue ( {
284+ harness : {
285+ id : "codex" ,
286+ label : "Codex" ,
287+ supports : ( ) => ( { supported : true } ) ,
288+ runAttempt : vi . fn ( ) ,
289+ runIsolatedCompletion : vi . fn ( async ( ) => ( {
290+ assistant : assistant ( [ { type : "text" , text : "partial" } ] , stopReason ) ,
291+ } ) ) ,
292+ } satisfies AgentHarness ,
293+ } ) ;
294+
295+ await expect ( runIsolatedCompletion ( request ( ) ) ) . rejects . toMatchObject ( {
296+ code : "output-rejected" ,
297+ message : expect . stringContaining ( `stop reason ${ stopReason } ` ) ,
298+ } ) ;
299+ } ,
300+ ) ;
301+
302+ it ( "rejects thinking-only harness output before usage reaches the runtime finalizer" , async ( ) => {
303+ mocks . getRegisteredAgentHarness . mockReturnValue ( {
304+ harness : {
305+ id : "codex" ,
306+ label : "Codex" ,
307+ supports : ( ) => ( { supported : true } ) ,
308+ runAttempt : vi . fn ( ) ,
309+ runIsolatedCompletion : vi . fn ( async ( ) => ( {
310+ assistant : assistant ( [ { type : "thinking" , thinking : "hidden" } ] ) ,
311+ } ) ) ,
312+ } satisfies AgentHarness ,
313+ } ) ;
314+
315+ await expect ( runIsolatedCompletion ( request ( ) ) ) . rejects . toMatchObject ( {
316+ code : "output-rejected" ,
317+ message : expect . stringContaining ( "empty output" ) ,
318+ } ) ;
319+ } ) ;
320+
280321 it ( "routes CLI owners through one exact empty-tool run without direct preparation" , async ( ) => {
281322 mocks . isCliRuntimeAliasForProvider . mockReturnValue ( true ) ;
282323 mocks . runCliAgent . mockResolvedValue ( {
283324 payloads : [ { text : '{"cli":true}' } ] ,
284- meta : { durationMs : 1 } ,
325+ meta : {
326+ durationMs : 1 ,
327+ agentMeta : {
328+ sessionId : "cli-session" ,
329+ provider : "claude-cli" ,
330+ model : "claude-test" ,
331+ usage : { input : 8 , output : 3 , cacheRead : 2 , total : 13 } ,
332+ } ,
333+ } ,
285334 } ) ;
286335
287336 await expect (
@@ -296,6 +345,7 @@ describe("runIsolatedCompletion", () => {
296345 provider : "anthropic" ,
297346 model : "claude-test" ,
298347 owner : { kind : "cli" , id : "claude-cli" } ,
348+ usage : { input : 8 , output : 3 , cacheRead : 2 , total : 13 } ,
299349 } ) ;
300350 expect ( mocks . prepareSimpleCompletionModel ) . not . toHaveBeenCalled ( ) ;
301351 expect ( mocks . runCliAgent ) . toHaveBeenCalledWith (
@@ -311,6 +361,30 @@ describe("runIsolatedCompletion", () => {
311361 ) ;
312362 } ) ;
313363
364+ it ( "keeps unavailable CLI usage absent" , async ( ) => {
365+ mocks . isCliRuntimeAliasForProvider . mockReturnValue ( true ) ;
366+ mocks . runCliAgent . mockResolvedValue ( {
367+ payloads : [ { text : "done" } ] ,
368+ meta : {
369+ durationMs : 1 ,
370+ agentMeta : {
371+ sessionId : "cli-session" ,
372+ provider : "claude-cli" ,
373+ model : "claude-test" ,
374+ } ,
375+ } ,
376+ } ) ;
377+
378+ const result = await runIsolatedCompletion ( {
379+ ...request ( ) ,
380+ provider : "anthropic" ,
381+ model : "claude-test" ,
382+ agentHarnessRuntimeOverride : "claude-cli" ,
383+ } ) ;
384+
385+ expect ( result ) . not . toHaveProperty ( "usage" ) ;
386+ } ) ;
387+
314388 it ( "forwards one explicit auth profile unchanged to a CLI owner" , async ( ) => {
315389 mocks . isCliRuntimeAliasForProvider . mockReturnValue ( true ) ;
316390 mocks . runCliAgent . mockResolvedValue ( { payloads : [ { text : "done" } ] } ) ;
0 commit comments