nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: openconfig/ygot
Pull request #608 (2021-11-30 18:24:10)

Add check for empty origin special case

coveralls: 
[![Coverage Status](https://coveralls.io/builds/44647201/badge)](https://coveralls.io/builds/44647201)

Coverage increased (+0.002%) to 90.978% when pulling **0303dccebcebd546436f3e04c4598d85f818487d on DanG100:match-origin** into **ef8f2a136f7de61f1aa2edfe02cc5d7c907e2418 on openconfig:master**.


Patch:
diff --git a/util/gnmi.go b/util/gnmi.go
index 546fcfe..8ef9771 100644
--- a/util/gnmi.go
+++ b/util/gnmi.go
@@ -103,7 +103,11 @@ func PathMatchesPathElemPrefix(path, prefix *gpb.Path) bool {
 // If either path and query contain nil elements func returns false.
 // Both paths must use the gNMI >=0.4.0 PathElem path format.
 func PathMatchesQuery(path, query *gpb.Path) bool {
-	if len(path.GetElem()) < len(query.GetElem()) || path.Origin != query.Origin {
+	if len(path.GetElem()) < len(query.GetElem()) {
+		return false
+	}
+	// Unset Origin fields can match "openconfig", see https://github.com/openconfig/reference/blob/master/rpc/gnmi/mixed-schema.md#special-values-of-origin.
+	if path.Origin != query.Origin && !(path.Origin == "" && query.Origin == "openconfig" || path.Origin == "openconfig" && query.Origin == "") {
 		return false
 	}
 	for i, queryElem := range query.Elem {


Test patch:
diff --git a/util/gnmi_test.go b/util/gnmi_test.go
index 9df882a..a7cb91e 100644
--- a/util/gnmi_test.go
+++ b/util/gnmi_test.go
@@ -547,6 +547,24 @@ func TestPathMatchesQuery(t *testing.T) {
 			}},
 		},
 		want: true,
+	}, {
+		desc: "valid query with implied openconfig origin path",
+		inPath: &gpb.Path{
+			Origin: "",
+		},
+		inQuery: &gpb.Path{
+			Origin: "openconfig",
+		},
+		want: true,
+	}, {
+		desc: "valid query with implied openconfig origin query",
+		inPath: &gpb.Path{
+			Origin: "openconfig",
+		},
+		inQuery: &gpb.Path{
+			Origin: "",
+		},
+		want: true,
 	}, {
 		desc: "valid query with wildcard name",
 		inPath: &gpb.Path{
@@ -648,6 +666,21 @@ func TestPathMatchesQuery(t *testing.T) {
 				Name: "three",
 			}},
 		},
+	}, {
+		desc: "invalid longer query",
+		inPath: &gpb.Path{
+			Elem: []*gpb.PathElem{
+				{
+					Name: "twelve",
+				}},
+		},
+		inQuery: &gpb.Path{
+			Elem: []*gpb.PathElem{{
+				Name: "one",
+			}, {
+				Name: "two",
+			}},
+		},
 	}, {
 		desc: "invalid names not equal",
 		inPath: &gpb.Path{