nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: go-logr/logr
Pull request #88 (2021-09-06 06:26:32)

handle typed nil on field
it raised panic. I fixed it.

so, I want to add tests about `Y, Z []int` for `nil` and `([]int)(nil)`, but its not compatible to `json.Marshal`.



Patch:
diff --git a/funcr/funcr.go b/funcr/funcr.go
index bb36d5e..ff47817 100644
--- a/funcr/funcr.go
+++ b/funcr/funcr.go
@@ -287,6 +287,9 @@ func prettyWithFlags(value interface{}, flags uint32) string {
 		buf.WriteRune('}')
 		return buf.String()
 	case reflect.Ptr, reflect.Interface:
+		if v.IsNil() {
+			return "null"
+		}
 		return pretty(v.Elem().Interface())
 	}
 	return fmt.Sprintf(`"<unhandled-%s>"`, t.Kind().String())


Test patch:
diff --git a/funcr/funcr_test.go b/funcr/funcr_test.go
index 70d0d31..735cbd6 100644
--- a/funcr/funcr_test.go
+++ b/funcr/funcr_test.go
@@ -95,6 +95,15 @@ func TestPretty(t *testing.T) {
 			{"nine", "three"},
 			{"seven", "six"},
 		},
+		struct {
+			A *int
+			B *int
+			C interface{}
+			D interface{}
+		}{
+			B: ptrint(1),
+			D: interface{}(2),
+		},
 	}
 
 	for i, tc := range cases {
Repository: go-openapi/runtime
Pull request #163 (2019-11-07 12:29:30)

different envs
Current way of checking the debug flag may affect many current applications where DEBUG flag is specified more precisely. Let's avoid it.


Patch:
diff --git a/logger/logger.go b/logger/logger.go
index d62c1f7..6f4debc 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -8,5 +8,13 @@ type Logger interface {
 }
 
 func DebugEnabled() bool {
-	return os.Getenv("SWAGGER_DEBUG") != "" || os.Getenv("DEBUG") != ""
+	d := os.Getenv("SWAGGER_DEBUG")
+	if d != "" && d != "false" && d != "0" {
+		return true
+	}
+	d = os.Getenv("DEBUG")
+	if d != "" && d != "false" && d != "0" {
+		return true
+	}
+	return false
 }


Test patch:
diff --git a/client/runtime_test.go b/client/runtime_test.go
index 7b6e17e..64f5441 100644
--- a/client/runtime_test.go
+++ b/client/runtime_test.go
@@ -929,6 +929,10 @@ func TestRuntime_DebugValue(t *testing.T) {
 	runtime = New("", "/", []string{"https"})
 	assert.True(t, runtime.Debug)
 
+	_ = os.Setenv("DEBUG", "false")
+	runtime = New("", "/", []string{"https"})
+	assert.False(t, runtime.Debug)
+
 	_ = os.Setenv("DEBUG", "foo")
 	runtime = New("", "/", []string{"https"})
 	assert.True(t, runtime.Debug)
Repository: go-openapi/runtime
Pull request #177 (2020-03-18 16:36:33)

adds a helper to build generic error responders
Signed-off-by: Ivan Porto Carrero <ivan@flanders.co.nz>


Patch:
diff --git a/middleware/not_implemented.go b/middleware/not_implemented.go
index 466f553..bc6942a 100644
--- a/middleware/not_implemented.go
+++ b/middleware/not_implemented.go
@@ -38,11 +38,30 @@ func (e *errorResp) WriteResponse(rw http.ResponseWriter, producer runtime.Produ
 		rw.WriteHeader(http.StatusInternalServerError)
 	}
 	if err := producer.Produce(rw, e.response); err != nil {
-		panic(err)
+		Logger.Printf("failed to write error response: %v", err)
 	}
 }
 
 // NotImplemented the error response when the response is not implemented
 func NotImplemented(message string) Responder {
-	return &errorResp{http.StatusNotImplemented, message, make(http.Header)}
+	return Error(http.StatusNotImplemented, message)
+}
+
+// Error creates a generic responder for returning errors, the data will be serialized
+// with the matching producer for the request
+func Error(code int, data interface{}, headers ...http.Header) Responder {
+	var hdr http.Header
+	for _, h := range headers {
+		for k, v := range h {
+			if hdr == nil {
+				hdr = make(http.Header)
+			}
+			hdr[k] = v
+		}
+	}
+	return &errorResp{
+		code:     code,
+		response: data,
+		headers:  hdr,
+	}
 }


Test patch:
diff --git a/middleware/not_implemented_test.go b/middleware/not_implemented_test.go
new file mode 100644
index 0000000..213a549
--- /dev/null
+++ b/middleware/not_implemented_test.go
@@ -0,0 +1,20 @@
+package middleware
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"testing"
+
+	"github.com/go-openapi/runtime"
+	"github.com/stretchr/testify/require"
+)
+
+func TestErrorResponder(t *testing.T) {
+	resp := Error(http.StatusBadRequest, map[string]string{"message": "this is the error body"})
+
+	rec := httptest.NewRecorder()
+	resp.WriteResponse(rec, runtime.JSONProducer())
+
+	require.Equal(t, http.StatusBadRequest, rec.Code)
+	require.Equal(t, "{\"message\":\"this is the error body\"}\n", rec.Body.String())
+}
Repository: go-openapi/runtime
Pull request #183 (2020-08-26 16:29:42)

