bun test v1.4.4 (38afee6c8)

.local/research/shared-login-draft.test.ts:
(pass) twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls [0.47ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject independent limits before dependent control requests [0.27ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject missing retry before dependent control requests [0.08ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject wrong body before dependent control requests [0.08ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject wrong instance before dependent control requests [0.06ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject wrong actor before dependent control requests [0.07ms]
1 | import {expect,test} from 'bun:test';import {createSharedLoginCase,type LoginObservation} from './shared-login-draft';
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:5:898)
(fail) reject unexpected overload before dependent control requests [0.06ms]
(pass) native failure preserves its original identity [0.08ms]
2 | const aliases={api1:'11111111-1111-4111-8111-111111111111',api2:'22222222-2222-4222-8222-222222222222'};
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
6 | test('native failure preserves its original identity',async()=>{const f=fixture(),error=Error('FIXTURE_NATIVE_HTTP');f.ports.request=async()=>{throw error;};let actual;try{await createSharedLoginCase(f.ports)(aliases);}catch(e){actual=e;}expect(actual).toBe(error);});
7 | test('expired main window cannot count a second rate window',async()=>{const f=fixture();let read=0;f.ports.now=()=>read++===0?1000:61000;await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow('LOGIN_CASE_WINDOW_EXPIRED');});
                                                                                                                                                                                                            ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:7:201)
(fail) expired main window cannot count a second rate window [0.08ms]
3 | function fixture(){let count=0,controls=0,active=0,maxActive=0;const responses:LoginObservation[]=[];return {responses,get controls(){return controls;},get maxActive(){return maxActive;},ports:{now:()=>1000,request:async(replica:'api1'|'api2',kind:'main'|'control'):Promise<LoginObservation>=>{active++;maxActive=Math.max(maxActive,active);await Promise.resolve();active--;if(kind==='control'){controls++;return{status:201,alias:aliases[replica],actorCorrect:true,retryAfter:null,errorCode:null};}const index=count++,result=responses[index]??{status:index<10?201:429,alias:aliases[replica],actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited'};return result;}}};}
4 | test('twenty requests in concurrent pairs prove one shared ten-attempt window and two other-account controls',async()=>{const f=fixture();expect(await createSharedLoginCase(f.ports)(aliases)).toEqual({requests:20,accepted:10,denied:10,controls:2,elapsedMilliseconds:0});expect(f.maxActive).toBe(2);});
5 | test.each([{name:'independent limits',patch:{status:201},code:'SHARED_LIMIT_NOT_PROVED',index:10},{name:'missing retry',patch:{retryAfter:null},code:'LOGIN_RETRY_AFTER_INVALID',index:10},{name:'wrong body',patch:{errorCode:'unavailable'},code:'LOGIN_REJECTION_BODY_INVALID',index:10},{name:'wrong instance',patch:{alias:aliases.api2},code:'LOGIN_INSTANCE_MISMATCH',index:0},{name:'wrong actor',patch:{actorCorrect:false},code:'LOGIN_SUCCESS_ACTOR_MISMATCH',index:0},{name:'unexpected overload',patch:{status:503},code:'LOGIN_STATUS_UNEXPECTED',index:0}])('reject $name before dependent control requests',async({patch,code,index})=>{const f=fixture();f.responses[index]={status:index<10?201:429,alias:index%2===0?aliases.api1:aliases.api2,actorCorrect:true,retryAfter:index<10?null:'60',errorCode:index<10?null:'rate_limited',...patch};await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow(code);expect(f.controls).toBe(0);});
6 | test('native failure preserves its original identity',async()=>{const f=fixture(),error=Error('FIXTURE_NATIVE_HTTP');f.ports.request=async()=>{throw error;};let actual;try{await createSharedLoginCase(f.ports)(aliases);}catch(e){actual=e;}expect(actual).toBe(error);});
7 | test('expired main window cannot count a second rate window',async()=>{const f=fixture();let read=0;f.ports.now=()=>read++===0?1000:61000;await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow('LOGIN_CASE_WINDOW_EXPIRED');});
8 | test('failed other-account control rejects',async()=>{const f=fixture(),native=f.ports.request;f.ports.request=async(r,k)=>k==='control'?{status:429,alias:aliases[r],actorCorrect:false,retryAfter:'60',errorCode:'rate_limited'}:native(r,k);await expect(createSharedLoginCase(f.ports)(aliases)).rejects.toThrow('LOGIN_CONTROL_FAILED');});
                                                                                                                                                                                                                                                                                                                 ^
error: expect(received).rejects.toThrow(expected)

Expected promise that rejects
Received promise that resolved: Promise { <resolved> }

      at <anonymous> (/Users/rey/mtuci/vp/lab7/.local/research/shared-login-draft.test.ts:8:302)
(fail) failed other-account control rejects [0.09ms]
(pass) explicit ports have no process or network fallback [0.02ms]

 3 pass
 8 fail
 12 expect() calls
Ran 11 tests across 1 file. [8.00ms]
