Repository: GoogleCloudPlatform/magic-modules
Pull request #13958: Combine all post replay templates into one
Author: login: trodge
Labels: name: service/accesscontextmanager
Created: 2025-05-14T22:00:46Z | Merged: 2025-05-21T21:13:50Z

<!--
Complete the self-review checklist to help speed up the review process: https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/

If your PR is still work in progress, please create it in draft mode.

Put a description of what this PR is for here, along with any references to issues that this resolves or contributes to.
For example: Fixes https://github.com/hashicorp/terraform-provider-google/issues/ISSUE_ID
-->
fixes https://github.com/hashicorp/terraform-provider-google/issues/19675

**Release Note Template for Downstream PRs (will be copied)**

See [Write release notes](https://googlecloudplatform.github.io/magic-modules/contribute/release-notes/) for guidance.

```release-note:none

```



Diff:
diff --git a/.ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl b/.ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl
deleted file mode 100644
index 9efae64310a5..000000000000
--- a/.ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl
+++ /dev/null
@@ -1,13 +0,0 @@
-{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0)}}
-#### Non-exercised tests
-
-{{if gt (len .NotRunBetaTests) 0 -}}
-{{color "red" "Tests were added that are skipped in VCR:"}}
-{{range .NotRunBetaTests}}{{. | printf "- %s\n"}}{{end}}
-{{end}}
-
-{{if gt (len .NotRunGATests) 0 -}}
-{{color "red" "Tests were added that are GA-only additions and require manual runs:"}}
-{{range .NotRunGATests}}{{. | printf "- %s\n"}}{{end}}
-{{end}}
-{{end}}
diff --git a/.ci/magician/cmd/templates/vcr/post_replay.tmpl b/.ci/magician/cmd/templates/vcr/post_replay.tmpl
new file mode 100644
index 000000000000..e89973cca41e
--- /dev/null
+++ b/.ci/magician/cmd/templates/vcr/post_replay.tmpl
@@ -0,0 +1,55 @@
+{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0)}}
+#### Non-exercised tests
+
+{{if gt (len .NotRunBetaTests) 0 -}}
+{{color "red" "Tests were added that are skipped in VCR:"}}
+{{range .NotRunBetaTests}}{{. | printf "- %s\n"}}{{end}}
+{{end}}
+
+{{if gt (len .NotRunGATests) 0 -}}
+{{color "red" "Tests were added that are GA-only additions and require manual runs:"}}
+{{range .NotRunGATests}}{{. | printf "- %s\n"}}{{end}}
+{{end}}
+{{end}}
+#### Tests analytics
+Total tests: {{add (add (len .ReplayingResult.PassedTests) (len .ReplayingResult.SkippedTests)) (len .ReplayingResult.FailedTests) }}
+Passed tests: {{len .ReplayingResult.PassedTests}}
+Skipped tests: {{len .ReplayingResult.SkippedTests}}
+Affected tests: {{len .ReplayingResult.FailedTests}}
+
+<details>
+<summary>Click here to see the affected service packages</summary>
+<blockquote>
+{{if .RunFullVCR}}
+All service packages are affected
+{{else if gt (len .AffectedServices) 0}}
+<ul>
+{{range .AffectedServices}}{{. | printf "<li>%s</li>\n"}}{{end}}
+</ul>
+{{else}}
+None
+{{end}}
+</blockquote>
+</details>
+{{ if gt (len .ReplayingResult.FailedTests) 0 -}}
+#### Action taken
+<details>
+<summary>Found {{len .ReplayingResult.FailedTests}} affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
+</summary>
+<blockquote>
+<ul>
+{{range .ReplayingResult.FailedTests}}{{. | printf "<li>%s</li>\n"}}{{end}}
+</ul>
+</blockquote>
+</details>
+
+[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
+{{ else -}}
+{{- if .ReplayingErr -}}
+{{color "red" "Errors occurred during REPLAYING mode. Please fix them to complete your PR."}}
+{{- else -}}
+{{color "green" "All tests passed!"}}
+{{- end}}
+
+View the [build log](https://storage.cloud.google.com/{{.LogBucket}}/{{.Version}}/refs/heads/{{.Head}}/artifacts/{{.BuildID}}/build-log/replaying_test.log)
+{{- end}}
\ No newline at end of file
diff --git a/.ci/magician/cmd/templates/vcr/test_analytics.tmpl b/.ci/magician/cmd/templates/vcr/test_analytics.tmpl
deleted file mode 100644
index 9c4006541946..000000000000
--- a/.ci/magician/cmd/templates/vcr/test_analytics.tmpl
+++ /dev/null
@@ -1,20 +0,0 @@
-#### Tests analytics
-Total tests: {{add (add (len .ReplayingResult.PassedTests) (len .ReplayingResult.SkippedTests)) (len .ReplayingResult.FailedTests) }}
-Passed tests: {{len .ReplayingResult.PassedTests}}
-Skipped tests: {{len .ReplayingResult.SkippedTests}}
-Affected tests: {{len .ReplayingResult.FailedTests}}
-
-<details>
-<summary>Click here to see the affected service packages</summary>
-<blockquote>
-{{if .RunFullVCR}}
-All service packages are affected
-{{else if gt (len .AffectedServices) 0}}
-<ul>
-{{range .AffectedServices}}{{. | printf "<li>%s</li>\n"}}{{end}}
-</ul>
-{{else}}
-None
-{{end}}
-</blockquote>
-</details>
diff --git a/.ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl b/.ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl
deleted file mode 100644
index d6d14bb4175f..000000000000
--- a/.ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl
+++ /dev/null
@@ -1,12 +0,0 @@
-#### Action taken
-<details>
-<summary>Found {{len .ReplayingResult.FailedTests}} affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
-</summary>
-<blockquote>
-<ul>
-{{range .ReplayingResult.FailedTests}}{{. | printf "<li>%s</li>\n"}}{{end}}
-</ul>
-</blockquote>
-</details>
-
-[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
diff --git a/.ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl b/.ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl
deleted file mode 100644
index 256d1652fc4f..000000000000
--- a/.ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl
+++ /dev/null
@@ -1,7 +0,0 @@
-{{- if .ReplayingErr -}}
-{{color "red" "Errors occurred during REPLAYING mode. Please fix them to complete your PR."}}
-{{- else -}}
-{{color "green" "All tests passed!"}}
-{{- end}}
-
-View the [build log](https://storage.cloud.google.com/{{.LogBucket}}/{{.Version}}/refs/heads/{{.Head}}/artifacts/{{.BuildID}}/build-log/replaying_test.log)
diff --git a/.ci/magician/cmd/test_eap_vcr.go b/.ci/magician/cmd/test_eap_vcr.go
index 867c1a7ac800..7534814914c7 100644
--- a/.ci/magician/cmd/test_eap_vcr.go
+++ b/.ci/magician/cmd/test_eap_vcr.go
@@ -141,29 +141,23 @@ func execTestEAPVCR(changeNumber, genPath, kokoroArtifactsDir, modifiedFilePath
 	for s := range services {
 		servicesArr = append(servicesArr, s)
 	}
-	analyticsData := analytics{
-		ReplayingResult:  replayingResult,
+	postReplayData := postReplay{
 		RunFullVCR:       runFullVCR,
 		AffectedServices: sort.StringSlice(servicesArr),
+		ReplayingResult:  replayingResult,
+		ReplayingErr:     replayingErr,
+		LogBucket:        "ci-vcr-logs",
+		Version:          provider.Private.String(),
+		Head:             head,
 	}
-	testsAnalyticsComment, err := formatTestsAnalytics(analyticsData)
+	comment, err := formatPostReplay(postReplayData)
 	if err != nil {
-		return fmt.Errorf("error formatting test_analytics comment: %w", err)
+		return fmt.Errorf("error formatting post replay comment: %w", err)
+	}
+	if err := postGerritComment(kokoroArtifactsDir, modifiedFilePath, comment, rnr); err != nil {
+		return fmt.Errorf("error posting comment: %w", err)
 	}
 	if len(replayingResult.FailedTests) > 0 {
-		withReplayFailedTestsData := withReplayFailedTests{
-			ReplayingResult: replayingResult,
-		}
-
-		withReplayFailedTestsComment, err := formatWithReplayFailedTests(withReplayFailedTestsData)
-		if err != nil {
-			return fmt.Errorf("error formatting action taken comment: %w", err)
-		}
-		comment := strings.Join([]string{testsAnalyticsComment, withReplayFailedTestsComment}, "\n")
-		if err := postGerritComment(kokoroArtifactsDir, modifiedFilePath, comment, rnr); err != nil {
-			return fmt.Errorf("error posting comment: %w", err)
-		}
-
 		recordingResult, recordingErr := vt.RunParallel(vcr.RunOptions{
 			Mode:     vcr.Recording,
 			Version:  provider.Private,
@@ -222,18 +216,6 @@ func execTestEAPVCR(changeNumber, genPath, kokoroArtifactsDir, modifiedFilePath
 		if err := postGerritComment(kokoroArtifactsDir, modifiedFilePath, recordReplayComment, rnr); err != nil {
 			return fmt.Errorf("error posting comment: %w", err)
 		}
-	} else { //  len(replayingResult.FailedTests) == 0
-		withoutReplayFailedTestsData := withoutReplayFailedTests{
-			ReplayingErr: replayingErr,
-		}
-		withoutReplayFailedTestsComment, err := formatWithoutReplayFailedTests(withoutReplayFailedTestsData)
-		if err != nil {
-			return fmt.Errorf("error formatting action taken comment: %w", err)
-		}
-		comment := strings.Join([]string{testsAnalyticsComment, withoutReplayFailedTestsComment}, "\n")
-		if err := postGerritComment(kokoroArtifactsDir, modifiedFilePath, comment, rnr); err != nil {
-			return fmt.Errorf("error posting comment: %w", err)
-		}
 	}
 	return nil
 }
diff --git a/.ci/magician/cmd/test_terraform_vcr.go b/.ci/magician/cmd/test_terraform_vcr.go
index 3dd30d9a3d1d..4c12b8b5755f 100644
--- a/.ci/magician/cmd/test_terraform_vcr.go
+++ b/.ci/magician/cmd/test_terraform_vcr.go
@@ -21,14 +21,8 @@ import (
 )
 
 var (
-	//go:embed templates/vcr/test_analytics.tmpl
-	testsAnalyticsTmplText string
-	//go:embed templates/vcr/non_exercised_tests.tmpl
-	nonExercisedTestsTmplText string
-	//go:embed templates/vcr/with_replay_failed_tests.tmpl
-	withReplayFailedTestsTmplText string
-	//go:embed templates/vcr/without_replay_failed_tests.tmpl
-	withoutReplayFailedTestsTmplText string
+	//go:embed templates/vcr/post_replay.tmpl
+	postReplayTmplText string
 	//go:embed templates/vcr/record_replay.tmpl
 	recordReplayTmplText string
 )
@@ -60,27 +54,17 @@ var ttvOptionalEnvironmentVariables = [...]string{
 	"GOOGLE_VMWAREENGINE_PROJECT",
 }
 
-type analytics struct {
-	ReplayingResult  vcr.Result
+type postReplay struct {
 	RunFullVCR       bool
 	AffectedServices []string
-}
-
-type nonExercisedTests struct {
-	NotRunBetaTests []string
-	NotRunGATests   []string
-}
-
-type withReplayFailedTests struct {
-	ReplayingResult vcr.Result
-}
-
-type withoutReplayFailedTests struct {
-	ReplayingErr error
-	LogBucket    string
-	Version      string
-	Head         string
-	BuildID      string
+	NotRunBetaTests  []string
+	NotRunGATests    []string
+	ReplayingResult  vcr.Result
+	ReplayingErr     error
+	LogBucket        string
+	Version          string
+	Head             string
+	BuildID          string
 }
 
 type recordReplay struct {
@@ -249,41 +233,29 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
 	for s := range services {
 		servicesArr = append(servicesArr, s)
 	}
-	analyticsData := analytics{
-		ReplayingResult:  replayingResult,
+
+	notRunBeta, notRunGa := notRunTests(tpgRepo.UnifiedZeroDiff, tpgbRepo.UnifiedZeroDiff, replayingResult)
+	postReplayData := postReplay{
 		RunFullVCR:       runFullVCR,
 		AffectedServices: sort.StringSlice(servicesArr),
+		NotRunBetaTests:  notRunBeta,
+		NotRunGATests:    notRunGa,
+		ReplayingResult:  replayingResult,
+		ReplayingErr:     replayingErr,
+		LogBucket:        "ci-vcr-logs",
+		Version:          provider.Beta.String(),
+		Head:             newBranch,
+		BuildID:          buildID,
 	}
-	testsAnalyticsComment, err := formatTestsAnalytics(analyticsData)
-	if err != nil {
-		return fmt.Errorf("error formatting test_analytics comment: %w", err)
-	}
-
-	notRunBeta, notRunGa := notRunTests(tpgRepo.UnifiedZeroDiff, tpgbRepo.UnifiedZeroDiff, replayingResult)
 
-	nonExercisedTestsData := nonExercisedTests{
-		NotRunBetaTests: notRunBeta,
-		NotRunGATests:   notRunGa,
-	}
-	nonExercisedTestsComment, err := formatNonExercisedTests(nonExercisedTestsData)
+	comment, err := formatPostReplay(postReplayData)
 	if err != nil {
-		return fmt.Errorf("error formatting non exercised tests comment: %w", err)
+		return fmt.Errorf("error formatting post replay comment: %w", err)
+	}
+	if err := gh.PostComment(prNumber, comment); err != nil {
+		return fmt.Errorf("error posting comment: %w", err)
 	}
-
 	if len(replayingResult.FailedTests) > 0 {
-		withReplayFailedTestsData := withReplayFailedTests{
-			ReplayingResult: replayingResult,
-		}
-		withReplayFailedTestsComment, err := formatWithReplayFailedTests(withReplayFailedTestsData)
-		if err != nil {
-			return fmt.Errorf("error formatting action taken comment: %w", err)
-		}
-
-		comment := strings.Join([]string{testsAnalyticsComment, nonExercisedTestsComment, withReplayFailedTestsComment}, "\n")
-		if err := gh.PostComment(prNumber, comment); err != nil {
-			return fmt.Errorf("error posting comment: %w", err)
-		}
-
 		recordingResult, recordingErr := vt.RunParallel(vcr.RunOptions{
 			Mode:     vcr.Recording,
 			Version:  provider.Beta,
@@ -363,24 +335,6 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
 		if err := gh.PostComment(prNumber, recordReplayComment); err != nil {
 			return fmt.Errorf("error posting comment: %w", err)
 		}
-
-	} else { //  len(replayingResult.FailedTests) == 0
-		withoutReplayFailedTestsData := withoutReplayFailedTests{
-			ReplayingErr: replayingErr,
-			LogBucket:    "ci-vcr-logs",
-			Version:      provider.Beta.String(),
-			Head:         newBranch,
-			BuildID:      buildID,
-		}
-		withoutReplayFailedTestsComment, err := formatWithoutReplayFailedTests(withoutReplayFailedTestsData)
-		if err != nil {
-			return fmt.Errorf("error formatting action taken comment: %w", err)
-		}
-
-		comment := strings.Join([]string{testsAnalyticsComment, nonExercisedTestsComment, withoutReplayFailedTestsComment}, "\n")
-		if err := gh.PostComment(prNumber, comment); err != nil {
-			return fmt.Errorf("error posting comment: %w", err)
-		}
 	}
 
 	if err := gh.PostBuildStatus(prNumber, "VCR-test", testState, buildStatusTargetURL, mmCommitSha); err != nil {
@@ -530,20 +484,8 @@ func formatComment(fileName string, tmplText string, data any) (string, error) {
 	return strings.TrimSpace(sb.String()), nil
 }
 
-func formatTestsAnalytics(data analytics) (string, error) {
-	return formatComment("test_analytics.tmpl", testsAnalyticsTmplText, data)
-}
-
-func formatNonExercisedTests(data nonExercisedTests) (string, error) {
-	return formatComment("non_exercised_tests.tmpl", nonExercisedTestsTmplText, data)
-}
-
-func formatWithReplayFailedTests(data withReplayFailedTests) (string, error) {
-	return formatComment("with_replay_failed_tests.tmpl", withReplayFailedTestsTmplText, data)
-}
-
-func formatWithoutReplayFailedTests(data withoutReplayFailedTests) (string, error) {
-	return formatComment("without_replay_failed_tests.tmpl", withoutReplayFailedTestsTmplText, data)
+func formatPostReplay(data postReplay) (string, error) {
+	return formatComment("post_replay.tmpl", postReplayTmplText, data)
 }
 
 func formatRecordReplay(data recordReplay) (string, error) {
diff --git a/.ci/magician/cmd/test_terraform_vcr_test.go b/.ci/magician/cmd/test_terraform_vcr_test.go
index cf7e4b019327..835d9d302d32 100644
--- a/.ci/magician/cmd/test_terraform_vcr_test.go
+++ b/.ci/magician/cmd/test_terraform_vcr_test.go
@@ -6,7 +6,6 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/google/go-cmp/cmp"
 	"github.com/stretchr/testify/assert"
 
 	"magician/provider"
@@ -220,13 +219,13 @@ func TestNotRunTests(t *testing.T) {
 
 func TestAnalyticsComment(t *testing.T) {
 	tests := []struct {
-		name string
-		data analytics
-		want string
+		name         string
+		data         postReplay
+		wantContains []string
 	}{
 		{
 			name: "run full vcr is false and no affected services",
-			data: analytics{
+			data: postReplay{
 				ReplayingResult: vcr.Result{
 					PassedTests:  []string{"a", "b", "c"},
 					SkippedTests: []string{"d", "e"},
@@ -235,29 +234,26 @@ func TestAnalyticsComment(t *testing.T) {
 				RunFullVCR:       false,
 				AffectedServices: []string{},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Tests analytics",
-					"Total tests: 6",
-					"Passed tests: 3",
-					"Skipped tests: 2",
-					"Affected tests: 1",
-					"",
-					"<details>",
-					"<summary>Click here to see the affected service packages</summary>",
-					"<blockquote>",
-					"",
-					"None",
-					"",
-					"</blockquote>",
-					"</details>",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Tests analytics",
+				"Total tests: 6",
+				"Passed tests: 3",
+				"Skipped tests: 2",
+				"Affected tests: 1",
+				"",
+				"<details>",
+				"<summary>Click here to see the affected service packages</summary>",
+				"<blockquote>",
+				"",
+				"None",
+				"",
+				"</blockquote>",
+				"</details>",
+			},
 		},
 		{
 			name: "run full vcr is false and has affected services",
-			data: analytics{
+			data: postReplay{
 				ReplayingResult: vcr.Result{
 					PassedTests:  []string{"a", "b", "c"},
 					SkippedTests: []string{"d", "e"},
@@ -266,33 +262,30 @@ func TestAnalyticsComment(t *testing.T) {
 				RunFullVCR:       false,
 				AffectedServices: []string{"svc-a", "svc-b"},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Tests analytics",
-					"Total tests: 6",
-					"Passed tests: 3",
-					"Skipped tests: 2",
-					"Affected tests: 1",
-					"",
-					"<details>",
-					"<summary>Click here to see the affected service packages</summary>",
-					"<blockquote>",
-					"",
-					"<ul>",
-					"<li>svc-a</li>",
-					"<li>svc-b</li>",
-					"",
-					"</ul>",
-					"",
-					"</blockquote>",
-					"</details>",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Tests analytics",
+				"Total tests: 6",
+				"Passed tests: 3",
+				"Skipped tests: 2",
+				"Affected tests: 1",
+				"",
+				"<details>",
+				"<summary>Click here to see the affected service packages</summary>",
+				"<blockquote>",
+				"",
+				"<ul>",
+				"<li>svc-a</li>",
+				"<li>svc-b</li>",
+				"",
+				"</ul>",
+				"",
+				"</blockquote>",
+				"</details>",
+			},
 		},
 		{
 			name: "run full vcr is true",
-			data: analytics{
+			data: postReplay{
 				ReplayingResult: vcr.Result{
 					PassedTests:  []string{"a", "b", "c"},
 					SkippedTests: []string{"d", "e"},
@@ -301,7 +294,7 @@ func TestAnalyticsComment(t *testing.T) {
 				RunFullVCR:       true,
 				AffectedServices: []string{},
 			},
-			want: strings.Join([]string{
+			wantContains: []string{
 				"#### Tests analytics",
 				"Total tests: 6",
 				"Passed tests: 3",
@@ -317,18 +310,18 @@ func TestAnalyticsComment(t *testing.T) {
 				"</blockquote>",
 				"</details>",
 			},
-				"\n",
-			),
 		},
 	}
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			got, err := formatTestsAnalytics(tc.data)
+			got, err := formatPostReplay(tc.data)
 			if err != nil {
 				t.Fatalf("Failed to format comment: %v", err)
 			}
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("formatTestsAnalytics() returned unexpected difference (-want +got):\n%s", diff)
+			for _, wc := range tc.wantContains {
+				if !strings.Contains(got, wc) {
+					t.Errorf("formatPostReplay() returned %q, which does not contain %q", got, wc)
+				}
 			}
 		})
 	}
@@ -336,84 +329,69 @@ func TestAnalyticsComment(t *testing.T) {
 
 func TestNonExercisedTestsComment(t *testing.T) {
 	tests := []struct {
-		name string
-		data nonExercisedTests
-		want string
+		name         string
+		data         postReplay
+		wantContains []string
 	}{
-		{
-			name: "without non exercised tests",
-			data: nonExercisedTests{},
-			want: strings.Join(
-				[]string{},
-				"\n",
-			),
-		},
 		{
 			name: "with not run beta tests",
-			data: nonExercisedTests{
+			data: postReplay{
 				NotRunBetaTests: []string{"beta-1", "beta-2"},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Non-exercised tests",
-					"",
-					color("red", "Tests were added that are skipped in VCR:"),
-					"- beta-1",
-					"- beta-2",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Non-exercised tests",
+				"",
+				color("red", "Tests were added that are skipped in VCR:"),
+				"- beta-1",
+				"- beta-2",
+			},
 		},
 		{
 			name: "with not run ga tests",
-			data: nonExercisedTests{
+			data: postReplay{
 				NotRunGATests: []string{"ga-1", "ga-2"},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Non-exercised tests",
-					"",
-					"",
-					"",
-					color("red", "Tests were added that are GA-only additions and require manual runs:"),
-					"- ga-1",
-					"- ga-2",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Non-exercised tests",
+				"",
+				"",
+				"",
+				color("red", "Tests were added that are GA-only additions and require manual runs:"),
+				"- ga-1",
+				"- ga-2",
+			},
 		},
 		{
 			name: "with not run ga tests and not run beta tests",
-			data: nonExercisedTests{
+			data: postReplay{
 				NotRunGATests:   []string{"ga-1", "ga-2"},
 				NotRunBetaTests: []string{"beta-1", "beta-2"},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Non-exercised tests",
-					"",
-					color("red", "Tests were added that are skipped in VCR:"),
-					"- beta-1",
-					"- beta-2",
-					"",
-					"",
-					"",
-					color("red", "Tests were added that are GA-only additions and require manual runs:"),
-					"- ga-1",
-					"- ga-2",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Non-exercised tests",
+				"",
+				color("red", "Tests were added that are skipped in VCR:"),
+				"- beta-1",
+				"- beta-2",
+				"",
+				"",
+				"",
+				color("red", "Tests were added that are GA-only additions and require manual runs:"),
+				"- ga-1",
+				"- ga-2",
+			},
 		},
 	}
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			got, err := formatNonExercisedTests(tc.data)
+			got, err := formatPostReplay(tc.data)
 			if err != nil {
 				t.Fatalf("Failed to format comment: %v", err)
 			}
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("formatNonExercisedTests() returned unexpected difference (-want +got):\n%s", diff)
+			for _, wc := range tc.wantContains {
+				if !strings.Contains(got, wc) {
+					t.Errorf("formatPostReplay() returned %q, which does not contain %q", got, wc)
+				}
 			}
 		})
 	}
@@ -421,46 +399,45 @@ func TestNonExercisedTestsComment(t *testing.T) {
 
 func TestWithReplayFailedTests(t *testing.T) {
 	tests := []struct {
-		name string
-		data withReplayFailedTests
-		want string
+		name         string
+		data         postReplay
+		wantContains []string
 	}{
 		{
 			name: "with failed tests",
-			data: withReplayFailedTests{
+			data: postReplay{
 				ReplayingResult: vcr.Result{
 					FailedTests: []string{"a", "b"},
 				},
 			},
-			want: strings.Join(
-				[]string{
-					"#### Action taken",
-					"<details>",
-					"<summary>Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests",
-					"</summary>",
-					"<blockquote>",
-					"<ul>",
-					"<li>a</li>",
-					"<li>b</li>",
-					"", // Empty line
-					"</ul>",
-					"</blockquote>",
-					"</details>",
-					"",
-					"[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)",
-				},
-				"\n",
-			),
+			wantContains: []string{
+				"#### Action taken",
+				"<details>",
+				"<summary>Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests",
+				"</summary>",
+				"<blockquote>",
+				"<ul>",
+				"<li>a</li>",
+				"<li>b</li>",
+				"", // Empty line
+				"</ul>",
+				"</blockquote>",
+				"</details>",
+				"",
+				"[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)",
+			},
 		},
 	}
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			got, err := formatWithReplayFailedTests(tc.data)
+			got, err := formatPostReplay(tc.data)
 			if err != nil {
 				t.Fatalf("Failed to format comment: %v", err)
 			}
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("formatWithReplayFailedTests() returned unexpected difference (-want +got):\n%s", diff)
+			for _, wc := range tc.wantContains {
+				if !strings.Contains(got, wc) {
+					t.Errorf("formatPostReplay() returned %q, which does not contain %q", got, wc)
+				}
 			}
 		})
 	}
@@ -469,12 +446,12 @@ func TestWithReplayFailedTests(t *testing.T) {
 func TestWithoutReplayFailedTests(t *testing.T) {
 	tests := []struct {
 		name         string
-		data         withoutReplayFailedTests
+		data         postReplay
 		wantContains []string
 	}{
 		{
 			name: "with replay error",
-			data: withoutReplayFailedTests{
+			data: postReplay{
 				ReplayingErr: fmt.Errorf("some error"),
 				BuildID:      "build-123",
 				Head:         "auto-pr-123",
@@ -488,7 +465,7 @@ func TestWithoutReplayFailedTests(t *testing.T) {
 		},
 		{
 			name: "without replay error",
-			data: withoutReplayFailedTests{
+			data: postReplay{
 				BuildID:   "build-123",
 				Head:      "auto-pr-123",
 				LogBucket: "ci-vcr-logs",
@@ -502,13 +479,13 @@ func TestWithoutReplayFailedTests(t *testing.T) {
 	}
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			got, err := formatWithoutReplayFailedTests(tc.data)
+			got, err := formatPostReplay(tc.data)
 			if err != nil {
 				t.Fatalf("Failed to format comment: %v", err)
 			}
 			for _, wc := range tc.wantContains {
 				if !strings.Contains(got, wc) {
-					t.Errorf("formatWithoutReplayFailedTests() returned %q, which does not contain %q", got, wc)
+					t.Errorf("formatPostReplay() returned %q, which does not contain %q", got, wc)
 				}
 			}
 		})


Reviews:
user: login: melinath
body: a couple small things. could you also make a change to a resource on this PR to exercise the new template? (Or make a global change to trigger a full test run.) here are some always-failing tests: https://github.com/GoogleCloudPlatform/magic-modules/pull/13836#issuecomment-2881983137
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-05-16T18:22:08Z
user: login: melinath
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-20T22:07:20Z

Review comments:
diff_hunk: @@ -141,25 +141,20 @@ func execTestEAPVCR(changeNumber, genPath, kokoroArtifactsDir, modifiedFilePath
 	for s := range services {
 		servicesArr = append(servicesArr, s)
 	}
-	analyticsData := analytics{
-		ReplayingResult:  replayingResult,
+	postReplayData := postReplay{
 		RunFullVCR:       runFullVCR,
 		AffectedServices: sort.StringSlice(servicesArr),
-	}
-	testsAnalyticsComment, err := formatTestsAnalytics(analyticsData)
-	if err != nil {
-		return fmt.Errorf("error formatting test_analytics comment: %w", err)
+		ReplayingResult:  replayingResult,
+		ReplayingErr:     replayingErr,
+		LogBucket:        "ci-vcr-logs",
+		Version:          provider.Private.String(),
+		Head:             head,
 	}
 	if len(replayingResult.FailedTests) > 0 {
-		withReplayFailedTestsData := withReplayFailedTests{
-			ReplayingResult: replayingResult,
-		}
-
-		withReplayFailedTestsComment, err := formatWithReplayFailedTests(withReplayFailedTestsData)
+		comment, err := formatPostReplay(postReplayData)
path: .ci/magician/cmd/test_eap_vcr.go
user: login: melinath
body: Formatting & posting the comment can happen before this if statement, since it's now the same render + post either way.
created_at: 2025-05-16T18:18:00Z
author_association: MEMBER
diff_hunk: @@ -249,37 +233,26 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
 	for s := range services {
 		servicesArr = append(servicesArr, s)
 	}
-	analyticsData := analytics{
-		ReplayingResult:  replayingResult,
-		RunFullVCR:       runFullVCR,
-		AffectedServices: sort.StringSlice(servicesArr),
-	}
-	testsAnalyticsComment, err := formatTestsAnalytics(analyticsData)
-	if err != nil {
-		return fmt.Errorf("error formatting test_analytics comment: %w", err)
-	}
 
 	notRunBeta, notRunGa := notRunTests(tpgRepo.UnifiedZeroDiff, tpgbRepo.UnifiedZeroDiff, replayingResult)
-
-	nonExercisedTestsData := nonExercisedTests{
-		NotRunBetaTests: notRunBeta,
-		NotRunGATests:   notRunGa,
-	}
-	nonExercisedTestsComment, err := formatNonExercisedTests(nonExercisedTestsData)
-	if err != nil {
-		return fmt.Errorf("error formatting non exercised tests comment: %w", err)
+	postReplayData := postReplay{
+		RunFullVCR:       runFullVCR,
+		AffectedServices: sort.StringSlice(servicesArr),
+		NotRunBetaTests:  notRunBeta,
+		NotRunGATests:    notRunGa,
+		ReplayingResult:  replayingResult,
+		ReplayingErr:     replayingErr,
+		LogBucket:        "ci-vcr-logs",
+		Version:          provider.Beta.String(),
+		Head:             newBranch,
+		BuildID:          buildID,
 	}
 
 	if len(replayingResult.FailedTests) > 0 {
-		withReplayFailedTestsData := withReplayFailedTests{
-			ReplayingResult: replayingResult,
-		}
-		withReplayFailedTestsComment, err := formatWithReplayFailedTests(withReplayFailedTestsData)
+		comment, err := formatPostReplay(postReplayData)
path: .ci/magician/cmd/test_terraform_vcr.go
user: login: melinath
body: same here
created_at: 2025-05-16T18:18:13Z
author_association: MEMBER

PR comments:
user: login: modular-magician
created_at: 2025-05-14T22:09:44Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR hasn't generated any diffs, but I'll let you know if a future commit does.





author_association: COLLABORATOR
user: login: trodge
created_at: 2025-05-14T22:45:53Z
body: @modular-magician reassign-reviewer
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-05-14T22:46:50Z
body: Hello! I am a robot. Tests will require approval from a repository maintainer to run. 

**Googlers:** For automatic test runs see go/terraform-auto-test-runs.

@melinath, a repository maintainer, has been assigned to [review your changes](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/). If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by [doing a self-review](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/) and by [running impacted tests locally](https://googlecloudplatform.github.io/magic-modules/get-started/run-provider-tests/).

author_association: NONE
user: login: modular-magician
created_at: 2025-05-16T21:59:22Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR generated some diffs in downstreams - here they are.

`google` provider: [Diff](https://github.com/modular-magician/terraform-provider-google/compare/9286ef1f30dc4e405b00bde38a8798f2f04513f7..d02011c012472277633336a2adfb2740ac51adcc) ( 1 file changed, 2 insertions(+))
`google-beta` provider: [Diff](https://github.com/modular-magician/terraform-provider-google-beta/compare/94a4754544ec3f911b3ac4c8069e5a43cf43ee87..98408618bdbf63729c9bc3fa114a64d0b0310d0e) ( 1 file changed, 2 insertions(+))





author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-05-16T22:06:52Z
body: #### Tests analytics
Total tests: 3
Passed tests: 3
Skipped tests: 0
Affected tests: 0

<details>
<summary>Click here to see the affected service packages</summary>
<blockquote>

<ul>
<li>accesscontextmanager</li>

</ul>

</blockquote>
</details>
🟢 All tests passed!

View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/9a6acb14-c0e2-4445-a2a4-446e5f748e15/build-log/replaying_test.log)
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-05-19T18:01:27Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR generated some diffs in downstreams - here they are.

`google` provider: [Diff](https://github.com/modular-magician/terraform-provider-google/compare/a9c614abff391a8259ae3b4674eea8a095897de6..1b61bb6155241e4fbc59cbd76ae4f161868e4c43) ( 1 file changed, 2 insertions(+))
`google-beta` provider: [Diff](https://github.com/modular-magician/terraform-provider-google-beta/compare/c15bf2bed3f3dec70627ca83140f29ea38301db8..651e38cfc7fde4cf89d8e365d2680960501caacf) ( 1 file changed, 2 insertions(+))





author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-05-19T20:02:07Z
body: #### Tests analytics
Total tests: 4962
Passed tests: 4496
Skipped tests: 461
Affected tests: 5

<details>
<summary>Click here to see the affected service packages</summary>
<blockquote>

All service packages are affected

</blockquote>
</details>
#### Action taken
<details>
<summary>Found 5 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
</summary>
<blockquote>
<ul>
<li>TestAccAccessContextManager</li>
<li>TestAccDataSourceGoogleGkeHubFeature_basic</li>
<li>TestAccDiscoveryEngineChatEngine_discoveryengineChatEngineExistingDialogflowAgentExample</li>
<li>TestAccHealthcarePipelineJob_healthcarePipelineJobBackfillExample</li>
<li>TestAccLoggingFolderSettings_update</li>

</ul>
</blockquote>
</details>

[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-05-19T20:18:59Z
body: 🟢 Tests passed during RECORDING mode:
`TestAccAccessContextManager` [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording/TestAccAccessContextManager.log)]
`TestAccDataSourceGoogleGkeHubFeature_basic` [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording/TestAccDataSourceGoogleGkeHubFeature_basic.log)]


🔴 Tests failed when rerunning REPLAYING mode:
`TestAccDataSourceGoogleGkeHubFeature_basic` [[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/build-log/replaying_build_after_recording/TestAccDataSourceGoogleGkeHubFeature_basic_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/replaying_after_recording/TestAccDataSourceGoogleGkeHubFeature_basic.log)]


Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.

Please fix these to complete your PR. If you believe these test failures to be incorrect or unrelated to your change, or if you have any questions, please raise the concern with your reviewer.


---


🔴 Tests failed during RECORDING mode:
`TestAccDiscoveryEngineChatEngine_discoveryengineChatEngineExistingDialogflowAgentExample` [[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/build-log/recording_build/TestAccDiscoveryEngineChatEngine_discoveryengineChatEngineExistingDialogflowAgentExample_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording/TestAccDiscoveryEngineChatEngine_discoveryengineChatEngineExistingDialogflowAgentExample.log)]
`TestAccHealthcarePipelineJob_healthcarePipelineJobBackfillExample` [[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/build-log/recording_build/TestAccHealthcarePipelineJob_healthcarePipelineJobBackfillExample_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording/TestAccHealthcarePipelineJob_healthcarePipelineJobBackfillExample.log)]
`TestAccLoggingFolderSettings_update` [[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/build-log/recording_build/TestAccLoggingFolderSettings_update_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording/TestAccLoggingFolderSettings_update.log)]



🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.



View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-13958/artifacts/6b0bfb97-6d7a-4992-911c-190ac30e7396/recording) for each test
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-05-20T22:09:31Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR hasn't generated any diffs, but I'll let you know if a future commit does.





author_association: COLLABORATOR