Added restconf prefix and test cases
Fixes 182


Patch:
diff --git a/middleware/denco/router.go b/middleware/denco/router.go
index ecacc31..5d2691e 100644
--- a/middleware/denco/router.go
+++ b/middleware/denco/router.go
@@ -20,6 +20,9 @@ const (
 	// SeparatorCharacter separates path segments.
 	SeparatorCharacter = '/'
 
+	// PathParamCharacter indicates a RESTCONF path param
+	PathParamCharacter = '='
+
 	// MaxSize is max size of records and internal slice.
 	MaxSize = (1 << 22) - 1
 )
@@ -426,8 +429,9 @@ func makeRecords(srcs []Record) (statics, params []*record) {
 	termChar := string(TerminationCharacter)
 	paramPrefix := string(SeparatorCharacter) + string(ParamCharacter)
 	wildcardPrefix := string(SeparatorCharacter) + string(WildcardCharacter)
+	restconfPrefix := string(PathParamCharacter) + string(ParamCharacter)
 	for _, r := range srcs {
-		if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) {
+		if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) ||strings.Contains(r.Key, restconfPrefix){
 			r.Key += termChar
 			params = append(params, &record{Record: r})
 		} else {


Test patch:
diff --git a/middleware/denco/router_test.go b/middleware/denco/router_test.go
index 7e4b784..81eb55c 100644
--- a/middleware/denco/router_test.go
+++ b/middleware/denco/router_test.go
@@ -26,6 +26,7 @@ func routes() []denco.Record {
 		{"/:year/:month/:day", "testroute8"},
 		{"/user/:id", "testroute9"},
 		{"/a/to/b/:param/*routepath", "testroute10"},
+		{"/path/with/key=:value", "testroute14"},
 	}
 }
 
@@ -211,6 +212,7 @@ func TestRouter_Lookup(t *testing.T) {
 		{"/user/777", "testroute9", []denco.Param{{"id", "777"}}, true},
 		{"/a/to/b/p1/some/wildcard/params", "testroute10", []denco.Param{{"param", "p1"}, {"routepath", "some/wildcard/params"}}, true},
 		{"/missing", nil, nil, false},
+		{"/path/with/key=value", "testroute14", []denco.Param{{"value", "value"}}, true},
 	}
 	runLookupTest(t, routes(), testcases)
Repository: go-openapi/runtime
Pull request #188 (2020-11-07 14:19:57)

enh: retain authorizer error
Issue: #158 
the solution suggested by @kenjones-cisco  

Signed-off-by: Sergei Chudievich <kuuu1010100@gmail.com


Patch:
diff --git a/middleware/context.go b/middleware/context.go
index fba5748..250e35f 100644
--- a/middleware/context.go
+++ b/middleware/context.go
@@ -435,6 +435,10 @@ func (c *Context) Authorize(request *http.Request, route *MatchedRoute) (interfa
 	}
 	if route.Authorizer != nil {
 		if err := route.Authorizer.Authorize(request, usr); err != nil {
+			if _, ok := err.(errors.Error); ok {
+				return nil, nil, err
+			}
+
 			return nil, nil, errors.New(http.StatusForbidden, err.Error())
 		}
 	}


Test patch:
diff --git a/internal/testing/petstore/api.go b/internal/testing/petstore/api.go
index 91641f7..4cb1418 100644
--- a/internal/testing/petstore/api.go
+++ b/internal/testing/petstore/api.go
@@ -52,6 +52,8 @@ func NewAPI(t gotest.TB) (*loads.Document, *untyped.API) {
 			return "admin", nil
 		} else if username == "topuser" && password == "topuser" {
 			return "topuser", nil
+		} else if username == "anyother" && password == "anyother" {
+			return "anyother", nil
 		}
 		return nil, errors.Unauthenticated("basic")
 	}))
