@@ -592,10 +592,10 @@ describe('/api/v1/chat/completions POST endpoint', () => {
592592 'x-forwarded-for' : '8.8.8.8' ,
593593 } ,
594594 body : JSON . stringify ( {
595- model : 'minimax/minimax-m2.7' ,
595+ model : FREEBUFF_DEEPSEEK_V4_FLASH_MODEL_ID ,
596596 stream : false ,
597597 codebuff_metadata : {
598- run_id : 'run-free' ,
598+ run_id : 'run-free-deepseek-flash ' ,
599599 client_id : 'test-client-id-123' ,
600600 cost_mode : 'free' ,
601601 freebuff_instance_id : 'active-instance-123' ,
@@ -705,6 +705,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
705705 )
706706
707707 it ( 'limits unknown-location free-mode requests to DeepSeek Flash' , async ( ) => {
708+ const checkSessionAdmissible = mock ( async ( ) => {
709+ throw new Error (
710+ 'limited model enforcement should run before session gate' ,
711+ )
712+ } )
708713 // Use a TEST-NET-1 IP (RFC 5737) that geoip-lite cannot resolve, with
709714 // no cf-ipcountry header. This avoids the dev-only localhost bypass
710715 // (which kicks in when there is no cf-ipcountry AND no/loopback IP).
@@ -738,24 +743,21 @@ describe('/api/v1/chat/completions POST endpoint', () => {
738743 fetch : mockFetch ,
739744 insertMessageBigquery : mockInsertMessageBigquery ,
740745 loggerWithContext : mockLoggerWithContext ,
741- checkSessionAdmissible : async ( params ) => {
742- expect ( params . accessTier ) . toBe ( 'limited' )
743- expect ( params . requestedModel ) . toBe ( 'minimax/minimax-m2.7' )
744- return {
745- ok : false ,
746- code : 'session_model_mismatch' ,
747- message :
748- 'Limited free access is only available with DeepSeek V4 Flash.' ,
749- }
750- } ,
746+ checkSessionAdmissible,
751747 } )
752748
753749 expect ( response . status ) . toBe ( 409 )
754750 const body = await response . json ( )
755751 expect ( body . error ) . toBe ( 'session_model_mismatch' )
752+ expect ( checkSessionAdmissible ) . toHaveBeenCalledTimes ( 0 )
756753 } )
757754
758755 it ( 'classifies anonymized Cloudflare country codes as limited access' , async ( ) => {
756+ const checkSessionAdmissible = mock ( async ( ) => {
757+ throw new Error (
758+ 'limited model enforcement should run before session gate' ,
759+ )
760+ } )
759761 const req = new NextRequest (
760762 'http://localhost:3000/api/v1/chat/completions' ,
761763 {
@@ -787,20 +789,13 @@ describe('/api/v1/chat/completions POST endpoint', () => {
787789 fetch : mockFetch ,
788790 insertMessageBigquery : mockInsertMessageBigquery ,
789791 loggerWithContext : mockLoggerWithContext ,
790- checkSessionAdmissible : async ( params ) => {
791- expect ( params . accessTier ) . toBe ( 'limited' )
792- return {
793- ok : false ,
794- code : 'session_model_mismatch' ,
795- message :
796- 'Limited free access is only available with DeepSeek V4 Flash.' ,
797- }
798- } ,
792+ checkSessionAdmissible,
799793 } )
800794
801795 expect ( response . status ) . toBe ( 409 )
802796 const body = await response . json ( )
803797 expect ( body . error ) . toBe ( 'session_model_mismatch' )
798+ expect ( checkSessionAdmissible ) . toHaveBeenCalledTimes ( 0 )
804799 } )
805800
806801 it (
0 commit comments