import {test,expect,vi} from 'vitest';
function val(v){return typeof v==='function'?{type:'function',name:v.name,length:v.length,tag:Object.prototype.toString.call(v),mock:vi.isMockFunction(v)}:v!==null&&typeof v==='object'?{type:'object',tag:Object.prototype.toString.call(v),keys:Reflect.ownKeys(v).map(String)}:{type:typeof v,value:v}}
function shape(v){if(v===null||(typeof v!=='object'&&typeof v!=='function'))return val(v);return {type:typeof v,tag:Object.prototype.toString.call(v),nullPrototype:Object.getPrototypeOf(v)===null,objectPrototype:Object.getPrototypeOf(v)===Object.prototype,functionPrototype:Object.getPrototypeOf(v)===Function.prototype,keys:Reflect.ownKeys(v).map(k=>typeof k==='symbol'?'symbol:'+String(k.description):k),descriptors:Reflect.ownKeys(v).map(k=>{const d=Object.getOwnPropertyDescriptor(v,k);return {key:typeof k==='symbol'?'symbol:'+String(k.description):k,value:val(d.value),get:typeof d.get,set:typeof d.set,writable:d.writable??null,enumerable:d.enumerable,configurable:d.configurable}}),prototype:typeof v==='function'&&Object.hasOwn(v,'prototype')?{keys:Reflect.ownKeys(v.prototype).map(String),descriptors:Reflect.ownKeys(v.prototype).map(k=>{const d=Object.getOwnPropertyDescriptor(v.prototype,k);return {key:String(k),value:val(d.value),get:typeof d.get,set:typeof d.set,writable:d.writable??null,enumerable:d.enumerable,configurable:d.configurable}})}:null}}
function observe(name,first,second){const fn=typeof first.default==='function'?first.default:first;const next=typeof second.default==='function'?second.default:second;const before={first:shape(first),default:shape(first.default),method:shape(fn.method),outerSame:first===second,defaultSame:first.default===second.default,methodSame:fn.method===next.method,namedMethodSame:first.method===fn.method,originalEvaluations:globalThis.__ws2CallableAutomaticCounts?.[name]??0};const result=fn(4);const member=fn.method();console.log('WS2_CALLABLE_AUTOMATIC:'+JSON.stringify({name,before,after:{result:val(result),member:val(member),calls:fn.mock.calls,memberCalls:fn.method.mock.calls,secondCalls:next.mock.calls,originalEvaluations:globalThis.__ws2CallableAutomaticCounts?.[name]??0}}));expect(vi.isMockFunction(fn)).toBe(true)}
test("complete named callable automatic-only namespace",async()=>{const first=await vi.importMock('./named.cjs');const second=await vi.importMock('./named.cjs');observe("named",first,second)});
test("complete anonymous callable automatic-only namespace",async()=>{const first=await vi.importMock('./anonymous.cjs');const second=await vi.importMock('./anonymous.cjs');observe("anonymous",first,second)});
test("complete arrow callable automatic-only namespace",async()=>{const first=await vi.importMock('./arrow.cjs');const second=await vi.importMock('./arrow.cjs');observe("arrow",first,second)});
test("complete class callable automatic-only namespace",async()=>{const first=await vi.importMock('./class.cjs');const second=await vi.importMock('./class.cjs');observe("class",first,second)});
test("complete bound callable automatic-only namespace",async()=>{const first=await vi.importMock('./bound.cjs');const second=await vi.importMock('./bound.cjs');observe("bound",first,second)});
test("complete own-default callable automatic-only namespace",async()=>{const first=await vi.importMock('./own-default.cjs');const second=await vi.importMock('./own-default.cjs');observe("own-default",first,second)});
test("complete falsy-flag callable automatic-only namespace",async()=>{const first=await vi.importMock('./falsy-flag.cjs');const second=await vi.importMock('./falsy-flag.cjs');observe("falsy-flag",first,second)});
