Skip to content

fix(build): pin smoke discovery to the head commit's deploy - #141

Merged
Ardnived merged 4 commits into
mainfrom
fix/smoke-head-sha
Aug 11, 2026
Merged

Ardnived merged 4 commits into
mainfrom
fix/smoke-head-sha

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The smoke lane could pass having tested a different commit. pick() gates the host, never which build that host serves — and Cloudflare publishes two per project: the per-deployment alias (a73c3b0c.sahajatlas.pages.dev, one commit forever) and a stable branch alias (fix-x.sahajatlas.pages.dev, whatever deployed to that branch last). Both cleared the gate, so "first match" could be either.
  • Discovery now ranks candidates by provenance instead of taking the first match: the deployment named by our own check run for the head SHA, then a deploy-shaped URL from a per-SHA source, then one from a Cloudflare comment naming the head, then a branch alias. A comment naming some other commit is refused outright, and so is the bare project host — that is production, not any preview.
  • Also fixes a live defect found while wiring this up: discover() computed failure but main() never read it, so timeoutStatus never saw it and the failed status — added by chore(build): make preview discovery survive a slow cloudflare deploy #132's code review so a broken build isn't reported as a slow one — has been unreachable in production while its four unit assertions stayed green. ci.yml's failed branch has never executed.

#122's check-run source was already fetched per-SHA (/commits/<sha>/check-runs), so URLs from it were always commit-correct. The exposure was the branch-scoped sources — chiefly the PR comment, which is one comment per PR edited in place. That is why the fix is a ranking rather than a rewrite of discovery.

Why this is a fact now, not a heuristic

The check run at the head SHA carries details_url ending in the deployment UUID, and Cloudflare's per-deployment alias is that UUID's first 8 characters. So the chain is unbroken: GitHub returned this run for the head SHA → the run names deployment X → the host we test is deployment X's.

Verified on every one of PRs #133–#137 — the summary carries the per-deploy URL, and Latest commit: matched the head 5/5. #132 fenced this fix off partly because that was unverified and tightening blind risked breaking discovery; it is verified now.

The bug, reproduced against the live API

PR #135 is the bug in the wild. Head 56c6b0d deployed to a73c3b0c, but the Cloudflare comment for this project was last edited naming 9326e3b and still linked that commit's deploy, 6b78e192. Today only source ordering saved it (check runs are harvested before comments).

Take the ordering away — commit cef5e90 on that same PR has zero Cloudflare check runs, so the comment is all there is:

--- OLD ---  ✅ found  → https://6b78e192.sahajatlas.pages.dev   (9326e3b's build)
--- NEW ---  ⚠️ absent → (refused, and logged by name)

Changes

  • scripts/get-cloudflare-preview-url.mjs — candidates harvested into a Map<url, scope> with provenance (commit / pr / none); new PROVENANCE, deploymentAlias, provenanceOf, pickPreview, waitingLine. pick() itself is untouched — ranking calls it per tier, so tightening which URL is taken cannot loosen whose host is accepted. Comment harvest additionally requires the Cloudflare login, matching the gate the evidence path already used.
  • scripts/get-cloudflare-preview-url.test.ts — 19 new cases, built on PR fix(event): deliver report-issue submissions instead of alerting #135's real URLs so the fixtures name the defect rather than paraphrasing it.
  • .claude/rules/tests.md — a third smoke-lane invariant; chore(build): make preview discovery survive a slow cloudflare deploy #132's "known gap, deliberately still open" removed, since its precondition is now answered.

tests/smoke/ and ci.yml were listed as possible in the ticket; neither needed a change — the preview_status vocabulary is unchanged.

Verification

  • Lint: ✓ (pnpm lint)
  • Types: ✓ (pnpm typecheck)
  • Tests: ✓ unit lane green — 979 (up from 960)
  • Build: N/A — no bundle-affecting changes (CI still runs it)

Live, against the real GitHub API:

case fixture result
head deploy selected #135 56c6b0d found → a73c3b0c (not the comment's 6b78e192)
ditto #136 / #137 heads found → 9260ebb2 / 0e2efdd2
stale comment refused #135 cef5e90 absent; old code said found + wrong commit
no PR number (push to main) a2cf111 found → b8a88946
no Cloudflare signal all-zero SHA absent

And on this PR's own CI run — the strongest evidence available, since no browser or live data is up this wave. Head db8a345; its Cloudflare Pages: sahajatlas check run carries deployment f54e4f62-0618-… and a summary listing both https://f54e4f62.sahajatlas.pages.dev and the branch alias https://fix-smoke-head-sha.sahajatlas.pages.dev. Discovery waited six polls (1m38s), logging check run "Cloudflare Pages: sahajatlas" (in_progress) each time — incidentally re-confirming #132's correction that the building state is observable live — then chose:

✅ `found` after 1m38s — smoke specs will run against https://f54e4f62.sahajatlas.pages.dev

