Skip to content

fix(build): find the preview URL on the check run, not just a comment - #122

Merged
Ardnived merged 1 commit into
mainfrom
fix/smoke-preview-discovery
Aug 7, 2026
Merged

Ardnived merged 1 commit into
mainfrom
fix/smoke-preview-discovery

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

The smoke gate #99 added is flaky by construction, and #120 is the proof: a red Smoke check on a commit whose Cloudflare deploy was healthy and whose preview was live the entire time.

Root cause

scripts/get-cloudflare-preview-url.mjs probes three sources for the head SHA. On this repo:

Source Reality here
1. commit statuses always empty — /commits/:sha/statuses returns []
2. deployment statuses always empty — /deployments returns [], for any SHA
3. Cloudflare bot PR comment best-effort — present on #121, absent on #120

So discovery rested entirely on a bot comment that Cloudflare does not reliably post. Before #99 a missing preview merely skipped the specs; now it hard-fails a same-repo PR, so the flake presents as a red check blocking a good merge — the gate built to stop a green check meaning nothing had started blocking merges at random instead.

Fix

Read the check run. Cloudflare renders the preview URL into output.summary, and that check run is the same object the Cloudflare Pages: <project> entry in the PR check list comes from — so it exists exactly when the deploy does. Confirmed present on both the failing and the passing PR.

Restricted to check runs owned by Cloudflare's GitHub App, mirroring the existing bot-author restriction on the comment source: posting a check run requires an installed app with write access — a far higher bar than commenting — but the summary is still attacker-influenced markdown if another app is installed. pick()'s exact-hostname match stays the real backstop.

Verification

Run against #120's head commit (df7b260), where discovery previously polled for six minutes and gave up:

Found preview URL: https://cad41df8.sahajatlas.pages.dev

Resolves immediately, and selects the app project rather than the -design playground — the discrimination pick() exists for.

Acceptance criteria

  • Discovery finds a preview for a commit that has a Cloudflare check run but no bot comment
  • Still prefers the configured project over sahajatlas-design.pages.dev
  • Non-Cloudflare check runs are ignored
  • Lint + typecheck clean
  • This PR's own Smoke check passes using the new source

Files affected

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

Unblocks #120.

The smoke gate was flaky by construction. Cloudflare posts neither commit
statuses nor GitHub deployments on this repo — both API queries return
empty — so preview discovery rested entirely on the Cloudflare bot's PR
comment, which is best-effort: it appeared on #121 and never on #120,
whose deploy was healthy and whose preview was live the whole time.

Since #99 made a missing preview hard-fail a same-repo PR, that flake
presents as a red Smoke check on a good commit, which is the worst
version of it — the gate added to stop a green check meaning nothing now
blocks merges at random.

Read the check run instead. Cloudflare renders the preview URL into the
check's output summary, and that check is the same object the
"Cloudflare Pages: <project>" entry in the PR check list comes from, so
it exists exactly when the deploy does. Restricted to check runs owned by
Cloudflare's app, mirroring the bot-author restriction on the comment
source; `pick()`'s hostname match remains the real backstop.

Verified against #120's head commit, where discovery previously polled
for six minutes and gave up: it now resolves immediately, and to the app
project rather than the -design playground.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: e9f91e3
Status: ✅  Deploy successful!
Preview URL: https://3199a3ce.sahajatlas.pages.dev
Branch Preview URL: https://fix-smoke-preview-discovery.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit c9d7c28 into main Aug 7, 2026
5 checks passed
@Ardnived
Ardnived deleted the fix/smoke-preview-discovery branch August 7, 2026 16:26
Ardnived added a commit that referenced this pull request Aug 7, 2026
One conflict, in README.md's CSP block, and it was load-bearing: this
branch added `https://cdn.usefathom.com` to script-src plus a warning
that CSP ignores every repeat of a directive name after the first, while
#121 added the widget's own origin as a SECOND `script-src` line — the
exact mistake the warning describes. Merged onto one line carrying all
three sources, so a host pasting the block actually gets Turnstile and
Fathom rather than silently losing them, and kept both explanations.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Aug 8, 2026
Review triage. The headline finding: a FAILED Cloudflare build still posts a
check run, so counting any run as "a deploy exists" classified it `pending` and
told the reader to RE-RUN a job that fails identically — training the exact
habit #132 set out to break, and making the rate-limit advice on the `absent`
branch unreachable in the one case it was written for.

- add a `failed` status, taken from the run whose name matches CF_PROJECT's own
  slug (the `-design` sibling succeeding says nothing about the app's build, and
  its "(success)" was often the only evidence shown). It outranks every other
  signal, and ci.yml tells the reader to read the Cloudflare log.
- bound every request with AbortSignal.timeout. undici defaults to 300s, so one
  hung socket could overrun the budget by 5 minutes and trip the job's
  `timeout-minutes` — which CANCELS the job, skipping the reporting step and
  leaving a red check with no message at all. Strictly worse than the timeout
  this ticket fixes.
- validate + cap PREVIEW_TIMEOUT_MS. `600` read as seconds was a 0.6s deadline
  and a confident "the deploy did not happen"; document the unit.
- write GITHUB_OUTPUT before the step summary, so an unwritable summary can't
  take the contract down with it.
- narrow source 2's evidence to /cloudflare/ (bare `pages` matched
  `github-pages`) and require a Cloudflare creator on source 1.
- lowercase pick()'s host — an uppercase CF_PROJECT matched nothing and turned
  every same-repo PR red; resolve the main-module guard through realpathSync.
- correct three comments: pick() cites source 4 not 3, and the threat is a bot
  of some installed App rather than "anyone who can comment" (the Bot gate
  already blocks that); CF_PROJECT is a host match, not a substring.

