diff --git a/deps.bzl b/deps.bzl index e3f9be261f26e..f01dc7160870c 100644 --- a/deps.bzl +++ b/deps.bzl @@ -5294,8 +5294,8 @@ def go_dependencies(): name = "com_github_sourcegraph_zoekt", build_file_proto_mode = "disable_global", importpath = "github.com/sourcegraph/zoekt", - sum = "h1:QnS7KZETcE9g2CvBCF423BMhIXIwtxuvck3N7SKBJC0=", - version = "v0.0.0-20240327102325-8cf8887a903a", + sum = "h1:tMqptvT8zd2xD1Yl11zDd42fBHxlT40zJoPU+Vl8REI=", + version = "v0.0.0-20240402071238-c39011a14191", ) go_repository( name = "com_github_spaolacci_murmur3", diff --git a/go.mod b/go.mod index 67f352033bf24..5ac49dc39c584 100644 --- a/go.mod +++ b/go.mod @@ -585,7 +585,7 @@ require ( github.com/scim2/filter-parser/v2 v2.2.0 github.com/sourcegraph/conc v0.3.1-0.20240108182409-4afefce20f9b github.com/sourcegraph/mountinfo v0.0.0-20240201124957-b314c0befab1 - github.com/sourcegraph/zoekt v0.0.0-20240327102325-8cf8887a903a + github.com/sourcegraph/zoekt v0.0.0-20240402071238-c39011a14191 github.com/spf13/cobra v1.8.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect diff --git a/go.sum b/go.sum index 5bdf03d6ed06a..d8f83a17e03b4 100644 --- a/go.sum +++ b/go.sum @@ -1690,8 +1690,8 @@ github.com/sourcegraph/scip v0.3.3 h1:3EOkChYOntwHl0pPSAju7rj0oRuujh8owC4vjGDEr0 github.com/sourcegraph/scip v0.3.3/go.mod h1:Q67VaoTpftINIy/CLrkYQOMwlsx67h8ys+ligmdUcqM= github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o= github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I= -github.com/sourcegraph/zoekt v0.0.0-20240327102325-8cf8887a903a h1:QnS7KZETcE9g2CvBCF423BMhIXIwtxuvck3N7SKBJC0= -github.com/sourcegraph/zoekt v0.0.0-20240327102325-8cf8887a903a/go.mod h1:+j+huwz4ZnffJmDHeLJyI9AY4a8DKQnfNV0J//upnyo= +github.com/sourcegraph/zoekt v0.0.0-20240402071238-c39011a14191 h1:tMqptvT8zd2xD1Yl11zDd42fBHxlT40zJoPU+Vl8REI= +github.com/sourcegraph/zoekt v0.0.0-20240402071238-c39011a14191/go.mod h1:+j+huwz4ZnffJmDHeLJyI9AY4a8DKQnfNV0J//upnyo= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v0.0.0-20170901052352-ee1bd8ee15a1/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= diff --git a/internal/search/job/jobutil/job_test.go b/internal/search/job/jobutil/job_test.go index d90a8646eb966..aad412a89d658 100644 --- a/internal/search/job/jobutil/job_test.go +++ b/internal/search/job/jobutil/job_test.go @@ -241,7 +241,7 @@ func TestNewPlanJob(t *testing.T) { (repoScope . [(and branch="HEAD" rawConfig:RcOnlyPublic|RcNoForks|RcNoArchived)]) (includePrivate . true) (globalZoektQueryRegexps . [(?i)(?-s:ok.*?ok)]) - (query . regex:"(?-s:ok.*?ok)") + (query . regex:"ok(?-s:.)*?ok") (type . text)) (REPOSEARCH (repoOpts.repoFilters . [(?:ok).*?(?:ok)]) @@ -386,7 +386,7 @@ func TestNewPlanJob(t *testing.T) { (repoScope . [(and branch="HEAD" rawConfig:RcOnlyPublic|RcNoForks|RcNoArchived)]) (includePrivate . true) (globalZoektQueryRegexps . [(?i)(?-s:foo.*?@bar)]) - (query . regex:"(?-s:foo.*?@bar)") + (query . regex:"foo(?-s:.)*?@bar") (type . text)) REPOSCOMPUTEEXCLUDED NOOP))))) @@ -880,7 +880,7 @@ func TestNewPlanJob(t *testing.T) { (repoScope . [(and branch="HEAD" rawConfig:RcOnlyPublic|RcNoForks|RcNoArchived)]) (includePrivate . true) (globalZoektQueryRegexps . [(?i)(?-s:a.*b)]) - (query . regex:"(?-s:a.*b)") + (query . regex:"a(?-s:.)*b") (type . text)) REPOSCOMPUTEEXCLUDED NOOP)))))) @@ -915,7 +915,7 @@ func TestNewPlanJob(t *testing.T) { (fileMatchLimit . 10000) (select . ) (zoektQueryRegexps . [(?i)(?-s:a.*b)]) - (query . regex:"(?-s:a.*b)") + (query . regex:"a(?-s:.)*b") (type . text)))) (REPOPAGER (containsRefGlobs . false) diff --git a/internal/search/zoekt/query_test.go b/internal/search/zoekt/query_test.go index a80dbe62779f9..2867ef2f48d58 100644 --- a/internal/search/zoekt/query_test.go +++ b/internal/search/zoekt/query_test.go @@ -3,7 +3,6 @@ package zoekt import ( "testing" - "github.com/google/go-cmp/cmp" "github.com/hexops/autogold/v2" "github.com/sourcegraph/sourcegraph/internal/search" @@ -17,79 +16,79 @@ func TestQueryToZoektQuery(t *testing.T) { Type search.IndexedRequestType Query string Features search.Features - WantZoektOutput string + WantZoektOutput autogold.Value }{ { Name: "substr", Type: search.TextRequest, Query: `foo patterntype:regexp`, - WantZoektOutput: `substr:"foo"`, + WantZoektOutput: autogold.Expect(`substr:"foo"`), }, { Name: "symbol substr", Type: search.SymbolRequest, Query: `foo patterntype:regexp type:symbol`, - WantZoektOutput: `sym:substr:"foo"`, + WantZoektOutput: autogold.Expect(`sym:substr:"foo"`), }, { Name: "regex", Type: search.TextRequest, Query: `(foo).*?(bar) patterntype:regexp`, - WantZoektOutput: `regex:"(?-s:foo.*?bar)"`, + WantZoektOutput: autogold.Expect(`regex:"foo(?-s:.)*?bar"`), }, { Name: "path", Type: search.TextRequest, Query: `foo file:\.go$ file:\.yaml$ -file:\bvendor\b patterntype:regexp`, - WantZoektOutput: `(and substr:"foo" file_regex:"(?m:\\.go$)" file_regex:"(?m:\\.yaml$)" (not file_regex:"\\bvendor\\b"))`, + WantZoektOutput: autogold.Expect(`(and substr:"foo" file_regex:"\\.go(?m:$)" file_regex:"\\.yaml(?m:$)" (not file_regex:"\\bvendor\\b"))`), }, { Name: "case", Type: search.TextRequest, Query: `foo case:yes patterntype:regexp file:\.go$ file:yaml`, - WantZoektOutput: `(and case_substr:"foo" case_file_regex:"(?m:\\.go$)" case_file_substr:"yaml")`, + WantZoektOutput: autogold.Expect(`(and case_substr:"foo" case_file_regex:"\\.go(?m:$)" case_file_substr:"yaml")`), }, { Name: "casepath", Type: search.TextRequest, Query: `foo case:yes file:\.go$ file:\.yaml$ -file:\bvendor\b patterntype:regexp`, - WantZoektOutput: `(and case_substr:"foo" case_file_regex:"(?m:\\.go$)" case_file_regex:"(?m:\\.yaml$)" (not case_file_regex:"\\bvendor\\b"))`, + WantZoektOutput: autogold.Expect(`(and case_substr:"foo" case_file_regex:"\\.go(?m:$)" case_file_regex:"\\.yaml(?m:$)" (not case_file_regex:"\\bvendor\\b"))`), }, { Name: "path matches only", Type: search.TextRequest, Query: `test type:path`, - WantZoektOutput: `file_substr:"test"`, + WantZoektOutput: autogold.Expect(`file_substr:"test"`), }, { Name: "content matches only", Type: search.TextRequest, Query: `test type:file patterntype:literal`, - WantZoektOutput: `content_substr:"test"`, + WantZoektOutput: autogold.Expect(`content_substr:"test"`), }, { Name: "content and path matches", Type: search.TextRequest, Query: `test`, - WantZoektOutput: `substr:"test"`, + WantZoektOutput: autogold.Expect(`substr:"test"`), }, { Name: "Just file", Type: search.TextRequest, Query: `file:\.go$`, - WantZoektOutput: `file_regex:"(?m:\\.go$)"`, + WantZoektOutput: autogold.Expect(`file_regex:"\\.go(?m:$)"`), }, { Name: "Languages get passed as file filter", Type: search.TextRequest, Query: `file:\.go$ lang:go`, - WantZoektOutput: `(and file_regex:"(?m:\\.go$)" file_regex:"(?im:\\.GO$)")`, + WantZoektOutput: autogold.Expect(`(and file_regex:"\\.go(?m:$)" file_regex:"(?i:\\.GO)(?m:$)")`), }, { Name: "Languages still use case_insensitive in case sensitivity mode", Type: search.TextRequest, Query: `file:\.go$ lang:go case:true`, - WantZoektOutput: `(and case_file_regex:"(?m:\\.go$)" case_file_regex:"(?im:\\.GO$)")`, + WantZoektOutput: autogold.Expect(`(and case_file_regex:"\\.go(?m:$)" case_file_regex:"(?i:\\.GO)(?m:$)")`), }, { Name: "Language get passed as lang: query", @@ -98,7 +97,7 @@ func TestQueryToZoektQuery(t *testing.T) { Features: search.Features{ ContentBasedLangFilters: true, }, - WantZoektOutput: `lang:Go`, + WantZoektOutput: autogold.Expect(`lang:Go`), }, { Name: "Multiple languages get passed as lang queries", @@ -107,7 +106,7 @@ func TestQueryToZoektQuery(t *testing.T) { Features: search.Features{ ContentBasedLangFilters: true, }, - WantZoektOutput: `(and lang:Go lang:TypeScript)`, + WantZoektOutput: autogold.Expect(`(and lang:Go lang:TypeScript)`), }, { Name: "Excluded languages get passed as lang: query", @@ -116,7 +115,7 @@ func TestQueryToZoektQuery(t *testing.T) { Features: search.Features{ ContentBasedLangFilters: true, }, - WantZoektOutput: `(and lang:Go (not lang:TypeScript) (not lang:Markdown))`, + WantZoektOutput: autogold.Expect(`(and lang:Go (not lang:TypeScript) (not lang:Markdown))`), }, { Name: "Mixed file and lang filters", @@ -125,7 +124,7 @@ func TestQueryToZoektQuery(t *testing.T) { Features: search.Features{ ContentBasedLangFilters: true, }, - WantZoektOutput: `(and lang:Go lang:TypeScript file_regex:"(?m:\\.go$)")`, + WantZoektOutput: autogold.Expect(`(and lang:Go lang:TypeScript file_regex:"\\.go(?m:$)")`), }, } for _, tt := range cases { @@ -140,10 +139,7 @@ func TestQueryToZoektQuery(t *testing.T) { t.Fatal("QueryToZoektQuery failed:", err) } - queryStr := got.String() - if diff := cmp.Diff(tt.WantZoektOutput, queryStr); diff != "" { - t.Errorf("mismatched queries during [%s] (-want +got):\n%s", tt.Name, diff) - } + tt.WantZoektOutput.Equal(t, got.String()) }) } }