@@ -63,7 +65,11 @@ func NewAPI(t gotest.TB) (*loads.Document, *untyped.API) {
 	}))
 	api.RegisterAuthorizer(runtime.AuthorizerFunc(func(r *http.Request, user interface{}) error {
 		if r.Method == http.MethodPost && strings.HasPrefix(r.URL.Path, "/api/pets") && user.(string) != "admin" {
-			return goerrors.New("unauthorized")
+			if user.(string) == "topuser" {
+				return errors.CompositeValidationError(errors.New(errors.InvalidTypeCode, "unauthorized"))
+			} else {
+				return goerrors.New("unauthorized")
+			}
 		}
 		return nil
 	}))
diff --git a/middleware/context_test.go b/middleware/context_test.go
index b50966e..8e8f9cd 100644
--- a/middleware/context_test.go
+++ b/middleware/context_test.go
@@ -203,7 +203,7 @@ func TestContextAuthorize_WithAuthorizer(t *testing.T) {
 
 	request.SetBasicAuth("topuser", "topuser")
 	p, reqWithCtx, err := ctx.Authorize(request, ri)
-	assert.Error(t, err)
+	assertAPIError(t, apierrors.InvalidTypeCode, err)
 	assert.Nil(t, p)
 	assert.Nil(t, reqWithCtx)
 
@@ -212,6 +212,15 @@ func TestContextAuthorize_WithAuthorizer(t *testing.T) {
 	assert.NoError(t, err)
 	assert.Equal(t, "admin", p)
 	assert.NotNil(t, reqWithCtx)
+
+	request.SetBasicAuth("anyother", "anyother")
+	p, reqWithCtx, err = ctx.Authorize(request, ri)
+	assert.Error(t, err)
+	ae, ok := err.(apierrors.Error)
+	assert.True(t, ok)
+	assert.Equal(t, http.StatusForbidden, int(ae.Code()))
+	assert.Nil(t, p)
+	assert.Nil(t, reqWithCtx)
 }
 
 func TestContextNegotiateContentType(t *testing.T) {
Repository: go-openapi/runtime
Pull request #197 (2021-03-17 18:59:44)

add AuthInfoWriter Composition
Signed-off-by: Youyuan Wu <youyuanwu@outlook.com>

Support AuthInfoWriter composition. When multiple api key headers needed, the new function is useful. One can also combine basic auth and api-key.


Patch:
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..d207b18
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,1 @@
+*.go text eol=lf
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 0000000..3d80902
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,25 @@
+name: Go
+
+on:
+  push:
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+
+    - name: Set up Go
+      uses: actions/setup-go@v2
+      with:
+        go-version: 1.16.2
+
+    - name: Setup gotestsum
+      uses: autero1/action-gotestsum@v0.1.0
+      with:
+        gotestsum_version: 1.6.2
+
+    - name: Test
+      run: gotestsum --format short-verbose -- -race -timeout=20m -coverprofile=coverage.txt -covermode=atomic ./...
diff --git a/.travis.yml b/.travis.yml
index 78cdc89..a716f63 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
 after_success:
 - bash <(curl -s https://codecov.io/bash)
 go:
-- 1.14.x
 - 1.x
 install:
 - GO111MODULE=off go get -u gotest.tools/gotestsum
diff --git a/client/auth_info.go b/client/auth_info.go
index bbe1479..d37e8f6 100644
--- a/client/auth_info.go
+++ b/client/auth_info.go
@@ -59,3 +59,19 @@ func BearerToken(token string) runtime.ClientAuthInfoWriter {
 		return r.SetHeaderParam("Authorization", "Bearer "+token)
 	})
 }
+
+// Compose combines multiple ClientAuthInfoWriters into a single one.
+// Useful when multiple auth headers are needed.
+func Compose(auths ...runtime.ClientAuthInfoWriter) runtime.ClientAuthInfoWriter {
+	return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
+		for _, auth := range auths {
+			if auth == nil {
+				continue
+			}
+			if err := auth.AuthenticateRequest(r, nil); err != nil {
+				return err
+			}
+		}
+		return nil
+	})
+}


