@@ -58,9 +58,16 @@ describe("LRUIdempotencyKeyCatalog", () => {
5858 expect ( catalog . getKeyOptions ( "hash2" ) ) . toBeDefined ( ) ;
5959 expect ( catalog . getKeyOptions ( "hash3" ) ) . toBeDefined ( ) ;
6060
61- // Add a fourth - hash1 should be evicted (it was least recently used after the gets above moved others)
62- // Note: After the gets above, the order is hash1, hash2, hash3 (hash1 was accessed first in the gets)
63- // Actually let's reset and test more carefully
61+ // After the gets above, the LRU order from oldest to newest is: hash1, hash2, hash3
62+ // (each get moves the key to the most recent position)
63+
64+ // Add a fourth - hash1 should be evicted (it was accessed first, so it's the oldest)
65+ catalog . registerKeyOptions ( "hash4" , { key : "key4" , scope : "global" } ) ;
66+
67+ expect ( catalog . getKeyOptions ( "hash1" ) ) . toBeUndefined ( ) ;
68+ expect ( catalog . getKeyOptions ( "hash2" ) ) . toBeDefined ( ) ;
69+ expect ( catalog . getKeyOptions ( "hash3" ) ) . toBeDefined ( ) ;
70+ expect ( catalog . getKeyOptions ( "hash4" ) ) . toBeDefined ( ) ;
6471 } ) ;
6572
6673 it ( "should evict least recently registered entry when capacity exceeded" , ( ) => {
@@ -178,4 +185,25 @@ describe("LRUIdempotencyKeyCatalog", () => {
178185 expect ( catalog . getKeyOptions ( "hash1000" ) ) . toBeDefined ( ) ;
179186 } ) ;
180187 } ) ;
188+
189+ describe ( "edge cases" , ( ) => {
190+ it ( "should handle negative maxSize by clamping to 0" , ( ) => {
191+ const catalog = new LRUIdempotencyKeyCatalog ( - 5 ) ;
192+
193+ // With maxSize clamped to 0, nothing should be stored
194+ catalog . registerKeyOptions ( "hash1" , { key : "key1" , scope : "global" } ) ;
195+
196+ // Should be immediately evicted since maxSize is 0
197+ expect ( catalog . getKeyOptions ( "hash1" ) ) . toBeUndefined ( ) ;
198+ } ) ;
199+
200+ it ( "should handle maxSize of 0" , ( ) => {
201+ const catalog = new LRUIdempotencyKeyCatalog ( 0 ) ;
202+
203+ catalog . registerKeyOptions ( "hash1" , { key : "key1" , scope : "global" } ) ;
204+
205+ // Should be immediately evicted since maxSize is 0
206+ expect ( catalog . getKeyOptions ( "hash1" ) ) . toBeUndefined ( ) ;
207+ } ) ;
208+ } ) ;
181209} ) ;
0 commit comments