diff --git a/sdk/api/handlers/handlers.go b/sdk/api/handlers/handlers.go index 6734d500..49e73d46 100644 --- a/sdk/api/handlers/handlers.go +++ b/sdk/api/handlers/handlers.go @@ -194,11 +194,11 @@ func requestExecutionMetadata(ctx context.Context) map[string]any { key = strings.TrimSpace(ginCtx.GetHeader("Idempotency-Key")) } } - if key == "" { - return make(map[string]any) - } - meta := map[string]any{idempotencyKeyMetadataKey: key} + meta := make(map[string]any) + if key != "" { + meta[idempotencyKeyMetadataKey] = key + } if pinnedAuthID := pinnedAuthIDFromContext(ctx); pinnedAuthID != "" { meta[coreexecutor.PinnedAuthMetadataKey] = pinnedAuthID } diff --git a/sdk/api/handlers/handlers_metadata_test.go b/sdk/api/handlers/handlers_metadata_test.go new file mode 100644 index 00000000..99af872d --- /dev/null +++ b/sdk/api/handlers/handlers_metadata_test.go @@ -0,0 +1,20 @@ +package handlers + +import ( + "testing" + + coreexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor" + "golang.org/x/net/context" +) + +func TestRequestExecutionMetadataIncludesExecutionSessionWithoutIdempotencyKey(t *testing.T) { + ctx := WithExecutionSessionID(context.Background(), "session-1") + + meta := requestExecutionMetadata(ctx) + if got := meta[coreexecutor.ExecutionSessionMetadataKey]; got != "session-1" { + t.Fatalf("ExecutionSessionMetadataKey = %v, want %q", got, "session-1") + } + if _, ok := meta[idempotencyKeyMetadataKey]; ok { + t.Fatalf("unexpected idempotency key in metadata: %v", meta[idempotencyKeyMetadataKey]) + } +}