Test patch:
diff --git a/client/auth_info_test.go b/client/auth_info_test.go
index ef88594..73054a5 100644
--- a/client/auth_info_test.go
+++ b/client/auth_info_test.go
@@ -67,3 +67,14 @@ func TestBearerTokenAuth(t *testing.T) {
 
 	assert.Equal(t, "Bearer the-shared-token", r.header.Get("Authorization"))
 }
+
+func TestCompose(t *testing.T) {
+	r, _ := newRequest("GET", "/", nil)
+
+	writer := Compose(APIKeyAuth("x-api-key", "header", "the-api-key"), APIKeyAuth("x-secret-key", "header", "the-secret-key"))
+	err := writer.AuthenticateRequest(r, nil)
+	assert.NoError(t, err)
+
+	assert.Equal(t, "the-api-key", r.header.Get("x-api-key"))
+	assert.Equal(t, "the-secret-key", r.header.Get("x-secret-key"))
+}
Repository: go-jet/jet
Pull request #55 (2020-09-29 22:33:07)

Add support for custom functions.
This allows expressions like jet.Func("FOO", String("test")) to be
emitted as FOO($1).

go-jet: Thanks for the MR.

I think a better approach would be to implement custom functions rather than custom expressions.

Method signature would be:
```go
func FUNC(name string, expressions ...Expression) Expression
```
this would allow us to write:
```go
FUNC("foo") => foo()
FUNC("foo", String("name")) => foo(?)
FUNC("foo", Customer.FirstName.CONCAT(Customer.LastName)) => foo(customer.first_name || customer.last_name)
```


go-jet: Not sure at the moment about custom operators, it might be functions like PostfixOp(), PrefixOp, or something similar.
There might be a case where there is no workaround, except to add custom expressions support, but would rather get that case as an issue, then to implement it up front.
For this issue, just a custom function support would be enough. 

Patch:
diff --git a/internal/jet/func_expression.go b/internal/jet/func_expression.go
index d4eaa57..606e7e1 100644
--- a/internal/jet/func_expression.go
+++ b/internal/jet/func_expression.go
@@ -801,3 +801,8 @@ func newTimestampzFunc(name string, expressions ...Expression) *timestampzFunc {
 
 	return timestampzFunc
 }
+
+// Func can be used to call an custom or as of yet unsupported function in the database.
+func Func(name string, expressions ...Expression) Expression {
+	return newFunc(name, expressions, nil)
+}
diff --git a/mysql/expressions.go b/mysql/expressions.go
index 2292108..5c5810d 100644
--- a/mysql/expressions.go
+++ b/mysql/expressions.go
@@ -74,5 +74,8 @@ var TimestampExp = jet.TimestampExp
 // For example: Raw("current_database()")
 var Raw = jet.Raw
 
