mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
Track when executor calls cross an upstream transport boundary and use that signal to keep model/provider errors from being replaced by later local preparation, selection, or internal failures. Mark HTTP, websocket, relay, and usage-tracked transports as upstream attempts, while avoiding marks for local validation, logging, missing sessions, and successful websocket handshakes before request send. Parse relative auth expiry metadata and adjust Antigravity refresh timing.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package pluginhost
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/executor"
|
|
"github.com/router-for-me/CLIProxyAPI/v7/sdk/pluginapi"
|
|
)
|
|
|
|
func TestHostHTTPClientMarksUpstreamAttempt(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
_, _ = io.WriteString(w, "ok")
|
|
}))
|
|
t.Cleanup(server.Close)
|
|
|
|
client := New().newHTTPClient(nil)
|
|
for _, test := range []struct {
|
|
name string
|
|
do func(context.Context) error
|
|
}{
|
|
{
|
|
name: "buffered",
|
|
do: func(ctx context.Context) error {
|
|
_, errDo := client.Do(ctx, pluginapi.HTTPRequest{URL: server.URL})
|
|
return errDo
|
|
},
|
|
},
|
|
{
|
|
name: "stream",
|
|
do: func(ctx context.Context) error {
|
|
response, errDo := client.DoStream(ctx, pluginapi.HTTPRequest{URL: server.URL})
|
|
if errDo != nil {
|
|
return errDo
|
|
}
|
|
for range response.Chunks {
|
|
}
|
|
return nil
|
|
},
|
|
},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
ctx := cliproxyexecutor.WithUpstreamAttemptTracker(context.Background())
|
|
if errDo := test.do(ctx); errDo != nil {
|
|
t.Fatalf("host HTTP request error = %v", errDo)
|
|
}
|
|
if !cliproxyexecutor.UpstreamAttempted(ctx) {
|
|
t.Fatal("host HTTP request did not mark an upstream attempt")
|
|
}
|
|
})
|
|
}
|
|
}
|