The branch alias was on offer in the same summary and was passed over, and the selected host is exactly the deployment UUID's first 8 characters.

I can not claim the old code would have picked wrong on this particular run: that would need to know what the PR comment held during the build window, and it is edited in place — the same retrospective blindness #132 documented. What the run proves is that the new code waited for the head commit's own deployment and took nothing weaker.

Review passes

/security-review completed and its verdict was net tightening, no new exposure — the set of URLs that can reach preview_url is a strict subset of what the old code could emit, pick() is untouched and still the sole host gate, and nothing new reaches $GITHUB_OUTPUT. No Critical, no High. It raised three Low findings, all three fixed in 2413afa:

  1. The deployment id was read from a check run admitted by name, and a name is self-declared — an installed App with checks:write could name itself Cloudflare Pages: sahajatlas and choose the details_url we derive the expected host from. It could never aim the lane off-host, but it could steer selection between builds of our own site. Now gated on the app slug.
  2. The bare project host is production, not a preview: it clears pick(), isn't deploy-shaped, and so sat on the alias floor. This script only runs for a PR head, so production is never right. Refused outright.
  3. includes(shortSha) matched a 7-hex prefix anywhere, including inside a longer hex run. Now a whole-token match.

It also flagged that the tests.md headline promised more than the alias floor delivers — softened — and that the "exactly one run per project" comment was wrong (filter=latest is one run per check name, unique per app, not globally, which is exactly why fix 1 matters).

/code-review also completed, ~12 minutes in — after CI had already gone green, which is itself worth noting. Two High, four Medium, three Low, all fixed in db8a345. The two High findings were both things this PR had asserted and I had not checked:

  • The summary denied the URL it had just refused. refused reached the poll log but never main(), so at timeout absent printed "no check run, no deployment, no bot comment" directly beneath a line naming the URL we declined — and ci.yml routes absent to "INVESTIGATE, don't re-run". Now threaded into explain(). It deliberately does not reach timeoutStatus: another commit's URL is not evidence that this one built, so it must not soften absent into "re-run".
  • \b<sha>\b rejected every longer spelling of the same commit (56c6b0d1, the full 40 hex). Since that predicate now gates the URL harvest and not just the evidence, source 4 would have died wholesale the day Cloudflare printed one more digit. Only the left boundary is anchored now.

Mediums: deploy-shape was read only at commit scope, so inside a single comment the table's print order decided which of its two URLs won — this ticket's own defect one level down (new claimed tier); the slug gate guarded only deployment, not failure, which is the sharper forgery; and the header's "the only URLs this refuses are …" was false four ways (the class MEMORY.md warns about, and it went in anyway). Lows: deploymentAlias took the first UUID while its doc said "ending in", the production refusal read a module-level slug rather than the passed host, and the poll line dropped evidence when it also had a refusal.

Dismissed: a failed build still polling the full budget (a Cloudflare retry creates a new deployment that filter=latest would surface, so breaking early could miss one in flight — the cost is idle minutes, not a wrong answer); sticky lastFailure (consistent with lastUrl/lastEvidence); an 8-hex branch name classifying as attested (already documented).

Known gap: discover(), harvest() and main()'s accumulation have no automated coverage — every H/M finding lived in that untested wiring. waitingLine was exported and specced in response; a discover()-level spec with an injectable fetch is the natural follow-up.

Notes for reviewer

  • The taxonomy is deliberately preserved. A refused URL never becomes lastUrl, so ignoring one leaves the status pending (evidence exists), not unreachable — and a correct-but-slow deploy still reads pending, never absent.
  • The alias tier is a floor on purpose. If Cloudflare ever stops printing the per-deploy URL, discovery should degrade rather than redden every same-repo PR under chore(build): add audit gate, size budget, and embed smoke tests #99's hard-fail.
  • A comment caps at alias even when deploy-shaped. Whether Cloudflare blanks its comment's URL cells mid-build is not observable retrospectively (the comment is edited in place), so the design assumes the unfavourable case and lets the check run win that race rather than tie it.
  • Weighed and declined: a build-stamped asset asserting the served build is the head commit. A CF_PAGES_COMMIT_SHA stamp shares its root of trust with the check run this already keys on, so it adds little; only a git rev-parse HEAD stamp taken inside the CF build container would be independent evidence. That is worth a follow-up ticket, but it costs a new red-lane failure mode plus a skipIf, and it cannot help discovery — it is a post-hoc check. Reasoning in full in the report.

Closes #138

🤖 Generated with Claude Code

Ardnived and others added 3 commits August 7, 2026 21:19
`pick()` gates the HOST, never which BUILD that host serves. Cloudflare
publishes two per project — the per-deployment alias and a stable branch
alias — and both cleared the gate, so the lane could go green having
smoke-tested the previous commit.