+// Func can be used to call an custom or as of yet unsupported function in the database.
+var Func = jet.Func
+
 // NewEnumValue creates new named enum value
 var NewEnumValue = jet.NewEnumValue
diff --git a/postgres/expressions.go b/postgres/expressions.go
index 61c0449..57a3335 100644
--- a/postgres/expressions.go
+++ b/postgres/expressions.go
@@ -85,5 +85,8 @@ var TimestampzExp = jet.TimestampzExp
 // For example: Raw("current_database()")
 var Raw = jet.Raw
 
+// Func can be used to call an custom or as of yet unsupported function in the database.
+var Func = jet.Func
+
 // NewEnumValue creates new named enum value
 var NewEnumValue = jet.NewEnumValue


Test patch:
diff --git a/internal/jet/func_expression_test.go b/internal/jet/func_expression_test.go
index c5a1e40..264be95 100644
--- a/internal/jet/func_expression_test.go
+++ b/internal/jet/func_expression_test.go
@@ -176,3 +176,7 @@ func TestTO_ASCII(t *testing.T) {
 	assertClauseSerialize(t, TO_ASCII(String("Karel")), `TO_ASCII($1)`, "Karel")
 	assertClauseSerialize(t, TO_ASCII(String("Karel")), `TO_ASCII($1)`, "Karel")
 }
+
+func TestFunc(t *testing.T) {
+	assertClauseSerialize(t, Func("FOO", String("test"), NULL, MAX(Int(1))), "FOO($1, NULL, MAX($2))", "test", int64(1))
+}
Repository: stern/stern
Pull request #235 (2023-02-25 23:51:47)

Return error when output option is invalid
Fixes https://github.com/stern/stern/issues/234

This PR fixes a bug that prints empty lines when an invalid output option is specified.


Patch:
diff --git a/cmd/cmd.go b/cmd/cmd.go
index f87fbd4..ca4b774 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -362,6 +362,8 @@ func (o *options) generateTemplate() (*template.Template, error) {
 				t = fmt.Sprintf("  \"namespace\": \"{{color .PodColor .Namespace}}\",\n%s", t)
 			}
 			t = fmt.Sprintf("{\n%s\n}", t)
+		default:
+			return nil, errors.New("output should be one of 'default', 'raw', 'json', 'extjson', and 'ppextjson'")
 		}
 		t += "\n"
 	}


