Repository navigation
ci(previews): deploy a live Studio preview for each PR - #2054
Merged
Merged
Conversation
Each PR into stage from a branch of this repository gets a live Studio at https://<branch>.app.<cluster domain>/, dropped when the PR closes. preview-build.yaml builds the PR's head commit in dev mode, without telemetry, in an unprivileged pull_request run and uploads web/. preview.yaml (pull_request_target, from stage) waits for that build, writes its own static config.yaml and deploys the payload as hdbms-pr-<N> with HarperFast/deploy-action v1.0.0 over OIDC. Fork PRs get no preview, and nothing in it checks out PR code. workflowPrivilege.test.ts now checks that every pull_request_target job has the fork guard and checks out nothing, since the cluster's trust policy pins the file's path, not its content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The wait step also matches the build run's head branch, so another PR's run at the same commit is never picked. - The guard test requires the fork guard as a top-level && term, with string literals stripped and no ||, so a negated, quoted or bypassed guard fails it. - deploying.md says previews need the dev CM's CORS entry, sign in with email and password, and serve Harper's plain 404. - Workflow comments keep only the constraints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- preview-build.yaml names each run "Build PR Preview #<N>", and the wait step matches that title, so another PR's run of the same commit, even from the same branch, is never picked. - A failed runs listing no longer counts as "no build started" after ten minutes; the 30-minute limit still applies. - The fork-guard test refuses any condition with parentheses, braces or ||, so a guard inside a negated group or between two interpolations fails it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds documentation for PR previews in .github/deploying.md and introduces a test suite in src/lib/workflowPrivilege.test.ts to ensure that pull_request_target workflows are properly guarded and do not execute untrusted code. The feedback recommends enhancing the robustness of the tests by normalizing whitespace when verifying the fork guard condition and adding defensive checks to handle malformed workflow files without crashing.
Previews will live on the central manager's own cluster, where a preview is a worker thread in CM's Harper process. - Both workflows run only when a login in the HARPER_PREVIEW_AUTHORS repository variable (a JSON array) opened the PR and caused the event. Unset, nobody gets a preview: its JavaScript runs with the visitor's dev CM session. - The deploy passes branched_databases: false. Branching would fork every database on the node but system, CM's included; the payload runs no server code, so sharing touches nothing. - The fork-guard test splits the condition at parenthesis depth 0, so a function call such as contains(fromJSON(...)) passes while a guard inside a call, a negated group or a top-level || still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…shared - The cleanup step runs only when HARPER_PREVIEW_TARGET is set and the PR's author is listed, so an unset variable doesn't fail every merge. The gate sits on the step: any other term in the job's if: makes harper preview setup unable to verify that cleanup runs on close. - The setup command in the header and deploying.md now says dataMode=shared, which branched_databases: false needs. - The fork-guard test also refuses index expressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est can't read The fork-guard check now compares with whitespace collapsed, so a guard split across lines still counts. A jobs, job, steps or step value of the wrong type is reported as a problem rather than crashing the test or being skipped, so it fails instead of passing unchecked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dawsontoth
marked this pull request as ready for review
November 9, 2026 17:05
dawsontoth
marked this pull request as draft
November 9, 2026 20:58
…views # Conflicts: # src/lib/workflowPrivilege.test.ts
…igin The sign-in buttons now name the serving origin in the OAuth redirect. The central manager keeps only the path for an origin it does not list, so dev Studio and production behave as before. For an origin in its postLoginRedirectOrigins (Studio PR previews on dev), it hands the sign-in over with a single-use oauth_handoff code in the fragment. /#/check-oauth clears that code from the URL and redeems it at POST /oauth/handoff from the page itself, since Harper names the session cookie after the request's Origin, then checks for the session as before. Refs HarperFast/central-manager#911. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any repository writer could make a run of their own preview-build.yaml with another PR's run title and commit, from a PR into a different base branch, and the wait step would pick it as that PR's build. The step now counts a run only when its actor and triggering actor are both in HARPER_PREVIEW_AUTHORS. Also drops comments that restated the names they sat on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iables actionlint failed Verify PR with SC2016 on the single-quoted jq expression. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dawsontoth
marked this pull request as ready for review
November 17, 2026 14:25
kriszyp
approved these changes
Nov 17, 2026
…y closed PR Kris's review of #2054: - preview.yaml writes its static config.yaml before downloading the build, and the pull_request_target guard test now refuses any step after an artifact download except deploy-action, so no step can execute what the PR built. download-artifact keeps every file inside its path. - Cleanup no longer checks the author list, so a preview is dropped when its PR closes even after its author leaves the list. Dropping a preview that doesn't exist does nothing. - Both workflows skip when HARPER_PREVIEW_TARGET is unset, instead of building and waiting before deploy-action finds no target. - The deploy job's failures say to re-run it once the build succeeds, and .github/deploying.md says so too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
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.
⊙ Problem
A Studio PR has no running build to try: reviewers check out the branch, or wait for
dev. Harper 5.4 hosts a preview per PR (HarperFast/harper#3042), and Harper's own repos should dogfood it with HarperFast/deploy-action, as HarperFast/documentation#797 does for the docs site.Closes HarperFast/central-manager#912.
🤔 Previews live on the central manager's own cluster
That is Dawson's plan: only the
hdbmsfront end gets previews, athttps://<branch>.app.dev.studio.harperfabric.com/, and they call the one dev CM. Each preview is a worker thread in CM's Harper process, not a sandbox, and the CM answers CORS only for origins it lists.💡 Solution
preview-build.yamlbuilds the PR's head in an unprivilegedpull_requestrun, in dev mode without telemetry: the bundle calls the dev CM, with no Datadog RUM, GTM or sourcemap upload. It uploadsweb/.preview.yamlis deploy-action's example plus documentation#797's wait: the deploy job waits for that build, writes its own staticconfig.yamlaround it, and deployshdbms-pr-<N>sharing the cluster's data. Nothing checks out PR code./#/check-oauthredeems the one-time code the CM hands back.🤔 Static files only, not the deploy template
The template is a fastify route plus
@fastify/static: server code the PR controls. On CM's cluster that code could read CM's deployed.env(its AWS keys) and reach the cluster's CA throughserver.operation, so the preview runs none;preview.yamlwrites the config. The cost: template changes aren't previewed, and previews lack the template's frame guard and cache headers.🤔 Trusted users, shared data
A preview's JavaScript runs with its visitor's dev CM session, so the
HARPER_PREVIEW_AUTHORSvariable lists who gets one; unset, nobody does. Previews share data because branching forks every database butsystem, CM's included. Google and GitHub sign-in finish on the preview through the CM's one-time handoff code; an organization's SSO still lands on dev Studio.🤔 Things to look at
The gate, polling, conflicts, permissions, and what isn't here
if:makesharper preview setupunable to verify that cleanup runs on close. It skips the author list, so a preview goes when its PR closes even after its author leaves the list; dropping one that doesn't exist does nothing. WithHARPER_PREVIEW_TARGETunset, neither workflow runs.pull_request_target, soworkflow_runcan't deploy. The deploy job polls for the build of its exact commit, by a run title naming the PR. Only a run listed users started and triggered counts: any writer can make a run with that title from a PR into a base branch whose workflow they wrote. Unlike documentation#797, another PR's build of the same commit can't be picked, and a failed API call isn't read as "no build started". It deploys nothing if the PR moves on or closes, and fails if the build fails, takes over 30 minutes, or never starts; re-running it once a build succeeds deploys that build.pull_requestrun for it, so the deploy job fails after 10 minutes and says why.stageget one. Both workflows filter on it, the default branch the trust policy pins; PRs intodevorprodrun neither.actions: readon the deploy job, beyond the example, reads the build's runs and downloads its artifact.⚖️ Alternatives
Four weighed
pull_request_target.workflow_rundeploy instead of polling: the trust policy pinsevent_name: pull_request_target, so that run could not exchange a token.previewinstead of a list: every push would wait for an approval.config.yaml, so a PR could load server code into CM's process.📋 Before this merges (Dawson)
All eight done: this PR itself changes no cluster or repository settings.
dev-1-studio) runsharper-pro:5.4.1; previews need5.4.0-alpha.2or later.tls.unixDomainSockets: trueis set besidehttp.securePort(9926), and Harper has restarted with its socket mirrors.threads.maxIsolated(default 8) caps live previews.http.corsAccessListlistshttps://*.app.dev.studio.harperfabric.com, and a preflight from a preview origin passes with credentials.*.app.dev.studio.harperfabric.comhas DNS and a certificate, and a Symphony proxy publishes the CM's 443: it ends TLS and hands each connection to Harper's own sockets with PROXY v2, a preview host to its preview, so the CM still sees client IPs. central-manager's version play deploys it (HarperFast/central-manager#1224).harper preview setup app=hdbms dataMode=shared target=https://dev.studio.harperfabric.com:9925created thehdbms-ci-previewrole and user and both trust policies (pinned topreview.yamlonstage, previews under.app.dev.studio.harperfabric.com, shared data), and setHARPER_PREVIEW_TARGET.HARPER_PREVIEW_AUTHORSrepository variable lists the six GitHub logins that get previews. Edit it to change who does.previewandpreview-cleanupexist, each allowing onlystage, with no required reviewers: the list is the gate.pull_request_targetfor.github/workflows/preview.yaml, which GitHub blocks in public repositories from December 2.🔧 Changes
.github/workflows/preview-build.yaml: the unprivileged build. It titles each runBuild PR Preview #<N>for the wait step to find, builds only for listed users, with a target set, builds in dev mode with noVITE_TELEMETRY_ENABLED, drops the hidden sourcemaps and uploadsweb/..github/workflows/preview.yaml: the deploy job, gated on the list, which needsactions: readto find the build by SHA, title and a listed starter, doesn't read a failed listing as "no build", writesconfig.yamlbefore downloading the artifact, runs the pinned action and shares data; and the cleanup job.src/lib/workflowPrivilege.test.ts: everypull_request_targetjob must carry the fork guard as a top-level&&term, outside every parenthesis (string literals stripped, whitespace collapsed; no top-level||, index or second${{ }}), and use no checkout, local action or reusable workflow. A job or step it can’t read fails. The refused shapes are listed beside it. After an artifact download, only deploy-action may run, so no step can execute what the PR built.src/lib/urls/getOAuthSignInUrl.tsand the Google and GitHub buttons: the buttons passcheckOAuthRedirectUrl(), the page's own/#/check-oauth. The CM keeps only its path unless the origin is in itspostLoginRedirectOrigins(on dev, previews: central-manager#1128).src/lib/urls/oauthHandoff.ts,src/features/auth/redeemOAuthHandoff.ts,src/features/auth/CheckOAuth.tsx:/#/check-oauthtakes theoauth_handoffcode out of the fragment, clears it, then redeems it with a credentialedPOST /oauth/handoffbefore the usual session check. A refused redeem still checks for a session.AGENTS.md: how a sign-in finishes on another origin..github/deploying.md: a PR previews section: who gets one, why previews share data, and that a preview to re-run a failed deploy once its build succeeds, and that a preview needs the CM's CORS entry, and how sign-in reaches it.✅ Verification
origin/main, branchstage): no problems, nothing unverified, nothing unsafe.tsc -b, oxlint, dprint, commitlint. Removing any new guard, in the workflow test or the sign-in code, turns a test red.hdbms-pr-2054) serves Studio through the CM's proxy. A deploy or cleanup by the workflow is not verified.More checks
main. A list term on the cleanup job'sif:is reported unverified, hence the step gate.--mode dev, noVITE_TELEMETRY_ENABLED) callsdev.studio.harperfabric.comand holds no Datadog token, GTM loader or Reo script: 30 MB without sourcemaps.verify-pr.yamlruns: fix(auth): verify email with the sign-up browser proof or the password #2050's head found its run and wroterun-id; a commit the PR had left, and merged feat(previews): turn on and manage PR previews from Studio #2045, exited 0 with a notice; another title matched nothing; a failing listing ran to the time limit.gh's jq against realverify-pr.yamlruns: a listed actor, in any case, selects the run; an unlisted one or an empty list selects nothing.CheckOAuth's order (clear, redeem, then the session check), and the redirect each button andgetOAuthSignInUrlbuilds (Google, GitHub).Build PR Preview #2054run uploadedpr-2054-build(12 MB).Review findings left open
cleanupshares neither the deploy's concurrency group nor itsby_ref. deploy-action re-reads the PR after deploying and drops its own preview if the PR closed (preview.ts), drops by app and PR number only (dropClosedPreview), and its README says to keep cleanup out of the deploy's group.🤖 Generated with Claude Code
Related PRs: 2 independent
Complexity: medium
Accepted behavior
Behavior the owner ruled intended, so there is nothing to file.
6 minor or nit
6553d6e7dab2178enone maintainability —.github/workflows/preview.yaml— cleanup omits by_ref: false that deploy passes — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-17ce41e45cbb2d33c6none concurrency —.github/workflows/preview.yaml— no supersession recheck between completed-build detection and deploy — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-17e4afb982f7aa04b1none maintainability —.github/workflows/preview-build.yaml— added comments narrate YAML or restate helpers — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-1798cb696214452d11none security —src/features/auth/CheckOAuth.tsx— preview redeems unsolicited oauth_handoff codes (login CSRF) — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-174340790679e977a6none reliability —src/features/auth/components/GoogleAuthenticationButton.tsx— absolute OAuth redirect assumes CM oauth =2.11 — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-1720999181cb5401efnone concurrency —.github/workflows/preview.yaml— cleanup not serialized with in-flight deploy — accepted: dawsontoth (PR owner) ruled it intended in the authoring session for studio#2054, 2026-11-17Ready-For-Promotion: 854693f urgency=normal late=folded
Review-Coverage: authored=claude; ran=cursor-composer,gemini,codex,cursor-grok; late=cursor-grok:adjudicated; adjudicated=domain; declined=muse; rounds=9; full=2 @ 854693f
Review-Attention: deep ~30m (sensitive: preview-build.yaml, preview.yaml +4; decisions: cleanup-ungated-by-author, artifact-consumer-allowlist, actor-allowlist-binding) @ 854693f