Skip to content

Commit cb8bc62

Browse files
authored
Merge pull request #405 from CircleCI-Public/fix-build-prompt-acceptance
Prevent fixture dates from going stale and breaking acceptance tests
2 parents b5c9dae + cb5670b commit cb8bc62

2 files changed

Lines changed: 62 additions & 37 deletions

File tree

internal/github/github_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,17 @@ func TestFetchReviewActivity(t *testing.T) {
205205

206206
t.Run("since filter", func(t *testing.T) {
207207
gh.SetReviewActivity("since-repo", fixtures.MultiReviewerResponse())
208-
// Set since between PR 100 reviews (2026-03-01T01-03) and PR 101 reviews (2026-03-02T01-02).
209-
// PR 100's updatedAt is 2026-03-01T00:00:00Z which is before since, so the
210-
// function will return early after processing PR 100 (which has no reviews/comments after since).
211-
// PR 101's updatedAt is 2026-03-02T00:00:00Z — but the fixture lists PR 100 first.
212-
// The early return means only PR 100 is seen; its reviews are all before since.
213-
since := time.Date(2026, 3, 1, 23, 0, 0, 0, time.UTC)
208+
// The fixture lists PR 100 first (updatedAt ~30 days ago) then PR 101 (~25 days ago).
209+
// Setting since to tomorrow means PR 100's updatedAt is before since, triggering
210+
// an early return before any reviews are processed.
211+
since := time.Now().AddDate(0, 0, 1)
214212
result, err := c.FetchReviewActivity(context.Background(), "org", "since-repo", since)
215213
if err != nil {
216214
t.Fatalf("unexpected error: %v", err)
217215
}
218216

219-
// PR 100 (first in fixture) has updatedAt=2026-03-01T00:00:00Z which is before since,
220-
// so the function returns early with no activity (reviews at T01-T03 are all before since too).
217+
// PR 100 (first in fixture) has updatedAt ~30 days ago, which is before since (tomorrow),
218+
// so the function returns early with no activity.
221219
if len(result.Activity) != 0 {
222220
t.Errorf("expected 0 reviewers (early return), got %d", len(result.Activity))
223221
}

internal/testing/fixtures/github.go

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package fixtures
22

3+
import "time"
4+
5+
// recentDate returns an RFC3339 timestamp offset from the current time,
6+
// keeping fixture dates within the default 3-month --since window.
7+
func recentDate(daysAgo int) string {
8+
return time.Now().AddDate(0, 0, -daysAgo).UTC().Format(time.RFC3339)
9+
}
10+
311
// OrgValidationResponse returns a successful org validation response.
412
func OrgValidationResponse(org string) string {
513
return `{
@@ -41,7 +49,12 @@ func OrgReposResponse(repoNames ...string) string {
4149
}
4250

4351
// ReviewActivityResponse returns a response with one PR containing review comments.
52+
// Dates are generated relative to now so they always fall within the default 3-month --since window.
4453
func ReviewActivityResponse() string {
54+
d0 := recentDate(30)
55+
d1 := recentDate(29)
56+
d2 := recentDate(28)
57+
d3 := recentDate(27)
4558
return `{
4659
"data": {
4760
"repository": {
@@ -52,12 +65,12 @@ func ReviewActivityResponse() string {
5265
"title": "Add feature X",
5366
"url": "https://github.com/test-org/test-repo/pull/42",
5467
"state": "MERGED",
55-
"updatedAt": "2026-03-01T00:00:00Z",
68+
"updatedAt": "` + d0 + `",
5669
"author": {"login": "pr-author"},
5770
"reviews": {
5871
"nodes": [
59-
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "2026-03-01T01:00:00Z"},
60-
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "2026-03-01T02:00:00Z"}
72+
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "` + d1 + `"},
73+
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "` + d2 + `"}
6174
]
6275
},
6376
"reviewThreads": {
@@ -69,7 +82,7 @@ func ReviewActivityResponse() string {
6982
"author": {"login": "reviewer-alice"},
7083
"body": "Consider using early return here to reduce nesting",
7184
"diffHunk": "@@ -1,3 +1,5 @@\n func foo() {\n+ if err != nil {\n+ return err\n+ }",
72-
"createdAt": "2026-03-01T01:00:00Z"
85+
"createdAt": "` + d1 + `"
7386
}
7487
]
7588
}
@@ -81,7 +94,7 @@ func ReviewActivityResponse() string {
8194
"author": {"login": "reviewer-bob"},
8295
"body": "This needs error handling for the nil case",
8396
"diffHunk": "@@ -10,3 +12,5 @@\n resp, err := client.Do(req)",
84-
"createdAt": "2026-03-01T02:00:00Z"
97+
"createdAt": "` + d2 + `"
8598
}
8699
]
87100
}
@@ -93,7 +106,7 @@ func ReviewActivityResponse() string {
93106
"author": {"login": "reviewer-alice"},
94107
"body": "Prefer const over let for immutable bindings",
95108
"diffHunk": "@@ -20,1 +22,1 @@\n-let x = 5;\n+const x = 5;",
96-
"createdAt": "2026-03-01T03:00:00Z"
109+
"createdAt": "` + d3 + `"
97110
}
98111
]
99112
}
@@ -112,7 +125,16 @@ func ReviewActivityResponse() string {
112125
// (alice: 3 comments, bob: 2, charlie: 1) plus dependabot[bot] in both
113126
// reviews and comments. Supports testing --top N filtering, bot filtering
114127
// on reviews, totalComments, and CSV ranking order.
128+
// Dates are generated relative to now so they always fall within the default 3-month --since window.
115129
func MultiReviewerResponse() string {
130+
d0 := recentDate(30)
131+
d1 := recentDate(29)
132+
d2 := recentDate(28)
133+
d3 := recentDate(27)
134+
d4 := recentDate(26)
135+
d5 := recentDate(25)
136+
d6 := recentDate(24)
137+
d7 := recentDate(23)
116138
return `{
117139
"data": {
118140
"repository": {
@@ -124,23 +146,23 @@ func MultiReviewerResponse() string {
124146
"title": "Big refactor",
125147
"url": "https://github.com/test-org/test-repo/pull/100",
126148
"state": "MERGED",
127-
"updatedAt": "2026-03-01T00:00:00Z",
149+
"updatedAt": "` + d0 + `",
128150
"author": {"login": "pr-author"},
129151
"reviews": {
130152
"nodes": [
131-
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "2026-03-01T01:00:00Z"},
132-
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "2026-03-01T02:00:00Z"},
133-
{"author": {"login": "reviewer-charlie"}, "state": "APPROVED", "createdAt": "2026-03-01T03:00:00Z"},
134-
{"author": {"login": "dependabot[bot]"}, "state": "APPROVED", "createdAt": "2026-03-01T04:00:00Z"}
153+
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "` + d1 + `"},
154+
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "` + d2 + `"},
155+
{"author": {"login": "reviewer-charlie"}, "state": "APPROVED", "createdAt": "` + d3 + `"},
156+
{"author": {"login": "dependabot[bot]"}, "state": "APPROVED", "createdAt": "` + d4 + `"}
135157
]
136158
},
137159
"reviewThreads": {
138160
"nodes": [
139-
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "Use early return", "diffHunk": "@@ -1,3 +1,5 @@\n+if err != nil {", "createdAt": "2026-03-01T01:00:00Z"}]}},
140-
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "Prefer const", "diffHunk": "@@ -10,1 +10,1 @@\n-let x = 5;", "createdAt": "2026-03-01T01:30:00Z"}]}},
141-
{"comments": {"nodes": [{"author": {"login": "reviewer-bob"}, "body": "Handle nil case", "diffHunk": "@@ -20,3 +22,5 @@\n resp, err := client.Do(req)", "createdAt": "2026-03-01T02:00:00Z"}]}},
142-
{"comments": {"nodes": [{"author": {"login": "reviewer-charlie"}, "body": "Add docs", "diffHunk": "@@ -30,1 +32,1 @@\n+// TODO", "createdAt": "2026-03-01T03:00:00Z"}]}},
143-
{"comments": {"nodes": [{"author": {"login": "dependabot[bot]"}, "body": "Dep update safe", "diffHunk": "@@ -1,1 +1,1 @@\n-v1.0\n+v1.1", "createdAt": "2026-03-01T04:00:00Z"}]}}
161+
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "Use early return", "diffHunk": "@@ -1,3 +1,5 @@\n+if err != nil {", "createdAt": "` + d1 + `"}]}},
162+
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "Prefer const", "diffHunk": "@@ -10,1 +10,1 @@\n-let x = 5;", "createdAt": "` + d2 + `"}]}},
163+
{"comments": {"nodes": [{"author": {"login": "reviewer-bob"}, "body": "Handle nil case", "diffHunk": "@@ -20,3 +22,5 @@\n resp, err := client.Do(req)", "createdAt": "` + d2 + `"}]}},
164+
{"comments": {"nodes": [{"author": {"login": "reviewer-charlie"}, "body": "Add docs", "diffHunk": "@@ -30,1 +32,1 @@\n+// TODO", "createdAt": "` + d3 + `"}]}},
165+
{"comments": {"nodes": [{"author": {"login": "dependabot[bot]"}, "body": "Dep update safe", "diffHunk": "@@ -1,1 +1,1 @@\n-v1.0\n+v1.1", "createdAt": "` + d4 + `"}]}}
144166
]
145167
}
146168
},
@@ -149,18 +171,18 @@ func MultiReviewerResponse() string {
149171
"title": "Small fix",
150172
"url": "https://github.com/test-org/test-repo/pull/101",
151173
"state": "MERGED",
152-
"updatedAt": "2026-03-02T00:00:00Z",
174+
"updatedAt": "` + d5 + `",
153175
"author": {"login": "pr-author"},
154176
"reviews": {
155177
"nodes": [
156-
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "2026-03-02T01:00:00Z"},
157-
{"author": {"login": "reviewer-bob"}, "state": "APPROVED", "createdAt": "2026-03-02T02:00:00Z"}
178+
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "` + d6 + `"},
179+
{"author": {"login": "reviewer-bob"}, "state": "APPROVED", "createdAt": "` + d7 + `"}
158180
]
159181
},
160182
"reviewThreads": {
161183
"nodes": [
162-
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "LGTM with nit", "diffHunk": "@@ -5,1 +5,1 @@\n-old\n+new", "createdAt": "2026-03-02T01:00:00Z"}]}},
163-
{"comments": {"nodes": [{"author": {"login": "reviewer-bob"}, "body": "Typo here", "diffHunk": "@@ -8,1 +8,1 @@\n-colour\n+color", "createdAt": "2026-03-02T02:00:00Z"}]}}
184+
{"comments": {"nodes": [{"author": {"login": "reviewer-alice"}, "body": "LGTM with nit", "diffHunk": "@@ -5,1 +5,1 @@\n-old\n+new", "createdAt": "` + d6 + `"}]}},
185+
{"comments": {"nodes": [{"author": {"login": "reviewer-bob"}, "body": "Typo here", "diffHunk": "@@ -8,1 +8,1 @@\n-colour\n+color", "createdAt": "` + d7 + `"}]}}
164186
]
165187
}
166188
}
@@ -183,7 +205,12 @@ func RepoNotFoundError(org, repo string) string {
183205

184206
// ReviewActivityWithBotResponse includes a bot reviewer and bot commenter
185207
// alongside human reviewers, for testing bot filtering.
208+
// Dates are generated relative to now so they always fall within the default 3-month --since window.
186209
func ReviewActivityWithBotResponse() string {
210+
d0 := recentDate(30)
211+
d1 := recentDate(29)
212+
d2 := recentDate(28)
213+
d3 := recentDate(27)
187214
return `{
188215
"data": {
189216
"repository": {
@@ -194,13 +221,13 @@ func ReviewActivityWithBotResponse() string {
194221
"title": "Add feature X",
195222
"url": "https://github.com/test-org/test-repo/pull/42",
196223
"state": "MERGED",
197-
"updatedAt": "2026-03-01T00:00:00Z",
224+
"updatedAt": "` + d0 + `",
198225
"author": {"login": "pr-author"},
199226
"reviews": {
200227
"nodes": [
201-
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "2026-03-01T01:00:00Z"},
202-
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "2026-03-01T02:00:00Z"},
203-
{"author": {"login": "dependabot[bot]"}, "state": "APPROVED", "createdAt": "2026-03-01T03:00:00Z"}
228+
{"author": {"login": "reviewer-alice"}, "state": "APPROVED", "createdAt": "` + d1 + `"},
229+
{"author": {"login": "reviewer-bob"}, "state": "CHANGES_REQUESTED", "createdAt": "` + d2 + `"},
230+
{"author": {"login": "dependabot[bot]"}, "state": "APPROVED", "createdAt": "` + d3 + `"}
204231
]
205232
},
206233
"reviewThreads": {
@@ -212,7 +239,7 @@ func ReviewActivityWithBotResponse() string {
212239
"author": {"login": "reviewer-alice"},
213240
"body": "Consider using early return here to reduce nesting",
214241
"diffHunk": "@@ -1,3 +1,5 @@\n func foo() {\n+ if err != nil {\n+ return err\n+ }",
215-
"createdAt": "2026-03-01T01:00:00Z"
242+
"createdAt": "` + d1 + `"
216243
}
217244
]
218245
}
@@ -224,7 +251,7 @@ func ReviewActivityWithBotResponse() string {
224251
"author": {"login": "reviewer-bob"},
225252
"body": "This needs error handling for the nil case",
226253
"diffHunk": "@@ -10,3 +12,5 @@\n resp, err := client.Do(req)",
227-
"createdAt": "2026-03-01T02:00:00Z"
254+
"createdAt": "` + d2 + `"
228255
}
229256
]
230257
}
@@ -236,7 +263,7 @@ func ReviewActivityWithBotResponse() string {
236263
"author": {"login": "dependabot[bot]"},
237264
"body": "This dependency update is safe to merge",
238265
"diffHunk": "@@ -1,1 +1,1 @@\n-dep: v1.0.0\n+dep: v1.1.0",
239-
"createdAt": "2026-03-01T03:00:00Z"
266+
"createdAt": "` + d3 + `"
240267
}
241268
]
242269
}
@@ -248,7 +275,7 @@ func ReviewActivityWithBotResponse() string {
248275
"author": {"login": "reviewer-alice"},
249276
"body": "Prefer const over let for immutable bindings",
250277
"diffHunk": "@@ -20,1 +22,1 @@\n-let x = 5;\n+const x = 5;",
251-
"createdAt": "2026-03-01T03:00:00Z"
278+
"createdAt": "` + d3 + `"
252279
}
253280
]
254281
}

0 commit comments

Comments
 (0)