Skip to content

Commit 91fa2f4

Browse files
committed
fix(ci): smoke measured whichever build the preview comment named
Cloudflare rewrites one comment per Worker in place, so between a push and that build finishing it still names the previous commit, and the address beside it is that build's. Discovery read the first workers.dev host in the comment and took it. The `Smoke (web)` lane on c221df7 therefore tested b60f0ac's deployment: five specs failed on routes the commit adds, and a head that commit emitted three times went unseen. Discovery now reads the comment's `Latest Commit` cell and skips a comment naming any other commit, so the 12-minute window is spent waiting for this commit's build rather than measuring the last one. A comment that names no commit is still accepted: the column is Cloudflare's to rename, and no address at all stops the lane. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWDpubJYs3RkxjCw1u
1 parent 7ef382b commit 91fa2f4

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎docs/cloudflare-previews-ci.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ branch's latest successful build rather than this commit, so running it earlier
4242
specs the previous build while this commit's own was still deploying. The address still has to
4343
answer before it reaches the specs. Read the `selected …` and `skipping …` lines the step prints.
4444

45+
⚠ **A comment is only accepted while it names the commit under test.** Cloudflare rewrites one
46+
comment per Worker in place, so between a push and that build finishing the comment still carries
47+
the previous commit's address, and discovery used to take it — the smoke lane then measured the
48+
build before the one on trial, reporting failures for routes the commit adds and missing what it
49+
broke (#282). Discovery now reads the comment's `Latest Commit` cell and keeps polling until it
50+
matches `PR_HEAD_SHA`. The other sources are keyed on the SHA already; the derived branch host is
51+
not, which is a second reason it runs only after the window closes.
52+
4553
| Target | Platform | URL host | Match substring | Config |
4654
| --- | --- | --- | --- | --- |
4755
| web | Workers Builds | `…-wemeditate-web.<acct>.workers.dev` | `wemeditate-web` | [wrangler.toml](../wrangler.toml) |

‎scripts/get-cloudflare-preview-url.mjs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ async function ghFetch(path) {
9999
// those rather than failing, since comments are only the first source tried.
100100
const PREVIEW_COMMENT_AUTHORS = ['cloudflare-workers-and-pages[bot]']
101101

102+
/**
103+
* Does this comment's deployment table name the commit under test?
104+
*
105+
* Cloudflare rewrites one comment per Worker in place, so between a push and that build
106+
* finishing it still names the previous commit — and the address beside it is that build's.
107+
* Discovery took it, and the smoke lane then measured the build before the one on trial: five
108+
* specs failed on routes the commit adds, while a head it emitted three times went unseen
109+
* (#282). Sources 2 to 4 are keyed on the SHA already; only this one and the derived branch
110+
* host are not.
111+
*
112+
* A comment naming no commit at all is still accepted. The column is Cloudflare's to rename,
113+
* and a wrong address is caught by the specs, where no address at all stops the lane.
114+
*/
115+
function namesCommit(body, sha) {
116+
if (!sha) return true
117+
// The short SHA is a cell of its own in the table. Every other hex run in the comment — the
118+
// account id, the build id — shares a cell with the link around it.
119+
const cells = [...String(body ?? '').matchAll(/\|\s*([0-9a-f]{7,40})\s*\|/gi)].map((m) =>
120+
m[1].toLowerCase(),
121+
)
122+
if (!cells.length) return true
123+
const head = sha.toLowerCase()
124+
return cells.some((cell) => head.startsWith(cell) || cell.startsWith(head))
125+
}
126+
102127
async function fromPrComments() {
103128
if (!PR_NUMBER) return []
104129
const comments = await ghFetch(`/repos/${REPO}/issues/${PR_NUMBER}/comments?per_page=100`)
@@ -111,6 +136,10 @@ async function fromPrComments() {
111136
console.error(`skipping ${url} [pr-comment(${author})] — not a preview bot`)
112137
continue
113138
}
139+
if (!namesCommit(c.body, SHA)) {
140+
console.error(`skipping ${url} [pr-comment(${author})] — names another commit, not ${SHA}`)
141+
continue
142+
}
114143
const project = (c.body || '').match(/Deploying\s+([a-z0-9._-]+)\s+with/i)?.[1] ?? null
115144
out.push({ project, url, source: `pr-comment(${author})` })
116145
}
@@ -268,6 +297,7 @@ export {
268297
PREVIEW_URL_RE,
269298
extractPreviewUrl,
270299
matchesTarget,
300+
namesCommit,
271301
slugifyBranch,
272302
accountSubdomain,
273303
fromDerivedBranchHost,

‎tests/guards/preview-discovery.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,38 @@ describe('the derived branch host', () => {
6969
})
7070
})
7171

72+
describe('the commit a preview comment names', () => {
73+
// Cloudflare's real comment for this pull request, one Worker's row.
74+
const comment = (sha: string) =>
75+
`| Status | Name | Latest Commit | Preview URL | Updated (UTC) |\n| -|-|-|-|-|\n` +
76+
`| ✅ Deployment successful! <br>[View logs](https://dash.cloudflare.com/?to=/c66c53a69689eb030b228c450515fff2/workers/services/view/wemeditate-web/production/builds/3e67b208-bec5-4c58-acb0-808cd52fdc30) ` +
77+
`| wemeditate-web | ${sha} | <a href='https://786c3f75-wemeditate-web.contact-c66.workers.dev'>Commit Preview URL</a> | Nov 19 2026, 03:58 AM |`
78+
79+
const HEAD = 'c221df7f593aca1e0b85ba31ecd7d0fc190cf8d3'
80+
81+
it('accepts the short SHA of the commit under test', () => {
82+
expect(discovery.namesCommit(comment('c221df7f'), HEAD)).toBe(true)
83+
})
84+
85+
it('refuses the commit before it, whose address the comment still carries', () => {
86+
expect(discovery.namesCommit(comment('b60f0acf'), HEAD)).toBe(false)
87+
})
88+
89+
it('reads the commit cell, not the account or build id beside it', () => {
90+
// Both are hex runs in the same comment, and neither is a cell of its own.
91+
expect(discovery.namesCommit(comment('c221df7f'), 'c66c53a69689eb030b228c450515fff2')).toBe(
92+
false,
93+
)
94+
})
95+
96+
it('accepts a comment that names no commit, and any comment when the SHA is unknown', () => {
97+
expect(discovery.namesCommit('https://x-wemeditate-web.contact-c66.workers.dev', HEAD)).toBe(
98+
true,
99+
)
100+
expect(discovery.namesCommit(comment('b60f0acf'), undefined)).toBe(true)
101+
})
102+
})
103+
72104
describe('target matching', () => {
73105
it('keeps the two Workers apart', () => {
74106
expect(

0 commit comments

Comments
 (0)