import {test,expect,vi} from 'vitest'
import {types} from 'node:util'
function shape(namespace) {
 return { nativeBrand: types.isModuleNamespaceObject(namespace), keys: Reflect.ownKeys(namespace).map(key => typeof key === 'symbol' ? String(key) : key), prototypeNull: Object.getPrototypeOf(namespace) === null, tag: namespace[Symbol.toStringTag] ?? null, extensible: Object.isExtensible(namespace), sealed: Object.isSealed(namespace), frozen: Object.isFrozen(namespace), descriptors: Reflect.ownKeys(namespace).map(key => { const d = Object.getOwnPropertyDescriptor(namespace,key); return { key: typeof key === 'symbol' ? String(key) : key, valueType: typeof d.value, get: typeof d.get, set: typeof d.set, writable: d.writable ?? null, enumerable: d.enumerable, configurable: d.configurable } }) }
}
test('holds complete nonleaf callable namespace/default/require identities across resets',async()=>{
 const first=await import('./root.cjs');const cached=await import('./root.cjs');vi.resetModules();const second=await import('./root.cjs');vi.resetModules();const third=await import('./root.cjs');const namespaces=[first,second,third];const roots=namespaces.map(value=>value.default);const dependencies=roots.map(value=>value.dependency);
 console.log('WS2_CJS_NONLEAF_CALLABLE:'+JSON.stringify({mode:'plain',cached:first===cached,namespaceIdentity:[first===second,second===third],rawIdentity:[roots[0]===roots[1],roots[1]===roots[2]],dependencyIdentity:[dependencies[0]===dependencies[1],dependencies[1]===dependencies[2]],evaluations:[globalThis.__ws2CallableRoot,globalThis.__ws2CallableDependency],reads:roots.map(value=>value('held')),namespaceShapes:namespaces.map(shape),rawShapes:roots.map(shape),dependencyShapes:dependencies.map(shape), }));expect(first).toBe(cached);expect(roots[0]).not.toBe(roots[1]);expect(dependencies[0]).toBe(dependencies[1])
})
