@@ -429,4 +429,72 @@ describe('logs routes', function () {
429429 expect ( JSON . parse ( state [ LOGS_KEY ] ) ) . to . deep . equal ( [ ] ) ;
430430 expect ( clearLogEntries ) . to . be . a ( 'function' ) ;
431431 } ) ;
432+
433+ it ( 'rejects negative logsMaxCount in settings PATCH' , async function ( ) {
434+ const app = createRouteApp ( ) ;
435+ registerSettingsRoutes ( app ) ;
436+ const patchHandler = app . handlers . get ( 'PATCH /api/settings' ) ;
437+
438+ const res = createResponse ( '/api/settings' ) ;
439+ await patchHandler ( { body : { logsMaxCount : - 1 } } , res ) ;
440+
441+ expect ( res . body . status ) . to . equal ( 'success' ) ;
442+ expect ( state [ SETTINGS_KEY ] ) . to . not . have . property ( 'logsMaxCount' ) ;
443+ } ) ;
444+
445+ it ( 'rejects NaN logsMaxCount in settings PATCH' , async function ( ) {
446+ const app = createRouteApp ( ) ;
447+ registerSettingsRoutes ( app ) ;
448+ const patchHandler = app . handlers . get ( 'PATCH /api/settings' ) ;
449+
450+ const res = createResponse ( '/api/settings' ) ;
451+ await patchHandler ( { body : { logsMaxCount : 'abc' } } , res ) ;
452+
453+ expect ( res . body . status ) . to . equal ( 'success' ) ;
454+ expect ( state [ SETTINGS_KEY ] ) . to . not . have . property ( 'logsMaxCount' ) ;
455+ } ) ;
456+
457+ it ( 'rejects null logsMaxCount in settings PATCH' , async function ( ) {
458+ const app = createRouteApp ( ) ;
459+ registerSettingsRoutes ( app ) ;
460+ const patchHandler = app . handlers . get ( 'PATCH /api/settings' ) ;
461+
462+ const res = createResponse ( '/api/settings' ) ;
463+ await patchHandler ( { body : { logsMaxCount : null } } , res ) ;
464+
465+ expect ( res . body . status ) . to . equal ( 'success' ) ;
466+ expect ( state [ SETTINGS_KEY ] ) . to . not . have . property ( 'logsMaxCount' ) ;
467+ } ) ;
468+
469+ it ( 'accepts valid positive integer logsMaxCount in settings PATCH' , async function ( ) {
470+ const app = createRouteApp ( ) ;
471+ registerSettingsRoutes ( app ) ;
472+ const patchHandler = app . handlers . get ( 'PATCH /api/settings' ) ;
473+
474+ const res = createResponse ( '/api/settings' ) ;
475+ await patchHandler ( { body : { logsMaxCount : 300 } } , res ) ;
476+
477+ expect ( res . body . status ) . to . equal ( 'success' ) ;
478+ expect ( state [ SETTINGS_KEY ] ) . to . deep . include ( { logsMaxCount : 300 } ) ;
479+ } ) ;
480+
481+ it ( 'clears log settings cache after settings PATCH so new logsMaxCount takes effect immediately' , async function ( ) {
482+ const app = createRouteApp ( ) ;
483+ registerSettingsRoutes ( app ) ;
484+ const patchHandler = app . handlers . get ( 'PATCH /api/settings' ) ;
485+
486+ state [ SETTINGS_KEY ] = { logsMaxCount : 500 } ;
487+ appendLogEntry ( $ , 'info' , [ 'before change' ] ) ;
488+ appendLogEntry ( $ , 'info' , [ 'before change 2' ] ) ;
489+ appendLogEntry ( $ , 'info' , [ 'before change 3' ] ) ;
490+
491+ await patchHandler ( { body : { logsMaxCount : 1 } } , createResponse ( '/api/settings' ) ) ;
492+
493+ appendLogEntry ( $ , 'info' , [ 'after change' ] ) ;
494+
495+ const storedLogs = JSON . parse ( state [ LOGS_KEY ] ) ;
496+ expect ( storedLogs ) . to . have . length ( 1 ) ;
497+ expect ( storedLogs [ 0 ] . message ) . to . equal ( '[unknown] INFO: after change' ) ;
498+ } ) ;
499+
432500} ) ;
0 commit comments