@@ -24,9 +24,6 @@ import (
2424 "time"
2525
2626 egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
27- "github.com/modelcontextprotocol/go-sdk/mcp"
28- "github.com/openai/openai-go"
29- "github.com/openai/openai-go/option"
3027 "github.com/stretchr/testify/require"
3128 "github.com/tetratelabs/func-e/api"
3229 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -35,84 +32,29 @@ import (
3532
3633 "github.com/envoyproxy/ai-gateway/cmd/extproc/mainlib"
3734 "github.com/envoyproxy/ai-gateway/internal/aigw"
38- "github.com/envoyproxy/ai-gateway/internal/autoconfig"
3935 "github.com/envoyproxy/ai-gateway/internal/filterapi"
4036 internaltesting "github.com/envoyproxy/ai-gateway/internal/testing"
4137)
4238
43- // startupRegexp ensures the status message is written to stderr as we know we are healthy!
44- var startupRegexp = `Envoy AI Gateway listening on http://localhost:1975 \(admin http://localhost:\d+\) after [^\n]+`
45-
39+ // TestRun verifies that the main run function starts up correctly without making any actual requests.
40+ //
41+ // The real e2e tests are in tests/e2e-aigw.
4642func TestRun (t * testing.T ) {
47- ollamaModel , err := internaltesting .GetOllamaModel (internaltesting .ChatModel )
48- if err == nil {
49- err = internaltesting .CheckIfOllamaReady (ollamaModel )
50- }
51- if err != nil {
52- t .Skip (err )
53- }
54-
5543 ports := internaltesting .RequireRandomPorts (t , 1 )
5644 // TODO: parameterize the main listen port 1975
5745 adminPort := ports [0 ]
5846
59- t .Setenv ("OPENAI_BASE_URL" , "http://localhost:11434/v1" )
47+ // Note: we do not make any real requests here!
48+ t .Setenv ("OPENAI_BASE_URL" , "https://api.openai.com/v1" )
6049 t .Setenv ("OPENAI_API_KEY" , "unused" )
6150
6251 buffers := internaltesting .DumpLogsOnFail (t , "aigw Stdout" , "aigw Stderr" )
6352 stdout , stderr := buffers [0 ], buffers [1 ]
6453 ctx , cancel := context .WithCancel (t .Context ())
6554 defer cleanupRun (t , cancel )
6655
67- go func () {
68- opts := runOpts {extProcLauncher : mainlib .Main }
69- require .NoError (t , run (ctx , cmdRun {Debug : true , AdminPort : adminPort }, opts , stdout , stderr ))
70- }()
71-
72- client := openai .NewClient (option .WithBaseURL ("http://localhost:1975/v1/" ))
73- chatReq := openai.ChatCompletionNewParams {
74- Messages : []openai.ChatCompletionMessageParamUnion {
75- openai .UserMessage ("Say this is a test" ),
76- },
77- Model : ollamaModel ,
78- }
79-
80- t .Run ("chat completion" , func (t * testing.T ) {
81- internaltesting .RequireEventuallyNoError (t , func () error {
82- chatCompletion , err := client .Chat .Completions .New (ctx , chatReq )
83- if err != nil {
84- return fmt .Errorf ("chat completion failed: %w" , err )
85- }
86- for _ , choice := range chatCompletion .Choices {
87- if choice .Message .Content != "" {
88- return nil
89- }
90- }
91- return fmt .Errorf ("no content in response" )
92- }, 1 * time .Minute , 2 * time .Second ,
93- "chat completion never succeeded" )
94- })
95-
96- // By now, we're listening
97- require .Regexp (t , startupRegexp , stderr .String ())
98-
99- t .Run ("access metrics" , func (t * testing.T ) {
100- internaltesting .RequireEventuallyNoError (t , func () error {
101- req , err := http .NewRequest (http .MethodGet ,
102- fmt .Sprintf ("http://localhost:%d/metrics" , adminPort ), nil )
103- require .NoError (t , err )
104- resp , err := http .DefaultClient .Do (req )
105- if err != nil {
106- return err
107- }
108- defer resp .Body .Close ()
109- if resp .StatusCode != http .StatusOK {
110- return fmt .Errorf ("status %d" , resp .StatusCode )
111- }
112- return nil
113- }, 1 * time .Minute , time .Second ,
114- "metrics endpoint never became available" )
115- })
56+ opts := runOpts {extProcLauncher : func (context.Context , []string , io.Writer ) error { return nil }}
57+ require .NoError (t , run (ctx , cmdRun {Debug : true , AdminPort : adminPort }, opts , stdout , stderr ))
11658}
11759
11860func cleanupRun (t testing.TB , cancel context.CancelFunc ) {
@@ -126,73 +68,6 @@ func cleanupRun(t testing.TB, cancel context.CancelFunc) {
12668 }
12769}
12870
129- // TestRunMCP runs the AIGW with MCP configured and verifies calling a tool.
130- // It uses the same MCP config as docker-compose.yaml to ensure consistency.
131- func TestRunMCP (t * testing.T ) {
132- ports := internaltesting .RequireRandomPorts (t , 1 )
133- // TODO: parameterize the main listen port 1975
134- adminPort := ports [0 ]
135-
136- mcpServers := & autoconfig.MCPServers {
137- McpServers : map [string ]autoconfig.MCPServer {
138- "kiwi" : {
139- Type : "http" ,
140- URL : "https://mcp.kiwi.com" ,
141- },
142- },
143- }
144-
145- buffers := internaltesting .DumpLogsOnFail (t , "aigw Stdout" , "aigw Stderr" )
146- stdout , stderr := buffers [0 ], buffers [1 ]
147- ctx , cancel := context .WithCancel (t .Context ())
148- defer cleanupRun (t , cancel )
149-
150- go func () {
151- opts := runOpts {extProcLauncher : mainlib .Main }
152- require .NoError (t , run (ctx , cmdRun {Debug : true , AdminPort : adminPort , mcpConfig : mcpServers }, opts , stdout , stderr ))
153- }()
154-
155- url := fmt .Sprintf ("http://localhost:%d/mcp" , 1975 )
156- mcpClient := mcp .NewClient (& mcp.Implementation {Name : "test-client" , Version : "0.1.0" },
157- & mcp.ClientOptions {})
158-
159- // Calculate departure date as one week from now
160- departureDate := time .Now ().AddDate (0 , 0 , 7 ).Format ("02/01/2006" )
161-
162- callTool := & mcp.CallToolParams {
163- Name : "kiwi__search-flight" ,
164- Arguments : map [string ]any {
165- "flyFrom" : "NYC" ,
166- "flyTo" : "LAX" ,
167- "departureDate" : departureDate ,
168- },
169- }
170-
171- t .Run ("call tool" , func (t * testing.T ) {
172- internaltesting .RequireEventuallyNoError (t , func () error {
173- session , err := mcpClient .Connect (t .Context (),
174- & mcp.StreamableClientTransport {Endpoint : url }, nil )
175- if err != nil {
176- return fmt .Errorf ("connect failed: %w" , err )
177- }
178- defer session .Close ()
179-
180- resp , err := session .CallTool (t .Context (), callTool )
181- if err != nil {
182- return fmt .Errorf ("call tool failed: %w" , err )
183- }
184- if resp .IsError {
185- return fmt .Errorf ("tool returned error response" )
186- }
187- return nil
188- }, 2 * time .Minute , 2 * time .Second ,
189- "MCP tool call never succeeded" )
190- })
191-
192- // By now, we're listening
193- require .Regexp (t , startupRegexp , stderr .String ())
194- }
195-
19671func TestRunExtprocStartFailure (t * testing.T ) {
19772 t .Setenv ("OPENAI_BASE_URL" , "http://localhost:11434/v1" )
19873 t .Setenv ("OPENAI_API_KEY" , "unused" )
0 commit comments