Records the one finding NOT fixed here: the URL harvest is unscoped by SHA and
pick() accepts the branch alias, so the lane can verify the previous commit.
Pre-existing, #122's territory, an explicit non-goal of this ticket, and
tightening it blind would break discovery. Written down in tests.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Aug 8, 2026
…#134)

* chore(build): make preview discovery survive a slow cloudflare deploy

The 6-minute deadline was not a margin over Cloudflare's build time, it WAS
that build time: across 86 measured `Cloudflare Pages: sahajatlas` check runs
on this repo the p95 is 373s, so 360s sat below it. #124 came in at 397s and
#99's hard-fail turned a healthy commit red.

Raise it to 10 minutes (overridable via PREVIEW_TIMEOUT_MS) and, more usefully,
stop collapsing every unhappy path into one empty output. A second
`preview_status` output names which it was, and ci.yml gives the two cases
different instructions: `absent` (no Cloudflare signal at all) says investigate,
`pending`/`unreachable` (a deploy demonstrably exists) says re-run. Both still
fail a same-repo PR, so the #99 invariant is untouched — a green Smoke check
still means the specs ran.

The wait is flat rather than adaptive because there is nothing to wait on:
across 230 check runs every one was already `completed` when first visible
(`started_at == completed_at`), and GitHub pre-creates a `queued` check suite
per installed app, so Cloudflare's is indistinguishable from the suites of apps
that never post. That verification is recorded in the script header and in
.claude/rules/tests.md rather than left to be re-derived.

Sources and `pick()` are unchanged; a new spec pins the latter's hostname
boundary, which was previously untested.

Closes #132

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* chore(build): don't repeat the elapsed wait, and name the error case

Three follow-ups from exercising the script against the live API:
- `explain()` no longer restates the elapsed time that `emit()` already
  prefixes every line with (it read "after 18s … after 18s").
- the poll loop no longer sleeps past its own deadline, so the reported wait
  is the budget we set rather than the budget plus a trailing interval.
- ci.yml gives `error` its own message: the discovery step itself failed, which
  is not "Cloudflare posted nothing". An unrecognised status still takes the
  loud branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* chore(build): sanitize quoted evidence and drop a dead branch

Self-triage of the branch diff:

- Source 3 accepts a check run whose NAME begins with "cloudflare pages" from
  ANY installed app, not only Cloudflare's, and that name is now quoted into the
  step summary. `report()` only defangs a LEADING `::`, so a newline in a crafted
  name could forge a summary line mid-string. `note()` flattens whitespace and
  caps at 120 chars before any API text is quoted.
- `explain()`'s `detail` arm was unreachable — `fail()` passes the error message
  straight to `emit()` and never routes through it. Dropped, so the three
  timeout outcomes are the whole function.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* chore(build): tell a failed deploy apart from a slow one

Review triage. The headline finding: a FAILED Cloudflare build still posts a
check run, so counting any run as "a deploy exists" classified it `pending` and
told the reader to RE-RUN a job that fails identically — training the exact
habit #132 set out to break, and making the rate-limit advice on the `absent`
branch unreachable in the one case it was written for.

- add a `failed` status, taken from the run whose name matches CF_PROJECT's own
  slug (the `-design` sibling succeeding says nothing about the app's build, and
  its "(success)" was often the only evidence shown). It outranks every other
  signal, and ci.yml tells the reader to read the Cloudflare log.
- bound every request with AbortSignal.timeout. undici defaults to 300s, so one
  hung socket could overrun the budget by 5 minutes and trip the job's
  `timeout-minutes` — which CANCELS the job, skipping the reporting step and
  leaving a red check with no message at all. Strictly worse than the timeout
  this ticket fixes.
- validate + cap PREVIEW_TIMEOUT_MS. `600` read as seconds was a 0.6s deadline
  and a confident "the deploy did not happen"; document the unit.
- write GITHUB_OUTPUT before the step summary, so an unwritable summary can't
  take the contract down with it.
- narrow source 2's evidence to /cloudflare/ (bare `pages` matched
  `github-pages`) and require a Cloudflare creator on source 1.
- lowercase pick()'s host — an uppercase CF_PROJECT matched nothing and turned
  every same-repo PR red; resolve the main-module guard through realpathSync.
- correct three comments: pick() cites source 4 not 3, and the threat is a bot
  of some installed App rather than "anyone who can comment" (the Bot gate
  already blocks that); CF_PROJECT is a host match, not a substring.

Records the one finding NOT fixed here: the URL harvest is unscoped by SHA and
pick() accepts the branch alias, so the lane can verify the previous commit.
Pre-existing, #122's territory, an explicit non-goal of this ticket, and
tightening it blind would break discovery. Written down in tests.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(build): correct the in-progress claim the live run disproved

This PR's own CI disproved its headline finding. The discovery step logged
`check run "Cloudflare Pages: sahajatlas" (in_progress)` on seven consecutive
polls before the URL appeared — so Cloudflare DOES publish a building state,
and the claim that it does not was wrong in the script header, in tests.md and
in the PR body.

The error was methodological, and worth recording because it is repeatable:
Cloudflare sets `started_at` when it COMPLETES a check run, so every finished
run reads `started_at == completed_at`. Sampling historical commits — what
#124's evidence and my own 230-run sweep both did — cannot see the in-progress
window and concludes it never existed. Only watching a live build shows it.

No behaviour changes. The flat deadline stands on the duration data, which is
unaffected, and now costs less than it seemed to: adaptive extension is
genuinely available if the queue ever outgrows the cap. The correction also
makes the `failed` guard's `status === 'completed'` test load-bearing rather
than incidental — an in-progress run has a null conclusion.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant