@@ -25,7 +25,6 @@ import (
2525 "github.com/coder/aibridge/mcp"
2626 "github.com/coder/aibridge/provider"
2727 "github.com/stretchr/testify/require"
28- "golang.org/x/tools/txtar"
2928)
3029
3130func openaiCfgWithAPIDump (url , key , dumpDir string ) config.OpenAI {
@@ -92,16 +91,9 @@ func TestAPIDump(t *testing.T) {
9291 ctx , cancel := context .WithTimeout (t .Context (), time .Second * 30 )
9392 t .Cleanup (cancel )
9493
95- arc := txtar .Parse (tc .fixture )
96- files := filesMap (arc )
97- require .Contains (t , files , fixtureRequest )
98- require .Contains (t , files , fixtureNonStreamingResponse )
99-
100- reqBody := files [fixtureRequest ]
101-
10294 // Setup mock upstream server.
103- srv := newMockServer ( ctx , t , files , nil , nil )
104- t . Cleanup ( srv . Close )
95+ fix := fixtures . Parse ( t , tc . fixture )
96+ srv := testutil . NewMockUpstream ( t , ctx , testutil . NewFixtureResponse ( fix ) )
10597
10698 // Create temp dir for API dumps.
10799 dumpDir := t .TempDir ()
@@ -117,7 +109,7 @@ func TestAPIDump(t *testing.T) {
117109 }
118110 mockSrv .Start ()
119111
120- req := tc .createRequestFunc (t , mockSrv .URL , reqBody )
112+ req := tc .createRequestFunc (t , mockSrv .URL , fix . Request () )
121113 resp , err := http .DefaultClient .Do (req )
122114 require .NoError (t , err )
123115 require .Equal (t , http .StatusOK , resp .StatusCode )
@@ -163,7 +155,7 @@ func TestAPIDump(t *testing.T) {
163155 require .NoError (t , err )
164156
165157 // Compare requests semantically (key order may differ).
166- require .JSONEq (t , string (dumpBody ), string (reqBody ), "request body JSON should match semantically" )
158+ require .JSONEq (t , string (dumpBody ), string (fix . Request () ), "request body JSON should match semantically" )
167159
168160 // Verify response dump contains expected HTTP response format.
169161 respDumpData , err := os .ReadFile (respDumpFile )
@@ -177,7 +169,7 @@ func TestAPIDump(t *testing.T) {
177169 require .NoError (t , err )
178170
179171 // Compare responses semantically (key order may differ).
180- expectedRespBody := files [ fixtureNonStreamingResponse ]
172+ expectedRespBody := fix . NonStreaming ()
181173 require .JSONEq (t , string (expectedRespBody ), string (dumpRespBody ), "response body JSON should match semantically" )
182174
183175 recorderClient .VerifyAllInterceptionsEnded (t )
0 commit comments