From cfc9553f8497ac318556ed2d2e4f439a69e5963a Mon Sep 17 00:00:00 2001 From: Xiaoyang Tan Date: Wed, 27 May 2026 16:42:56 -0700 Subject: [PATCH 1/2] Export GetReqsHash for external use --- core/common/utils.go | 8 ++++---- core/common/utils_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/common/utils.go b/core/common/utils.go index a89ba87..43020a8 100644 --- a/core/common/utils.go +++ b/core/common/utils.go @@ -56,14 +56,14 @@ func ToShortRemote(remote string) string { // requestOptions is folded into the key when any of its fields affect computation // (today: extra_exclude_files_regex). Empty/nil ⇒ legacy path unchanged. func GetGraphByTreeHash(remote, treehash string, requestOptions *tangopb.RequestOptions) string { - return filepath.Join(ToShortRemote(remote), treehash) + HashRequestOptions(requestOptions) + return filepath.Join("graph", ToShortRemote(remote), treehash) + HashRequestOptions(requestOptions) } // GetTreehashCachePath returns the cache path for the treehash mapping. // The git treehash is purely a function of git state, so requestOptions is not // part of this key. func GetTreehashCachePath(buildDescription *tangopb.BuildDescription) string { - return filepath.Join(ToShortRemote(buildDescription.Remote), fmt.Sprintf("treehash-map-%s", buildDescription.BaseSha), getReqsHash(buildDescription.Requests)) + "-" + buildDescription.Strategy.String() + return filepath.Join("treehash", ToShortRemote(buildDescription.Remote), fmt.Sprintf("treehash-map-%s", buildDescription.BaseSha), GetReqsHash(buildDescription.Requests)) + "-" + buildDescription.Strategy.String() } // GetComparedTargetsCachePath returns the cache path for a compared target graph result. @@ -84,10 +84,10 @@ func GetChangedTargetsAndEdgesCachePath(remote, treehash1, treehash2 string, req return filepath.Join("compared-targets-and-edges", ToShortRemote(remote), treehash1, treehash2) + HashRequestOptions(requestOptions) } -// getReqsHash returns a fixed-length MD5 hash of the sorted request URLs. +// GetReqsHash returns a fixed-length MD5 hash of the sorted request URLs. // Each URL's bytes are fed into the digest individually (no separator), matching // the Java MessageDigest.update(str.getBytes()) per-string behavior. -func getReqsHash(requests []*tangopb.Request) string { +func GetReqsHash(requests []*tangopb.Request) string { if len(requests) == 0 { return "" } diff --git a/core/common/utils_test.go b/core/common/utils_test.go index 8c82afc..b04ea4e 100644 --- a/core/common/utils_test.go +++ b/core/common/utils_test.go @@ -136,7 +136,7 @@ func TestGetReqsHash(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, getReqsHash(tt.in)) + assert.Equal(t, tt.want, GetReqsHash(tt.in)) }) } } From 9f024b710e46313b7efb7f77edab8508b9ef2999 Mon Sep 17 00:00:00 2001 From: Xiaoyang Tan Date: Wed, 27 May 2026 17:56:11 -0700 Subject: [PATCH 2/2] Fix test expectations for graph/ and treehash/ path prefixes --- core/common/utils_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/common/utils_test.go b/core/common/utils_test.go index b04ea4e..f79ac29 100644 --- a/core/common/utils_test.go +++ b/core/common/utils_test.go @@ -64,7 +64,7 @@ func TestGetGraphByTreeHash(t *testing.T) { // Nil/empty options ⇒ legacy path (regression: cache compatibility). got := GetGraphByTreeHash(remote, treehash, nil) - assert.Equal(t, filepath.Join("uber/tango", treehash), got) + assert.Equal(t, filepath.Join("graph", "uber/tango", treehash), got) assert.Equal(t, got, GetGraphByTreeHash(remote, treehash, &pb.RequestOptions{})) // Non-empty options ⇒ suffix appended; different lists ⇒ different keys. @@ -94,7 +94,7 @@ func TestGetTreehashCachePath(t *testing.T) { h := md5.New() h.Write([]byte("custom://foo/bar")) h.Write([]byte("github://org/repo/pull/1")) - want := filepath.Join("uber/tango", "treehash-map-deadbeef", fmt.Sprintf("%x", h.Sum(nil))) + "-" + pb.COMPUTATION_STRATEGY_INVALID.String() + want := filepath.Join("treehash", "uber/tango", "treehash-map-deadbeef", fmt.Sprintf("%x", h.Sum(nil))) + "-" + pb.COMPUTATION_STRATEGY_INVALID.String() assert.Equal(t, want, got) }