11import { act , cloneElement , type ReactElement , type ReactNode } from "react" ;
2- import { create , type ReactTestRenderer } from "react-test-renderer" ;
3- import { EnvironmentId , ThreadId , type OrchestrationV2ContextTransfer } from "@t3tools/contracts" ;
2+ import { create , type ReactTestInstance , type ReactTestRenderer } from "react-test-renderer" ;
3+ import {
4+ EnvironmentId ,
5+ ThreadId ,
6+ type ModelSelection ,
7+ type ProviderOptionDescriptor ,
8+ type OrchestrationV2ContextTransfer ,
9+ } from "@t3tools/contracts" ;
410import * as DateTime from "effect/DateTime" ;
511import { afterEach , expect , it , vi } from "vite-plus/test" ;
612
@@ -196,7 +202,11 @@ it("shows readable models and only differing workspace details in agent tooltips
196202 worktreePath : null as string | null ,
197203 branch : null as string | null ,
198204 title : "Worker" ,
199- modelSelection : { instanceId : "codex" , model : "gpt-5.4" } ,
205+ modelSelection : {
206+ instanceId : "codex" ,
207+ model : "gpt-5.4" ,
208+ options : [ { id : "reasoningEffort" , value : "high" } ] as ModelSelection [ "options" ] ,
209+ } ,
200210 lineage : { parentThreadId : "parent" , relationshipToParent : "subagent" } ,
201211 } ;
202212 state . projects = [
@@ -231,6 +241,7 @@ it("shows readable models and only differing workspace details in agent tooltips
231241 {
232242 id : "agent" ,
233243 childThreadId : "child" ,
244+ origin : "app_owned" ,
234245 driver : "codex" ,
235246 providerInstanceId : "codex" ,
236247 title : "Worker" ,
@@ -253,12 +264,24 @@ it("shows readable models and only differing workspace details in agent tooltips
253264 await act ( async ( ) => {
254265 renderer = create ( panel ) ;
255266 } ) ;
256- const text = ( ) =>
257- renderer . root
258- . findAll ( ( node ) => typeof node . type === "string" )
259- . flatMap ( ( node ) => node . children . filter ( ( child ) => typeof child === "string" ) )
260- . join ( "" ) ;
267+ const text = ( visibleOnly = false ) => {
268+ const read = ( node : ReactTestInstance | string ) : string => {
269+ if ( typeof node === "string" ) return node ;
270+ if ( visibleOnly && node . props . className === "sr-only" ) return "" ;
271+ return node . children . map ( read ) . join ( "" ) ;
272+ } ;
273+ return read ( renderer . root ) ;
274+ } ;
275+ expect ( text ( ) ) . toContain ( "My GPT · high" ) ;
276+ state . projection = {
277+ ...projection ,
278+ subagents : [ { ...projection . subagents [ 0 ] , origin : "provider_native" } ] ,
279+ } ;
280+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
261281 expect ( text ( ) ) . toContain ( "My GPT" ) ;
282+ expect ( text ( ) ) . not . toContain ( "My GPT · high" ) ;
283+ state . projection = projection ;
284+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
262285 expect ( text ( ) ) . not . toContain ( "Tokens" ) ;
263286 expect ( text ( ) ) . not . toContain ( "Open subagent" ) ;
264287 expect ( text ( ) ) . not . toContain ( "Project" ) ;
@@ -279,6 +302,11 @@ it("shows readable models and only differing workspace details in agent tooltips
279302 } ;
280303 await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
281304 expect ( text ( ) ) . toContain ( expected ) ;
305+ if ( ! model ?. trim ( ) || model === "gpt-5.5" || model === "custom/model-v1" ) {
306+ expect ( text ( ) ) . not . toContain ( " · high" ) ;
307+ } else {
308+ expect ( text ( ) ) . toContain ( `${ expected } · high` ) ;
309+ }
282310 expect ( text ( ) ) . not . toContain ( "Unknown" ) ;
283311 if ( ! model ?. trim ( ) ) expect ( text ( ) ) . not . toContain ( "My GPT" ) ;
284312 }
@@ -302,6 +330,179 @@ it("shows readable models and only differing workspace details in agent tooltips
302330 expect ( text ( ) ) . not . toContain ( "My GPT" ) ;
303331 }
304332
333+ state . projection = projection ;
334+ for ( const [ options , expected ] of [
335+ [ [ { id : "effort" , value : "max" } ] , " · max" ] ,
336+ [ [ { id : "reasoning" , value : "low" } ] , " · low" ] ,
337+ [ [ { id : "variant" , value : "high" } ] , " · high" ] ,
338+ [ [ { id : "reasoningEffort" , value : "none" } ] , " · none" ] ,
339+ [ [ { id : "reasoningEffort" , value : true } ] , "" ] ,
340+ [ [ { id : "serviceTier" , value : "fast" } ] , "" ] ,
341+ [ [ ] , "" ] ,
342+ [ undefined , "" ] ,
343+ ] as const ) {
344+ child . modelSelection . options = options ;
345+ state . shells = [ { environmentId : "test" , source : { ...child } } ] ;
346+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
347+ expect ( text ( ) ) . toContain ( `My GPT${ expected } ` ) ;
348+ if ( ! expected ) expect ( text ( ) ) . not . toContain ( "My GPT ·" ) ;
349+ }
350+ const speedConfig = state . configs . get ( "test" ) ;
351+ const serviceTier : ProviderOptionDescriptor = {
352+ id : "serviceTier" ,
353+ label : "Service Tier" ,
354+ type : "select" ,
355+ currentValue : "priority" ,
356+ options : [
357+ { id : "default" , label : "Standard" , isDefault : true } ,
358+ { id : "priority" , label : "Fast" } ,
359+ { id : "ultrafast" , label : "Ultrafast" } ,
360+ { id : "flex" , label : "Flex" } ,
361+ ] ,
362+ } ;
363+ const fastMode : ProviderOptionDescriptor = {
364+ id : "fastMode" ,
365+ label : "Fast Mode" ,
366+ type : "boolean" ,
367+ currentValue : true ,
368+ } ;
369+ for ( const [ driver , descriptor , value , iconLabel ] of [
370+ [ "codex" , serviceTier , "default" , "" ] ,
371+ [ "codex" , serviceTier , "priority" , "Fast mode on" ] ,
372+ [ "codex" , serviceTier , "ultrafast" , "Ultrafast mode on" ] ,
373+ [ "codex" , serviceTier , "flex" , "" ] ,
374+ [ "codex" , serviceTier , "unknown" , "" ] ,
375+ [
376+ "codex" ,
377+ { ...serviceTier , options : serviceTier . options . filter ( ( { id } ) => id !== "ultrafast" ) } ,
378+ "ultrafast" ,
379+ "" ,
380+ ] ,
381+ [ "codex" , serviceTier , true , "" ] ,
382+ [ "codex" , serviceTier , undefined , "" ] ,
383+ [ "claudeAgent" , fastMode , true , "Fast mode on" ] ,
384+ [ "claudeAgent" , fastMode , false , "" ] ,
385+ [ "cursor" , fastMode , true , "Fast mode on" ] ,
386+ [ "cursor" , fastMode , false , "" ] ,
387+ [ "opencode" , fastMode , true , "Fast mode on" ] ,
388+ [ "cursor" , fastMode , "true" , "" ] ,
389+ [ "cursor" , serviceTier , "priority" , "" ] ,
390+ ] as const ) {
391+ state . configs . set ( "test" , {
392+ providers : [
393+ {
394+ instanceId : "codex" ,
395+ driver,
396+ models : [
397+ {
398+ slug : "gpt-5.4" ,
399+ name : "My GPT" ,
400+ capabilities : { optionDescriptors : [ descriptor ] } ,
401+ } ,
402+ ] ,
403+ } ,
404+ ] ,
405+ } ) ;
406+ child . modelSelection . options = [
407+ { id : "reasoningEffort" , value : "high" } ,
408+ ...( value === undefined ? [ ] : [ { id : descriptor . id , value } ] ) ,
409+ ] ;
410+ state . shells = [ { environmentId : "test" , source : { ...child } } ] ;
411+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
412+ expect ( text ( true ) ) . toContain ( "My GPT · high" ) ;
413+ expect ( text ( true ) ) . not . toMatch ( / F a s t | U l t r a f a s t | N o r m a l | S t a n d a r d | F l e x / ) ;
414+ expect ( text ( ) ) . toContain ( `My GPT · ${ iconLabel } high` ) ;
415+ if ( ! iconLabel ) expect ( text ( ) ) . not . toContain ( "mode on" ) ;
416+ child . modelSelection . options = child . modelSelection . options . filter (
417+ ( { id } ) => id !== "reasoningEffort" ,
418+ ) ;
419+ state . shells = [ { environmentId : "test" , source : { ...child } } ] ;
420+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
421+ expect ( text ( ) ) . not . toContain ( " · high" ) ;
422+ expect ( text ( true ) ) . not . toMatch ( / F a s t | U l t r a f a s t | N o r m a l | S t a n d a r d | F l e x / ) ;
423+ if ( iconLabel ) expect ( text ( ) ) . toContain ( iconLabel ) ;
424+ else expect ( text ( ) ) . not . toContain ( "mode on" ) ;
425+ state . projection = {
426+ ...projection ,
427+ subagents : [ { ...projection . subagents [ 0 ] , origin : "provider_native" } ] ,
428+ } ;
429+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
430+ expect ( text ( ) ) . not . toMatch ( / F a s t | U l t r a f a s t | N o r m a l | S t a n d a r d | F l e x | · h i g h / ) ;
431+ state . projection = projection ;
432+ for ( const modelSelection of [
433+ { ...child . modelSelection , instanceId : "other" } ,
434+ { ...child . modelSelection , model : "gpt-5.5" } ,
435+ ] ) {
436+ state . shells = [ { environmentId : "test" , source : { ...child , modelSelection } } ] ;
437+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
438+ expect ( text ( ) ) . not . toMatch ( / F a s t | U l t r a f a s t | N o r m a l | S t a n d a r d | F l e x | · h i g h / ) ;
439+ }
440+ }
441+ state . configs . set ( "test" , {
442+ providers : [
443+ {
444+ instanceId : "codex" ,
445+ driver : "codex" ,
446+ displayName : "Work account" ,
447+ models : [
448+ {
449+ slug : "gpt-5.4" ,
450+ name : "My GPT" ,
451+ capabilities : { optionDescriptors : [ serviceTier ] } ,
452+ } ,
453+ ] ,
454+ } ,
455+ {
456+ instanceId : "codex_personal" ,
457+ driver : "codex" ,
458+ displayName : "Personal account" ,
459+ models : [ ] ,
460+ } ,
461+ ] ,
462+ } ) ;
463+ child . modelSelection . options = [
464+ { id : "reasoningEffort" , value : "high" } ,
465+ { id : "serviceTier" , value : "priority" } ,
466+ ] ;
467+ state . shells = [ { environmentId : "test" , source : { ...child } } ] ;
468+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
469+ expect ( text ( true ) ) . toContain ( "My GPT · Work account · high" ) ;
470+ expect ( text ( ) ) . toContain ( "My GPT · Work account · Fast mode onhigh" ) ;
471+ expect ( text ( ) ) . not . toContain ( "Personal account" ) ;
472+ state . configs . set ( "test" , speedConfig ) ;
473+ child . modelSelection . options = [ { id : "reasoningEffort" , value : "high" } ] ;
474+ state . shells = [
475+ {
476+ environmentId : "test" ,
477+ source : { ...child , modelSelection : { ...child . modelSelection , instanceId : "other" } } ,
478+ } ,
479+ ] ;
480+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
481+ expect ( text ( ) ) . not . toContain ( "My GPT ·" ) ;
482+ const config = state . configs . get ( "test" ) ;
483+ state . configs . clear ( ) ;
484+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
485+ expect ( text ( ) ) . toContain ( "GPT-5.4" ) ;
486+ expect ( text ( ) ) . not . toContain ( "GPT-5.4 ·" ) ;
487+ state . shells = [ { environmentId : "test" , source : { ...child } } ] ;
488+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
489+ expect ( text ( ) ) . toContain ( "GPT-5.4 · high" ) ;
490+ state . configs . set ( "test" , config ) ;
491+ for ( const model of [ "custom/model-v1" , "custom/model-v2" ] ) {
492+ state . projection = {
493+ ...projection ,
494+ subagents : [ { ...projection . subagents [ 0 ] , model } ] ,
495+ } ;
496+ state . shells = [
497+ {
498+ environmentId : "test" ,
499+ source : { ...child , modelSelection : { ...child . modelSelection , model : "custom/model-v1" } } ,
500+ } ,
501+ ] ;
502+ await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
503+ expect ( text ( ) . includes ( `${ model } · high` ) ) . toBe ( model === "custom/model-v1" ) ;
504+ }
505+
305506 state . projection = {
306507 ...projection ,
307508 subagents : [
@@ -364,6 +565,7 @@ it("shows readable models and only differing workspace details in agent tooltips
364565 state . configs . clear ( ) ;
365566 await act ( async ( ) => renderer . update ( cloneElement ( panel ) ) ) ;
366567 expect ( text ( ) ) . toContain ( "GPT-5.4" ) ;
568+ expect ( text ( ) ) . not . toContain ( "GPT-5.4 ·" ) ;
367569 expect ( text ( ) ) . not . toContain ( "gpt-5.4" ) ;
368570 expect ( text ( ) ) . not . toContain ( "Project" ) ;
369571 expect ( text ( ) ) . not . toContain ( "Workspace" ) ;
0 commit comments