MCPcopy Index your code
hub / github.com/chainreactors/EvilProxy / TestExecutorAdapterMethods

Function TestExecutorAdapterMethods

internal/pluginhost/adapters_test.go:2553–2742  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2551}
2552
2553func TestExecutorAdapterMethods(t *testing.T) {
2554 streamChunks := make(chan pluginapi.ExecutorStreamChunk, 2)
2555 streamErr := errors.New("stream failed")
2556 streamChunks <- pluginapi.ExecutorStreamChunk{Payload: []byte("stream-1")}
2557 streamChunks <- pluginapi.ExecutorStreamChunk{Err: streamErr}
2558 close(streamChunks)
2559
2560 pluginHTTPBody := []byte("http-response")
2561 pluginHTTPHeaders := http.Header{"X-Http": []string{"1"}}
2562 authProvider := fakeAuthProvider{
2563 identifier: "plugin-provider",
2564 refreshAuth: func(ctx context.Context, req pluginapi.AuthRefreshRequest) (pluginapi.AuthRefreshResponse, error) {
2565 if req.AuthID != "auth-1" || req.AuthProvider != "plugin-provider" || req.Metadata["old"] != "value" {
2566 t.Fatalf("refresh request = %#v, want auth metadata", req)
2567 }
2568 if req.HTTPClient == nil {
2569 t.Fatal("refresh request HTTPClient = nil, want host HTTP bridge")
2570 }
2571 return pluginapi.AuthRefreshResponse{
2572 Auth: pluginapi.AuthData{
2573 Metadata: map[string]any{"token": "new"},
2574 },
2575 }, nil
2576 },
2577 }
2578 executorRecord := normalizeTestCapabilityRecord(capabilityRecord{id: "executor-plugin"})
2579 host := newHostWithRecords(
2580 capabilityRecord{
2581 id: "auth-plugin",
2582 plugin: pluginapi.Plugin{
2583 Capabilities: pluginapi.Capabilities{
2584 AuthProvider: authProvider,
2585 },
2586 },
2587 },
2588 executorRecord,
2589 )
2590
2591 exec := &fakeExecutor{
2592 identifier: "ignored-by-adapter",
2593 execute: func(ctx context.Context, req pluginapi.ExecutorRequest) (pluginapi.ExecutorResponse, error) {
2594 assertExecutorRequest(t, req)
2595 return pluginapi.ExecutorResponse{
2596 Payload: []byte("execute-response"),
2597 Headers: http.Header{"X-Execute": []string{"1"}},
2598 Metadata: map[string]any{
2599 "phase": "execute",
2600 },
2601 }, nil
2602 },
2603 executeStream: func(ctx context.Context, req pluginapi.ExecutorRequest) (pluginapi.ExecutorStreamResponse, error) {
2604 assertExecutorRequest(t, req)
2605 return pluginapi.ExecutorStreamResponse{
2606 Headers: http.Header{"X-Stream": []string{"1"}},
2607 Chunks: streamChunks,
2608 }, nil
2609 },
2610 countTokens: func(ctx context.Context, req pluginapi.ExecutorRequest) (pluginapi.ExecutorResponse, error) {

Callers

nothing calls this directly

Calls 13

newHostWithRecordsFunction · 0.85
assertExecutorRequestFunction · 0.85
IdentifierMethod · 0.65
ExecuteMethod · 0.65
ExecuteStreamMethod · 0.65
RefreshMethod · 0.65
CountTokensMethod · 0.65
HttpRequestMethod · 0.65
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected