maintner/maintnerd/maintapi: adjust heuristic for tip version

The vast majority of the time, when Go 1.X (or Go 1.X.Y) is the latest
supported Go release, non-release branches are used for developing
the next Go 1.(X+1) version and not the same Go 1.X version.

Adjust the imperfect heuristic used to determine the Go version from
the branch name by taking this into account.

Make the output from the TestFindTryWork test easier to read,
as it's expensive to add test coverage for this change elsewhere.

For golang/go#42341.
Fixes golang/go#42377.
Updates golang/go#42376.

Change-Id: I70b21662f2a4c853d14a0928f8bd7361fc6aafd6
Reviewed-on: https://go-review.googlesource.com/c/build/+/267677
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/maintner/maintnerd/maintapi/api.go b/maintner/maintnerd/maintapi/api.go
index 74e7b28..f68beee 100644
--- a/maintner/maintnerd/maintapi/api.go
+++ b/maintner/maintnerd/maintapi/api.go
@@ -249,6 +249,11 @@
 	if err != nil {
 		return nil, err
 	}
+	// If Go X.Y is the latest supported release, the version in development is likely Go X.(Y+1).
+	develVersion := &apipb.MajorMinor{
+		Major: supportedReleases[0].Major,
+		Minor: supportedReleases[0].Minor + 1,
+	}
 
 	res := new(apipb.GoFindTryWorkResponse)
 	for _, ci := range cis {
@@ -264,26 +269,23 @@
 		work := tryWorkItem(cl, ci, comments)
 		if work.Project == "go" {
 			// Trybot on Go repo. Set the GoVersion field based on branch name.
-			if work.Branch == "master" {
-				latest := supportedReleases[0]
-				work.GoVersion = []*apipb.MajorMinor{{latest.Major, latest.Minor}}
-			} else if major, minor, ok := parseReleaseBranchVersion(work.Branch); ok {
+			if major, minor, ok := parseReleaseBranchVersion(work.Branch); ok {
 				// A release branch like release-branch.goX.Y.
 				// Use the major-minor Go version determined from the branch name.
 				work.GoVersion = []*apipb.MajorMinor{{major, minor}}
 			} else {
-				// A branch that is neither master nor release-branch.goX.Y.
-				// I don't see a straightforward way to compute its version,
-				// so use the latest Go release until we need to do more.
-				latest := supportedReleases[0]
-				work.GoVersion = []*apipb.MajorMinor{{latest.Major, latest.Minor}}
+				// A branch that is not release-branch.goX.Y: maybe
+				// "master" or a development branch like "dev.link".
+				// There isn't a way to determine the version from its name,
+				// so use the development Go version until we need to do more.
+				// TODO(golang.org/issue/42376): This can be made more precise.
+				work.GoVersion = []*apipb.MajorMinor{develVersion}
 			}
 		} else {
 			// Trybot on a subrepo. Set the Go fields to master and the supported releases.
 			work.GoCommit = []string{goProj.Ref("refs/heads/master").String()}
 			work.GoBranch = []string{"master"}
-			latest := supportedReleases[0]
-			work.GoVersion = []*apipb.MajorMinor{{latest.Major, latest.Minor}}
+			work.GoVersion = []*apipb.MajorMinor{develVersion}
 			for _, r := range supportedReleases {
 				work.GoCommit = append(work.GoCommit, r.BranchCommit)
 				work.GoBranch = append(work.GoBranch, r.BranchName)
diff --git a/maintner/maintnerd/maintapi/api_test.go b/maintner/maintnerd/maintapi/api_test.go
index 2c7b429..93d16f8 100644
--- a/maintner/maintnerd/maintapi/api_test.go
+++ b/maintner/maintnerd/maintapi/api_test.go
@@ -14,6 +14,7 @@
 	"testing"
 	"time"
 
+	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"golang.org/x/build/gerrit"
 	"golang.org/x/build/maintner"
@@ -61,7 +62,7 @@
 
 func TestFindTryWork(t *testing.T) {
 	if !*hitGerrit {
-		t.Skip("skipping without flag --hit_gerrit")
+		t.Skip("skipping without flag -hit_gerrit")
 	}
 	c := getGoData(t)
 	s := apiService{c}
@@ -75,13 +76,13 @@
 
 	// Just for interactive debugging. This is using live data.
 	// The stable tests are in TestTryWorkItem and TestTryBotStatus.
-	t.Logf("Current: %v", res)
+	t.Logf("Current:\n%v", proto.MarshalTextString(res))
 
 	t1 := time.Now()
-	res, err = s.GoFindTryWork(context.Background(), req)
+	res2, err := s.GoFindTryWork(context.Background(), req)
 	d1 := time.Since(t1)
 	t.Logf("Latency: %v, then %v", d0, d1)
-	t.Logf("Cached: %v, %v", res, err)
+	t.Logf("Cached: equal=%v, err=%v", proto.Equal(res, res2), err)
 }
 
 func TestTryBotStatus(t *testing.T) {