Test patch:
diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go
index c11b366..6af8d6e 100644
--- a/cmd/cmd_test.go
+++ b/cmd/cmd_test.go
@@ -254,6 +254,18 @@ func TestOptionsGenerateTemplate(t *testing.T) {
 `,
 			false,
 		},
+		{
+			"invalid output",
+			func() *options {
+				o := NewOptions(streams)
+				o.output = "invalid"
+
+				return o
+			}(),
+			"message",
+			"",
+			true,
+		},
 		{
 			"template",
 			func() *options {
Repository: stern/stern
Pull request #331 (2025-01-06 14:55:06)

Add check for when `--no-follow` is set with `--tail=0`
These flags shouldn't be used together, otherwise no logs will ever be shown.

felipecrs: > Please add a test case.

Done.

Patch:
diff --git a/cmd/cmd.go b/cmd/cmd.go
index bef98c7..64a2250 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -163,6 +163,9 @@ func (o *options) Validate() error {
 	if o.selector != "" && o.resource != "" {
 		return errors.New("--selector and the <resource>/<name> query can not be set at the same time")
 	}
+	if o.noFollow && o.tail == 0 {
+		return errors.New("--no-follow cannot be used with --tail=0")
+	}
 
 	return nil
 }


Test patch:
diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go
index 5ec4e2a..62dba15 100644
--- a/cmd/cmd_test.go
+++ b/cmd/cmd_test.go
@@ -122,6 +122,18 @@ func TestOptionsValidate(t *testing.T) {
 			}(),
 			"--selector and the <resource>/<name> query can not be set at the same time",
 		},
+		{
+			"Specify both --no-follow and --tail=0",
+			func() *options {
+				o := NewOptions(streams)
+				o.podQuery = "."
+				o.noFollow = true
+				o.tail = 0
+
+				return o
+			}(),
+			"--no-follow cannot be used with --tail=0",
+		},
 		{
 			"Use prompt",
 			func() *options {
Repository: parquet-go/parquet-go
Pull request #233 (2025-01-31 22:37:36)

expose column chunk statistics
We used to miss an API to access the column chunk statistics, this PR addresses it.

I added these to the `FileColumnChunk` type only instead of the `ColumnChunk` interface to avoid building dependencies, we can revisit in the future.


Patch:
diff --git a/file.go b/file.go
index 97200b3..4890209 100644
--- a/file.go
+++ b/file.go
@@ -513,6 +513,21 @@ func (c *FileColumnChunk) Type() Type { return c.column.Type() }
 // Column returns the column index of this chunk in its parent row group.
 func (c *FileColumnChunk) Column() int { return int(c.column.Index()) }
 
+// Bounds returns the min and max values found in the column chunk.
+func (c *FileColumnChunk) Bounds() (min, max Value, ok bool) {
+	stats := &c.chunk.MetaData.Statistics
+	columnKind := c.Type().Kind()
+	hasMinValue := stats.MinValue != nil
+	hasMaxValue := stats.MaxValue != nil
+	if hasMinValue {
+		min = columnKind.Value(stats.MinValue)
+	}
+	if hasMaxValue {
+		max = columnKind.Value(stats.MaxValue)
+	}
+	return min, max, hasMinValue && hasMaxValue
+}
+
 // Pages returns a page reader for the column chunk.
 func (c *FileColumnChunk) Pages() Pages {
 	pages := Pages(c.PagesFrom(c.file.reader))
@@ -611,6 +626,14 @@ func (c *FileColumnChunk) NumValues() int64 {
 	return c.chunk.MetaData.NumValues
 }
 
+// NullCount returns the number of null values in the column chunk.
+//
+// This value is extracted from the column chunk statistics, parquet writers are
+// not required to populate it.
+func (c *FileColumnChunk) NullCount() int64 {
+	return c.chunk.MetaData.Statistics.NullCount
+}
+
 func (c *FileColumnChunk) readColumnIndex() (*FileColumnIndex, error) {
 	return c.readColumnIndexFrom(c.file.reader)
 }


Test patch:
diff --git a/file_test.go b/file_test.go
index e7beee8..9ce1a38 100644
--- a/file_test.go
+++ b/file_test.go
@@ -215,7 +215,7 @@ func TestFileKeyValueMetadata(t *testing.T) {
 }
 
 func TestFileTypes(t *testing.T) {
-	f, err := os.Open("testdata/alltypes_plain.parquet")
+	f, err := os.Open("testdata/data_index_bloom_encoding_stats.parquet")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -237,9 +237,21 @@ func TestFileTypes(t *testing.T) {
 			t.Fatalf("row group of parquet.File must be of type *parquet.FileRowGroup but got %T", rowGroup)
 		}
 		for _, columnChunk := range rowGroup.ColumnChunks() {
-			if _, ok := columnChunk.(*parquet.FileColumnChunk); !ok {
+			fcc, ok := columnChunk.(*parquet.FileColumnChunk)
+			if !ok {
 				t.Fatalf("column chunk of parquet.File must be of type *parquet.FileColumnChunk but got %T", columnChunk)
 			}
+			min, max, ok := fcc.Bounds()
+			if !ok {
+				t.Error("column chunk is missing statistics")
+			} else {
+				if min.IsNull() {
+					t.Error("column chunk has null min value")
+				}
+				if max.IsNull() {
+					t.Error("column chunk has null max value")
+				}
+			}
 		}
 	}
 }