@@ -497,40 +497,25 @@ describe("background run_shell (shellGuardPlugin)", () => {
497497} ) ;
498498
499499describe ( "advertiseShellGuardTimeout" , ( ) => {
500- test ( "rewrites run_shell timeout description when a settings default is set" , ( ) => {
501- const rewritten = advertiseShellGuardTimeout (
502- {
503- name : "run_shell" ,
504- description : "Execute a shell command" ,
505- inputSchema : {
506- type : "object" ,
507- properties : {
508- command : { type : "string" } ,
509- timeout : {
510- type : "number" ,
511- description : "Timeout in milliseconds (default: 30000)" ,
512- } ,
513- } ,
514- required : [ "command" ] ,
515- } ,
516- } ,
517- 120_000 ,
518- ) ;
519- const timeout = (
520- rewritten . inputSchema [ "properties" ] as Record <
521- string ,
522- { description : string }
523- >
524- ) [ "timeout" ] ;
525- expect ( timeout ?. description ) . toContain ( "120000" ) ;
526- expect ( timeout ?. description ) . not . toContain ( "30000" ) ;
527- expect ( ( timeout as { default ?: number } | undefined ) ?. default ) . toBe (
528- 120_000 ,
529- ) ;
530- } ) ;
500+ function timeoutSchema ( def : {
501+ inputSchema : { properties ?: unknown } ;
502+ } ) : { description ?: string ; default ?: number } | undefined {
503+ const properties = def . inputSchema [ "properties" ] as
504+ | Record < string , { description ?: string ; default ?: number } >
505+ | undefined ;
506+ return properties ?. [ "timeout" ] ;
507+ }
531508
532- test ( "advertises default 120000 when settings default is unset" , ( ) => {
533- const rewritten = advertiseShellGuardTimeout ( {
509+ function runShellDef ( ) : {
510+ name : string ;
511+ description : string ;
512+ inputSchema : {
513+ type : "object" ;
514+ properties : Record < string , { type : string ; description ?: string } > ;
515+ required : string [ ] ;
516+ } ;
517+ } {
518+ return {
534519 name : "run_shell" ,
535520 description : "Execute a shell command" ,
536521 inputSchema : {
@@ -544,18 +529,48 @@ describe("advertiseShellGuardTimeout", () => {
544529 } ,
545530 required : [ "command" ] ,
546531 } ,
547- } ) ;
548- const timeout = (
549- rewritten . inputSchema [ "properties" ] as Record <
550- string ,
551- { description : string ; default ?: number }
552- >
553- ) [ "timeout" ] ;
554- expect ( timeout ?. description ) . toContain ( "120000" ) ;
532+ } ;
533+ }
534+
535+ test ( "rewrites run_shell timeout description when a settings default is set" , ( ) => {
536+ const rewritten = advertiseShellGuardTimeout ( runShellDef ( ) , 120_000 ) ;
537+ const timeout = timeoutSchema ( rewritten ) ;
538+ expect ( timeout ?. description ) . toContain ( "foreground default: 120000" ) ;
539+ expect ( timeout ?. description ) . toMatch (
540+ / o m i t o n b a c k g r o u n d : t r u e f o r n o t i m e o u t / ,
541+ ) ;
542+ expect ( timeout ?. description ) . not . toContain ( "30000" ) ;
543+ expect ( timeout ?. default ) . toBe ( 120_000 ) ;
544+ } ) ;
545+
546+ test ( "advertises default 120000 when settings default is unset" , ( ) => {
547+ const rewritten = advertiseShellGuardTimeout ( runShellDef ( ) ) ;
548+ const timeout = timeoutSchema ( rewritten ) ;
549+ expect ( timeout ?. description ) . toContain ( "foreground default: 120000" ) ;
555550 expect ( timeout ?. default ) . toBe ( 120_000 ) ;
556551 expect ( timeout ?. description ) . not . toContain ( "30000" ) ;
557552 expect ( timeout ?. description ) . not . toContain ( "15000" ) ;
558- expect ( timeout ?. description ) . not . toMatch ( / n o d e f a u l t | o m i t / i) ;
553+ expect ( timeout ?. description ) . toMatch (
554+ / o m i t o n b a c k g r o u n d : t r u e f o r n o t i m e o u t / ,
555+ ) ;
556+ } ) ;
557+
558+ test ( "advertised default matches resolver when only maxTimeoutMs is set" , ( ) => {
559+ const maxMs = 60_000 ;
560+ const resolved = resolveShellTimeoutMs ( {
561+ requested : undefined ,
562+ background : false ,
563+ maxMs,
564+ } ) ;
565+ const rewritten = advertiseShellGuardTimeout (
566+ runShellDef ( ) ,
567+ undefined ,
568+ maxMs ,
569+ ) ;
570+ const timeout = timeoutSchema ( rewritten ) ;
571+ expect ( resolved ) . toBe ( 60_000 ) ;
572+ expect ( timeout ?. default ) . toBe ( resolved ) ;
573+ expect ( timeout ?. description ) . toContain ( `foreground default: ${ resolved } ` ) ;
559574 } ) ;
560575
561576 test ( "leaves other tools unchanged" , ( ) => {
@@ -585,6 +600,7 @@ describe("advertiseShellGuardTimeout", () => {
585600 ) [ "background" ] ;
586601 expect ( background ) . toBeDefined ( ) ;
587602 expect ( background ?. description ) . toContain ( "shell_collect" ) ;
603+ expect ( background ?. description ) . toMatch ( / o m i t t i m e o u t / i) ;
588604 expect ( background ?. description ) . toMatch (
589605 / d o e s n o t c h a n g e t h e r e t a i n e d s h e l l c w d / i,
590606 ) ;
0 commit comments