Repository navigation
fix(build): pin smoke discovery to the head commit's deploy - #141
Merged
Merged
Conversation
`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]>
Deploying sahajatlas-design with
|
| 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 |
Deploying sahajatlas with
|
| Latest commit: |
db8a345
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f54e4f62.sahajatlas.pages.dev |
| Branch Preview URL: | https://fix-smoke-head-sha.sahajatlas.pages.dev |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.discover()computedfailurebutmain()never read it, sotimeoutStatusnever saw it and thefailedstatus — 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'sfailedbranch 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_urlending 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
56c6b0ddeployed toa73c3b0c, but the Cloudflare comment for this project was last edited naming9326e3band still linked that commit's deploy,6b78e192. Today only source ordering saved it (check runs are harvested before comments).Take the ordering away — commit
cef5e90on that same PR has zero Cloudflare check runs, so the comment is all there is:Changes
scripts/get-cloudflare-preview-url.mjs— candidates harvested into aMap<url, scope>with provenance (commit/pr/none); newPROVENANCE,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/andci.ymlwere listed as possible in the ticket; neither needed a change — thepreview_statusvocabulary is unchanged.Verification
pnpm lint)pnpm typecheck)Live, against the real GitHub API:
56c6b0dfound→a73c3b0c(not the comment's6b78e192)found→9260ebb2/0e2efdd2cef5e90absent; old code saidfound+ wrong commita2cf111found→b8a88946absentAnd on this PR's own CI run — the strongest evidence available, since no browser or live data is up this wave. Head
db8a345; itsCloudflare Pages: sahajatlascheck run carries deploymentf54e4f62-0618-…and a summary listing bothhttps://f54e4f62.sahajatlas.pages.devand the branch aliashttps://fix-smoke-head-sha.sahajatlas.pages.dev. Discovery waited six polls (1m38s), loggingcheck run "Cloudflare Pages: sahajatlas" (in_progress)each time — incidentally re-confirming #132's correction that the building state is observable live — then chose: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-reviewcompleted and its verdict was net tightening, no new exposure — the set of URLs that can reachpreview_urlis 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 in2413afa:checks:writecould name itselfCloudflare Pages: sahajatlasand choose thedetails_urlwe 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.pick(), isn't deploy-shaped, and so sat on thealiasfloor. This script only runs for a PR head, so production is never right. Refused outright.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
aliasfloor delivers — softened — and that the "exactly one run per project" comment was wrong (filter=latestis one run per check name, unique per app, not globally, which is exactly why fix 1 matters)./code-reviewalso completed, ~12 minutes in — after CI had already gone green, which is itself worth noting. Two High, four Medium, three Low, all fixed indb8a345. The two High findings were both things this PR had asserted and I had not checked:refusedreached the poll log but nevermain(), so at timeoutabsentprinted "no check run, no deployment, no bot comment" directly beneath a line naming the URL we declined — and ci.yml routesabsentto "INVESTIGATE, don't re-run". Now threaded intoexplain(). It deliberately does not reachtimeoutStatus: another commit's URL is not evidence that this one built, so it must not softenabsentinto "re-run".\b<sha>\brejected 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
commitscope, 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 (newclaimedtier); the slug gate guarded onlydeployment, notfailure, which is the sharper forgery; and the header's "the only URLs this refuses are …" was false four ways (the classMEMORY.mdwarns about, and it went in anyway). Lows:deploymentAliastook 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=latestwould surface, so breaking early could miss one in flight — the cost is idle minutes, not a wrong answer); stickylastFailure(consistent withlastUrl/lastEvidence); an 8-hex branch name classifying asattested(already documented).Known gap:
discover(),harvest()andmain()'s accumulation have no automated coverage — every H/M finding lived in that untested wiring.waitingLinewas exported and specced in response; adiscover()-level spec with an injectable fetch is the natural follow-up.Notes for reviewer
lastUrl, so ignoring one leaves the statuspending(evidence exists), notunreachable— and a correct-but-slow deploy still readspending, neverabsent.aliastier 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.aliaseven 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.CF_PAGES_COMMIT_SHAstamp shares its root of trust with the check run this already keys on, so it adds little; only agit rev-parse HEADstamp 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 askipIf, and it cannot help discovery — it is a post-hoc check. Reasoning in full in the report.Closes #138
🤖 Generated with Claude Code