File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -692,7 +692,7 @@ describe("recorder strict mode", () => {
692692 expect ( body . error . message ) . toBe ( "Strict mode: no fixture matched" ) ;
693693 } ) ;
694694
695- it ( "record + strict: proxy succeeds when upstream is available" , async ( ) => {
695+ it ( "record + strict: strict blocks proxy even when upstream is available" , async ( ) => {
696696 await setupUpstreamAndRecorder ( [
697697 {
698698 match : { userMessage : "hello" } ,
@@ -714,14 +714,15 @@ describe("recorder strict mode", () => {
714714 record : { providers : { openai : upstream ! . url } , fixturePath : tmpDir } ,
715715 } ) ;
716716
717+ // Strict mode now takes precedence over proxy — returns 503
717718 const resp = await post ( `${ recorder . url } /v1/chat/completions` , {
718719 model : "gpt-4" ,
719720 messages : [ { role : "user" , content : "hello" } ] ,
720721 } ) ;
721722
722- expect ( resp . status ) . toBe ( 200 ) ;
723+ expect ( resp . status ) . toBe ( 503 ) ;
723724 const body = JSON . parse ( resp . body ) ;
724- expect ( body . choices [ 0 ] . message . content ) . toBe ( "world " ) ;
725+ expect ( body . error . message ) . toBe ( "Strict mode: no fixture matched " ) ;
725726 } ) ;
726727} ) ;
727728
Original file line number Diff line number Diff line change @@ -219,4 +219,19 @@ describe("X-AIMock-Strict header integration", () => {
219219 expect ( entries . length ) . toBe ( 1 ) ;
220220 expect ( entries [ 0 ] . response . strictOverride ) . toBe ( false ) ;
221221 } ) ;
222+
223+ it ( "strict header prevents proxy in record mode" , async ( ) => {
224+ server = await createServer ( [ ] , {
225+ port : 0 ,
226+ record : {
227+ providers : { openai : "https://api.openai.com" } ,
228+ } ,
229+ } ) ;
230+ const res = await httpPost ( `${ server . url } /v1/chat/completions` , chatRequest ( "anything" ) , {
231+ "X-AIMock-Strict" : "true" ,
232+ } ) ;
233+ expect ( res . status ) . toBe ( 503 ) ;
234+ const body = JSON . parse ( res . body ) ;
235+ expect ( body . error . message ) . toBe ( "Strict mode: no fixture matched" ) ;
236+ } ) ;
222237} ) ;
You can’t perform that action at this time.
0 commit comments