Candidates now carry provenance and are ranked: the deployment named by
our own check run for this SHA (its `details_url` ends in the deployment
UUID, whose first 8 chars ARE the alias) beats a deploy-shaped URL from a
per-SHA source, which beats a branch alias. A Cloudflare comment naming
some other commit is refused outright — that is the observed defect, not
a hypothetical: on PR #135 the comment still linked `9326e3b`'s deploy
while the head was `56c6b0d`.

Also wires `failure` through `main()`. It was computed in `discover()`
and dropped on the floor, so `timeoutStatus` never saw it and the
`failed` status — added by #132's code review precisely so a broken build
is not reported as a slow one — was unreachable in production while its
unit spec passed.

Closes #138

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Eleven cases over `deploymentAlias` / `provenanceOf` / `pickPreview`,
built on PR #135's real data so the fixture names the defect rather than
paraphrasing it. The host gate is re-asserted at the strongest tier as
well as the weakest: ranking chooses AMONG urls `pick()` accepts and must
never reach past it.

tests.md gains the third invariant — a green Smoke check means the specs
ran against THIS commit — and loses #132's "known gap, deliberately still
open", whose precondition (does the check-run summary carry a per-commit
URL?) is now answered: yes, on all of #133-#137.

It also records why a passing unit spec did not stop `failed` being
unreachable: the defect was in the wiring, which no pure test can see.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three Low findings, all about the new attestation trusting something
self-declared:

- The deployment id was read from any check run admitted by NAME, and a
  name is self-declared. An installed App with `checks:write` could call
  itself "Cloudflare Pages: sahajatlas" and choose the `details_url` we
  derive the expected host from. It could never aim us off-host — pick()
  decides that — but it could steer selection between builds of our own
  site, which is the defect this ticket closes. Now gated on the app slug,
  matching source 1's "both the context AND the author".
- The bare project host is PRODUCTION, not a preview. It clears pick(),
  isn't deploy-shaped, and so sat on the `alias` floor beside a branch
  alias — but this script only runs for a PR head, so production is never
  the right answer. Refused outright.
- `includes(shortSha)` matched a 7-hex prefix anywhere, including inside a
  longer hex run, so a stale comment could be called "naming the head" on
  a coincidence. Now a whole-token match, built only from a real hex
  prefix so a bogus PR_HEAD_SHA degrades instead of throwing.

Also softens the tests.md headline, which promised more than the `alias`
floor delivers, and corrects the "exactly one run" comment: filter=latest
is one run per check NAME, which is unique per APP, not globally — which
is exactly why the slug gate matters.

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

cloudflare-workers-and-pages Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: db8a345
Status: ✅  Deploy successful!
Preview URL: https://c500553e.sahajatlas-design.pages.dev
Branch Preview URL: https://fix-smoke-head-sha.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: db8a345
Status: ✅  Deploy successful!
Preview URL: https://f54e4f62.sahajatlas.pages.dev
Branch Preview URL: https://fix-smoke-head-sha.sahajatlas.pages.dev

View logs

Two High, four Medium, three Low. The two that mattered most were both
things this PR had asserted and not checked:

- The summary DENIED the URL it had just refused. `refused` reached the
  poll log but never `main()`, so at timeout `absent` read "no check run,
  no deployment, no bot comment" while the line above named the URL we
  declined — and ci.yml routes `absent` to "INVESTIGATE, don't re-run". It
  now rides into `explain()`. It deliberately does NOT reach
  `timeoutStatus`: another commit's URL is not evidence that this one
  built, so it must not soften `absent` into "re-run".
- `\b<sha>\b` rejected every LONGER spelling of the same commit (`56c6b0d1`,
  the full 40 hex). Since that predicate now gates the URL harvest and not
  just the evidence, source 4 would have died wholesale the day Cloudflare
  printed one more digit. Only the left boundary is anchored now.

- Deploy-shape is read at BOTH scopes. Reading it only for per-SHA sources
  left one comment's two URLs indistinguishable, so Cloudflare's table
  order decided which won — this ticket's own defect, one level down. New
  `claimed` tier: below the check run, above a branch alias.
- The slug gate now guards every CONCLUSION drawn from a check run, not
  just `deployment`. An impostor could still set `failure`, and `failed`
  tells the reader "re-running cannot help" — a red check nobody can clear.
  URLs stay on the name-only path; `pick()` bounds those.
- The header's "the only URLs this refuses are X" was false four ways.
  Replaced with the enumeration, and the top-line "take the first we find"
  corrected. MEMORY.md warns about exactly this class of scope claim.
- `deploymentAlias` took the FIRST uuid while its doc said "ending in";
  the production-host refusal read a module-level slug instead of the
  passed host; the poll line dropped evidence whenever it had a refusal.

`waitingLine` is exported and specced, per the lesson this PR itself added
to tests.md — the wiring is where every one of these lived.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 8039e1f into main Aug 11, 2026
5 checks passed
@Ardnived
Ardnived deleted the fix/smoke-head-sha branch August 11, 2026 16:15
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.

fix(build): pin smoke discovery to the head commit's deploy

1 participant