@@ -23,7 +23,7 @@ SOFTWARE.
2323import { describe , expect , it } from 'vitest'
2424
2525import { createTestFunction } from './utils/test-helpers.mjs'
26- import { LOOP_SENTINEL } from '../src/constants.js'
26+ // import { LOOP_SENTINEL } from '../src/constants.js' -- No longer needed after optimization
2727import {
2828 encodeComponent ,
2929 encodeNamespace ,
@@ -1158,15 +1158,28 @@ describe('Edge cases and additional coverage', () => {
11581158
11591159 // Test recursiveFreeze infinite loop detection
11601160 it ( 'should detect infinite loops in recursiveFreeze' , ( ) => {
1161- // Create a large array to trigger loop detection
1162- const obj = { arr : [ ] }
1163- // Add exactly LOOP_SENTINEL items to trigger the check
1164- for ( let i = 0 ; i < LOOP_SENTINEL ; i ++ ) {
1165- ; ( obj . arr as any ) . push ( { value : i } )
1161+ // Create a structure that will exceed LOOP_SENTINEL when traversed
1162+ // Use nested objects to reach the limit more efficiently
1163+ const createDeepStructure = ( ) => {
1164+ const depth = 1000
1165+ // depth * width > 1,000,000 (LOOP_SENTINEL)
1166+ const width = 1001
1167+ const root : any = { children : [ ] }
1168+
1169+ for ( let i = 0 ; i < width ; i ++ ) {
1170+ let current = root
1171+ for ( let j = 0 ; j < depth ; j ++ ) {
1172+ const child = { value : `${ i } -${ j } ` , children : [ ] }
1173+ current . children . push ( child )
1174+ current = child
1175+ }
1176+ }
1177+ return root
11661178 }
11671179
1180+ const largeGraph = createDeepStructure ( )
11681181 // This should throw when hitting the sentinel
1169- expect ( ( ) => recursiveFreeze ( obj ) ) . toThrow ( / O b j e c t g r a p h t o o l a r g e / )
1182+ expect ( ( ) => recursiveFreeze ( largeGraph ) ) . toThrow ( / O b j e c t g r a p h t o o l a r g e / )
11701183 } )
11711184
11721185 // Test purl-component functions
0 commit comments