diff --git a/.baseline/product/README.md b/.baseline/product/README.md index 91da032..e6c3422 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -113,10 +113,21 @@ key is public by design, and RLS is what protects the data. ## Custom domain The app answers on workers.dev from its first deploy. To serve it on your -own domain, attach the domain to the Worker in Cloudflare (Workers & Pages → -`supabase-starter-web-prod` → Settings → Domains & Routes), then make it -prod's `app_origin` in `infra/terraform/supabase/terraform/main.tf` and merge -— the apply owns the project's Auth Site URL and redirect allow-list. +own domain: + +1. Attach the domain to the Worker in Cloudflare (Workers & Pages → + `supabase-starter-web-prod` → Settings → Domains & Routes). +2. Set `SITE_URL: https://` under `environments.prod.env` in + `intent.yaml`. It is the one setting for the product's origin: the app's + build bakes it into its absolute links (the Open Graph and Twitter + images), and the supabase apply makes it the project's Auth Site URL and + redirect allow-list. +3. Redeploy both: change the last line of `apps/web/component.yaml` and of + `infra/terraform/supabase/component.yaml` (`# orun: redeploy …`) in the + same pull request — a change to `intent.yaml` alone plans nothing. + +The apply owns the project's Auth URLs: an edit in the Supabase dashboard is +undone by the next apply. ## CI diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index a8e8b2d..04d622b 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -149,10 +149,12 @@ orun new --blueprint repo-blueprint.yaml \ - **Tables**: the protected page's tutorial creates `notes` with row-level security on and per-user policies. Every table in `public` needs RLS — the publishable key is public by design. -- **Custom domain**: attach it to the Worker in Cloudflare, then make it - prod's Auth Site URL in the product's supabase root (its README, "Custom - domain"). There is no domain phase: attaching a domain needs zone - permissions the brokered `workers-deploy` token does not carry. +- **Custom domain**: attach it to the Worker in Cloudflare, then set + `SITE_URL` under the environment's `env:` in the product's `intent.yaml` — + the app's absolute links and the project's Auth Site URL both follow it — + and redeploy web and supabase (the product's README, "Custom domain"). + There is no domain phase: attaching a domain needs zone permissions the + brokered `workers-deploy` token does not carry. - **Refresh the record**: re-run `--phase 02-docs`; it is idempotent, and it records whether sign-up asks for confirmation. diff --git a/ai/context/operations.md b/ai/context/operations.md index 98cd98b..9c4afbe 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -71,10 +71,14 @@ Caveats that matter: project): edit the template and run `pnpm run wire:fixture`. The deploy lanes render the real one in their own job tree; never commit a real project's URL or key. -- Supabase Auth sends its links (password recovery, and confirmation when it - is on) to the Worker's workers.dev origin — the supabase root sets it from - its `workersDevSubdomain` parameter, and owns it: an edit in the dashboard - is undone by the next apply. On a custom domain, change it there (below). +- The product's origin is ONE setting. Unset, it is the environment's + workers.dev URL (`-web-..workers.dev`); with a custom + domain, `SITE_URL` under the environment's `env:` in `intent.yaml`. The + app's build bakes it into its absolute links (the Open Graph and Twitter + images), and the supabase apply makes it Auth's Site URL and redirect + allow-list, where Supabase sends its links (password recovery, and + confirmation when it is on). The apply owns those Auth settings: an edit in + the dashboard is undone by the next apply. ## Auth and email @@ -152,7 +156,7 @@ orun integrations list --org --json && orun cloud check --org | require email confirmation | SMTP first, then `authEmailConfirmation: "true"` (above) | | add a table | create it with `enable row level security` and `auth.uid()` policies (above); the day the product has migrations, Lumen's `packages/db` + `db-migrate` is the shape, reading `SUPABASE_DB_URL` | | redeploy without a change | edit the last line of the component's `component.yaml` (`# orun: redeploy `) and merge — it is a deploy trigger, nothing reads it | -| serve a custom domain | attach it to the Worker in Cloudflare, then make it prod's `app_origin` in `infra/terraform/supabase/terraform/main.tf` and merge — the apply owns Auth's Site URL and redirect allow-list, so a dashboard edit would be undone | +| serve a custom domain | attach it to the Worker in Cloudflare, set `SITE_URL` under `environments.prod.env` in `intent.yaml`, and touch the redeploy line of both `apps/web/component.yaml` and `infra/terraform/supabase/component.yaml` in the same PR (an `intent.yaml` change alone plans nothing) | | headless credentials | `ORUN_TOKEN` (workspace-scoped) + `GITHUB_TOKEN` | The deployment record is the bootstrap's `02-docs` phase. Re-running it (the diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 859a3d3..db3d308 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -4,9 +4,13 @@ import { ThemeProvider } from "next-themes"; import "./globals.css"; import { SITE_NAME } from "@/lib/site"; -const defaultUrl = process.env.VERCEL_URL - ? `https://${process.env.VERCEL_URL}` - : "http://localhost:3000"; +// The product's public origin, which the Open Graph and Twitter images' +// absolute URLs resolve against. Not upstream's: it read VERCEL_URL, which no +// Cloudflare build has, so every deployed page pointed its images at +// localhost. Baked in at build — component.yaml's buildCommand sets it from +// the environment's SITE_URL (a custom domain), else its workers.dev URL, the +// same origin the Supabase project's Auth sends its links to. +const defaultUrl = process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000"; export const metadata: Metadata = { metadataBase: new URL(defaultUrl), diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index 53f5711..d8a859a 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -1,4 +1,3 @@ -import { DeployButton } from "@/components/deploy-button"; import { EnvVarWarning } from "@/components/env-var-warning"; import { AuthButton } from "@/components/auth-button"; import { Hero } from "@/components/hero"; @@ -18,9 +17,6 @@ export default function Home() {
{SITE_NAME} -
- -
{!hasEnvVars ? ( diff --git a/apps/web/app/protected/layout.tsx b/apps/web/app/protected/layout.tsx index 20c256b..4143202 100644 --- a/apps/web/app/protected/layout.tsx +++ b/apps/web/app/protected/layout.tsx @@ -1,4 +1,3 @@ -import { DeployButton } from "@/components/deploy-button"; import { EnvVarWarning } from "@/components/env-var-warning"; import { AuthButton } from "@/components/auth-button"; import { ThemeSwitcher } from "@/components/theme-switcher"; @@ -19,9 +18,6 @@ export default function ProtectedLayout({
{SITE_NAME} -
- -
{!hasEnvVars ? ( diff --git a/apps/web/component.yaml b/apps/web/component.yaml index 146b00f..7f7bf96 100644 --- a/apps/web/component.yaml +++ b/apps/web/component.yaml @@ -84,7 +84,15 @@ spec: # tree, from this environment's wiring document, so the Worker's vars and # the URL and key `next build` inlines are the real project's; dev # verifies with the fixture and has no wiring. - buildCommand: if [ "${ORUN_ENVIRONMENT}" != dev ]; then node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components supabase --env "${ORUN_ENVIRONMENT}"; fi && pnpm exec turbo run build --filter=@app/web + # + # The product's public origin (the Open Graph and Twitter image links are + # absolute): the environment's SITE_URL when intent.yaml sets one (a + # custom domain), else its workers.dev URL — the same origin the supabase + # root gives the project's Auth as its Site URL. The subdomain is written + # out rather than read from ${WORKERS_DEV_SUBDOMAIN}: the composition + # exports that to the smoke step only, so the build would see it empty. + # ${ORUN_ENVIRONMENT} the runner sets for every step. + buildCommand: if [ "${ORUN_ENVIRONMENT}" != dev ]; then node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components supabase --env "${ORUN_ENVIRONMENT}"; fi && NEXT_PUBLIC_SITE_URL="${SITE_URL:-https://supabase-starter-web-${ORUN_ENVIRONMENT}.your-workers-subdomain.workers.dev}" pnpm exec turbo run build --filter=@app/web # Smoke: the home page renders, signed-out header included, and # /api/health answers ok — the project's Auth reachable with the key this diff --git a/apps/web/components/deploy-button.tsx b/apps/web/components/deploy-button.tsx deleted file mode 100644 index a6b2c26..0000000 --- a/apps/web/components/deploy-button.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import Link from "next/link"; -import { Button } from "./ui/button"; - -export function DeployButton() { - return ( - <> - - - - - ); -} diff --git a/docs/phases/01-product.md b/docs/phases/01-product.md index e17be03..58b09dc 100644 --- a/docs/phases/01-product.md +++ b/docs/phases/01-product.md @@ -54,14 +54,15 @@ main and reads the order off it: `supabase → web`. org `SUPABASE_ORG_ID` names, with a generated database password; then, once the project reports `ACTIVE_HEALTHY`, its API keys are read and its Auth is set — Site URL and redirect allow-list - `https://-web-..workers.dev`, email - confirmation off. Its outputs are lease-published as `WIRING_SUPABASE` + `https://-web-..workers.dev` (or the + environment's `SITE_URL`), email confirmation off. Its outputs are lease-published as `WIRING_SUPABASE` (the URL and the publishable key), `SUPABASE_PROJECT_REF`, `SUPABASE_DB_PASSWORD` and `SUPABASE_DB_URL`. A new project takes five to seven minutes to come up. 2. **web** — installs, re-renders `wrangler.jsonc` from this environment's wiring document, builds with OpenNext (`next build` inlines the same URL - and key into the browser bundle), deploys `-web-`, and + and key into the browser bundle, and the same origin Auth was given into + the pages' absolute image links), deploys `-web-`, and smoke-tests it: the home page, and `/api/health`, which answers only when the project's Auth answers the key the build inlined. diff --git a/infra/terraform/supabase/terraform/main.tf b/infra/terraform/supabase/terraform/main.tf index 06fcb8c..8b71805 100644 --- a/infra/terraform/supabase/terraform/main.tf +++ b/infra/terraform/supabase/terraform/main.tf @@ -124,13 +124,23 @@ variable "authEmailConfirmation" { # --- Locals --- +# The product's own origin when the environment has a custom domain: SITE_URL +# under its `env:` in intent.yaml, which the runner exports to this job as it +# does to the app's build (apps/web/component.yaml) — one setting, so Auth's +# links and the app's absolute URLs name the same origin. Empty when unset. +data "external" "site_url" { + program = ["bash", "-c", "jq -n --arg url \"$${SITE_URL:-}\" '{url: $url}'"] +} + locals { supabase_org_id = var.supabaseOrgId supabase_region = var.supabaseRegion project_name = "${var.repo}-${var.environment}" # The environment's Worker, as apps/web/component.yaml names it: - # -web- on the account's workers.dev subdomain. - app_origin = "https://${var.repo}-web-${var.environment}.${var.workersDevSubdomain}.workers.dev" + # -web- on the account's workers.dev subdomain — unless SITE_URL + # names the environment's custom domain. + worker_origin = "https://${var.repo}-web-${var.environment}.${var.workersDevSubdomain}.workers.dev" + app_origin = coalesce(trimsuffix(data.external.site_url.result.url, "/"), local.worker_origin) } # --- Generate database password --- diff --git a/intent.yaml b/intent.yaml index ab1b553..b9ad726 100644 --- a/intent.yaml +++ b/intent.yaml @@ -130,6 +130,12 @@ environments: env: BASE_DOMAIN: supabase-starter.example.com + # SITE_URL, set under an environment's `env:`, is the product's public + # origin there — the one its Open Graph and Twitter image links are built + # on and the one the Supabase project's Auth sends its links to. Unset, it + # is the environment's workers.dev URL. Set it once a custom domain answers + # for the environment (README, "Custom domain"); the next deploy of + # apps/web and the next apply of infra/terraform/supabase pick it up. stage: description: Deployed on every merge to main, before prod. url: https://supabase-starter-web-stage.your-workers-subdomain.workers.dev diff --git a/specs/epics/README.md b/specs/epics/README.md index 3793f3e..ba09278 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`supabase-starter/`](./supabase-starter/) | **SS** | 🔄 SS4 in review | Vercel's Next.js and Supabase Starter, equivalent in code and function, on Cloudflare Workers with the Supabase project provisioned by Orun — and an Orun baseline that instantiates it in one landing (SS4) | +| [`supabase-starter/`](./supabase-starter/) | **SS** | 🔄 SS5 in review | Vercel's Next.js and Supabase Starter, equivalent in code and function, on Cloudflare Workers with the Supabase project provisioned by Orun — and an Orun baseline that instantiates it in one landing (SS4, `baseline-v1`) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/supabase-starter/IMPLEMENTATION-STATUS.md b/specs/epics/supabase-starter/IMPLEMENTATION-STATUS.md index ee05aee..8e6f9a5 100644 --- a/specs/epics/supabase-starter/IMPLEMENTATION-STATUS.md +++ b/specs/epics/supabase-starter/IMPLEMENTATION-STATUS.md @@ -9,7 +9,8 @@ the code departed from `design.md` or from the upstream template. | SS1 — the starter on Workers | ✅ Shipped | [#2](https://github.com/sourceplane/supabase-starter/pull/2) | | SS2 — the Supabase project from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/supabase-starter/pull/3) | | SS3 — ready to instantiate | ✅ Shipped | [#4](https://github.com/sourceplane/supabase-starter/pull/4) | -| SS4 — a baseline | 🔄 In review (SS-5) | this branch, `claude/blissful-ptolemy-c5ajf8` | +| SS4 — a baseline | ✅ Shipped, tagged `baseline-v1` | [#5](https://github.com/sourceplane/supabase-starter/pull/5) | +| SS5 — the product's own origin | 🔄 In review (SS-6) | this branch, `claude/blissful-ptolemy-c5ajf8` | ## Departures from the upstream template @@ -149,3 +150,41 @@ check`; `terraform fmt`, `init -backend=false` and `validate` on the root. Not verified: a Terraform apply (so neither the brokered OAuth token's reach to the API-keys and Auth-config endpoints nor `ACTIVE_HEALTHY` polling), a live deploy, a live bootstrap, and real email delivery (SS-I). + +## SS5 — the product's own origin (SS-6) + +Two defects `baseline-v1` shipped in every product: + +- **The image links named localhost.** `app/layout.tsx` built `metadataBase` + from `VERCEL_URL`, which no Cloudflare build has, so `og:image` and + `twitter:image` on every deployed page were `http://localhost:3000/…`. + `metadataBase` is now `NEXT_PUBLIC_SITE_URL`, which `component.yaml`'s + buildCommand bakes in: the environment's `SITE_URL` when `intent.yaml` sets + one, else `https://-web-..workers.dev` — written out + in the command (the rename rewrites the worker name and the subdomain), + because the composition exports `WORKERS_DEV_SUBDOMAIN` to the smoke step + only. Baked at build rather than read from the request (`headers()` in + `generateMetadata`), because the pages are prerendered (`cacheComponents`): + a request-time origin would have made every static page dynamic. +- **The header offered "Deploy to Vercel"**, cloning upstream's example to + Vercel. `components/deploy-button.tsx` is gone, and so is its use in the + home page and the protected layout. The tutorial's Vercel-only step + (`sign-up-user-steps.tsx`, shown only when `VERCEL_ENV` is set) never + renders on Cloudflare and is left as upstream wrote it. + +One origin, one setting: the supabase root reads the same `SITE_URL` (the +runner exports an environment's `env:` to every job of it) and makes it +Auth's Site URL and redirect allow-list, falling back to the same workers.dev +URL — so a custom domain is `SITE_URL` plus a redeploy of both components. +The rename's upstream list drops the deploy link and the demo URL, which +nothing in the tree carries any more. + +### Verified (SS5) + +The repository's checks; `testing/rebrand.test.sh`, `leak.test.sh` and +`placement.test.sh` (the product's build bakes its own origin, Auth's Site +URL follows SITE_URL, no Vercel clone link in the app); `e2e.test.sh` at +v2.78.4, which now asserts the served home page's `og:image` and +`twitter:image` start with the stage Worker's origin, that both images are +served, and that no "Deploy to Vercel" appears; `terraform validate` on the +root, and the origin it computes with and without `SITE_URL`. diff --git a/specs/epics/supabase-starter/README.md b/specs/epics/supabase-starter/README.md index 3bf4892..19658fe 100644 --- a/specs/epics/supabase-starter/README.md +++ b/specs/epics/supabase-starter/README.md @@ -8,8 +8,8 @@ The upstream code stays the code: the `@supabase/ssr` server/browser clients, th | Field | Value | |-------|-------| -| Status | ✅ SS0–SS3 shipped (#1–#4) · 🔄 SS4 — a baseline (SS-5) in review. Supabase apply and live deploy gated on a linked workspace | -| Cluster | **SS** (SS0–SS4) | +| Status | ✅ SS0–SS4 shipped (#1–#5; SS4 tagged `baseline-v1`) · 🔄 SS5 — the product's own origin (SS-6) in review. Supabase apply and live deploy gated on a linked workspace | +| Cluster | **SS** (SS0–SS5) | | Owner(s) | `apps/web` (the app) · `tests/web` (proxy tests) · `infra/terraform/supabase` (the project) | | Builds on | `lumen` conventions — the `supabase` Terraform root and the orun-secrets wiring; `cirrus-baseline` conventions for the repository shape | | Upstream | [vercel/next.js `examples/with-supabase`](https://github.com/vercel/next.js/tree/canary/examples/with-supabase) | @@ -34,3 +34,4 @@ The upstream code stays the code: the `@supabase/ssr` server/browser clients, th | SS2 — the Supabase project from Terraform | `infra/terraform/supabase`, the app's `secretEnv` and `dependsOn` | the root plans; the wiring keys match the template | | SS3 — ready to instantiate | README, as-built status | a reader can run, test, preview and deploy it | | SS4 — a baseline | card, build document, rename, bootstrap tooling, the product's README and context pack, tests | a new product goes from nothing to live on stage and prod in one landing, signing users up on its first deploy; Baseline CI green | +| SS5 — the product's own origin | `metadataBase` from the build's `NEXT_PUBLIC_SITE_URL`, SITE_URL read by the supabase root too, the Deploy to Vercel button removed | the served pages' image links name the product's origin; no Vercel call to action | diff --git a/specs/epics/supabase-starter/epic.yaml b/specs/epics/supabase-starter/epic.yaml index 8966979..5d90882 100644 --- a/specs/epics/supabase-starter/epic.yaml +++ b/specs/epics/supabase-starter/epic.yaml @@ -40,3 +40,10 @@ spec: - "the tutorial's table has row-level security keyed on auth.uid(); the e2e proves each user reads only their own rows and anon none" - "Baseline CI is green: contract tests, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the product's plans, and the end-to-end tier" tasks: [SS-5] + - name: "SS5 — the product's own origin" + exitCriteria: + - "every page's og:image and twitter:image are absolute URLs on the product's own origin — the environment's workers.dev URL, or its SITE_URL — never localhost" + - "SITE_URL is one setting: the build's metadataBase and the Supabase project's Auth Site URL both follow it" + - "the product offers its visitors no Deploy to Vercel button" + - "the e2e tier asserts both on the served home page" + tasks: [SS-6] diff --git a/specs/epics/supabase-starter/risks-and-open-questions.md b/specs/epics/supabase-starter/risks-and-open-questions.md index 3b9b01a..83de062 100644 --- a/specs/epics/supabase-starter/risks-and-open-questions.md +++ b/specs/epics/supabase-starter/risks-and-open-questions.md @@ -102,3 +102,15 @@ so a pull-request plan it makes holds the infra edge enforced rather than advisory. The product's own CI plans with its lane pin (v2.78.4), which reads them; the placement tier says when it cannot check them and the e2e tier, pinned at the lane version, does. + +## SS-L — The product's origin (RESOLVED, SS5) + +Next resolves the Open Graph and Twitter image links against `metadataBase`, +which upstream took from `VERCEL_URL` — never set on Cloudflare, so every +deployed page linked its images on `localhost:3000`. The origin is now baked +in at build (`NEXT_PUBLIC_SITE_URL`: the environment's `SITE_URL`, else its +workers.dev URL) rather than read per request, because the pages are +prerendered. The supabase root reads the same `SITE_URL` for Auth's Site URL, +so the two cannot disagree. Changing `SITE_URL` in `intent.yaml` alone plans +nothing (`--changed` maps no component to it); the README says to redeploy +both components with it. diff --git a/tasks/SS-6.TaskContract.yaml b/tasks/SS-6.TaskContract.yaml new file mode 100644 index 0000000..e66acac --- /dev/null +++ b/tasks/SS-6.TaskContract.yaml @@ -0,0 +1,29 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SS-6 + title: "The product's own origin" +spec: + goal: A product built from the baseline links its Open Graph and Twitter images on its own origin — the environment's workers.dev URL, or the SITE_URL a custom domain sets, the same origin the Supabase project's Auth is given — and offers its visitors no Deploy to Vercel button + affects: + - apps/web/app/layout.tsx + - apps/web/app/page.tsx + - apps/web/app/protected/layout.tsx + - apps/web/components/deploy-button.tsx + - apps/web/component.yaml + - infra/terraform/supabase/terraform/main.tf + - intent.yaml + - tooling/rebrand/rebrand.mjs + - testing/** + - .baseline/product/README.md + - ai/context/operations.md + - BOOTSTRAP.md + - docs/phases/** + - specs/** + - tasks/** + doneWhen: + - the served home page's og:image and twitter:image start with the stage Worker's own origin in the e2e tier + - no page links to Vercel's clone flow + - SITE_URL under an environment's env is the single setting for the app's absolute links and Auth's Site URL + gates: + - checks diff --git a/testing/e2e.test.sh b/testing/e2e.test.sh index d0b9712..1502ff1 100644 --- a/testing/e2e.test.sh +++ b/testing/e2e.test.sh @@ -30,8 +30,10 @@ # the product promises: the pages carry the product's name, the auth # pages render, `/protected` and every other guarded path send a # signed-out visitor to the login page, `/api/health` (answered only by -# the Worker) says how sign-up behaves, and the email-confirm route -# refuses a bad link with the error page, not a 500; +# the Worker) says how sign-up behaves, the email-confirm route refuses +# a bad link with the error page, not a 500, and the home page's +# og:image and twitter:image name the product's own origin — with no +# "Deploy to Vercel" anywhere; # 5. the user flow: a visitor signs up and is signed in at once, the Worker # reads the session from the cookies @supabase/ssr wrote and renders the # protected page with their claims; a forged session is refused; a wrong @@ -347,8 +349,20 @@ for want in ('href="/auth/login"', 'href="/auth/sign-up"', "Sign up your first u bad(f"the signed-out home page has no {want}") if "Supabase environment variables required" in home: bad("the home page says the Supabase variables are missing — the build did not inline them") -if "vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase" not in html.unescape(home): - bad("the header's Deploy to Vercel link to the upstream example is gone") +if "Deploy to Vercel" in text(home) or "vercel.com/new/clone" in html.unescape(home): + bad("the home page still offers to deploy the upstream example to Vercel") +# The image links are absolute, and on the product's OWN origin — the stage +# Worker this build was made for (SITE_URL unset), the one the Supabase +# project's Auth is given — not localhost, not Vercel's. +origin = f"https://{values['reponame']}-web-stage.{values['subdomain']}.workers.dev" +for attr, key, image in (("property", "og:image", "opengraph-image.png"), ("name", "twitter:image", "twitter-image.png")): + tags = re.findall(r'-web-..workers.dev") +if 'worker_origin = "https://${var.repo}-web-${var.environment}.${var.workersDevSubdomain}.workers.dev"' not in main_tf \ + or "app_origin = coalesce(trimsuffix(data.external.site_url.result.url, \"/\"), local.worker_origin)" not in main_tf \ + or "$${SITE_URL:-}" not in main_tf: + bad("main.tf no longer builds Auth's Site URL as SITE_URL, else https://-web-..workers.dev") for env in ("stage", "prod"): sj = jobs.get(("supabase", env)) exported = "\n".join(s.get("run") or "" for s in (sj or {}).get("steps") or []) @@ -399,6 +409,9 @@ for env in ("stage", "prod"): bad(f"web@{env} checks another config before the build: {steps.get('verify-app-structure','').strip()}") if "tooling/wire/live.mjs" not in steps.get("build-app", "") or "--components supabase" not in steps.get("build-app", ""): bad(f"web@{env} does not render its wrangler config from the Supabase wiring before it builds") + origin = f'NEXT_PUBLIC_SITE_URL="${{SITE_URL:-https://{repo}-web-${{ORUN_ENVIRONMENT}}.{sub}.workers.dev}}"' + if origin not in steps.get("build-app", ""): + bad(f"web@{env} does not bake the product's own origin into its build ({origin})") if f'EFFECTIVE_WORKER_NAME="{repo}-web-{env}"' not in steps.get("deploy", ""): bad(f"web@{env} deploys a Worker not named {repo}-web-{env}") if "/api/health" not in steps.get("smoke", "") or f'export WORKERS_DEV_SUBDOMAIN="{sub}"' not in steps.get("smoke", ""): diff --git a/testing/rebrand.test.sh b/testing/rebrand.test.sh index 1340eee..afd8423 100755 --- a/testing/rebrand.test.sh +++ b/testing/rebrand.test.sh @@ -3,13 +3,14 @@ # # Drives the real tooling/rebrand/rebrand.mjs over one-file trees and compares # the file. Each case is a shape this baseline's identity actually takes in the -# tree — the name seam, the worker name, the Worker's own origin, the -# placeholder domain, a secret ref, the `repo` the Supabase project is named -# after — and each runs through as many passes as a bootstrap might make, so a -# value written once must survive every later pass unchanged. Two things must -# NOT be renamed although they spell the slug: the upstream template's own -# links (its name is this baseline's slug), and a migration (its checksum is -# in the manifest and in every database it was applied to). +# tree — the name seam, the worker name, the Worker's own origin (the one the +# build bakes into the app's absolute URLs and the Supabase project's Auth +# sends its links to), the placeholder domain, a secret ref, the `repo` the +# Supabase project is named after — and each runs through as many passes as a +# bootstrap might make, so a value written once must survive every later pass +# unchanged. What must NOT be renamed: the upstream example's own link, and +# what merely spells `supabase` — a wiring token names the component, not this +# baseline. # # The identity is PINNED (fixtures/baseline-identity.supabase-starter.json) rather # than read from .baseline/identity.json: what this tests is the engine, and @@ -72,6 +73,10 @@ check "the worker name is re-prefixed, the environment suffix kept" \ check "the Worker's own origin: worker name and subdomain" \ "$acme" intent.yaml ' url: https://supabase-starter-web-stage.your-workers-subdomain.workers.dev' \ ' url: https://acme-notes-web-stage.acme.workers.dev' +check "the product's own origin the build bakes in when SITE_URL is unset" \ + "$acme" apps/web/component.yaml \ + ' buildCommand: pnpm build && NEXT_PUBLIC_SITE_URL="${SITE_URL:-https://supabase-starter-web-${ORUN_ENVIRONMENT}.your-workers-subdomain.workers.dev}"' \ + ' buildCommand: pnpm build && NEXT_PUBLIC_SITE_URL="${SITE_URL:-https://acme-notes-web-${ORUN_ENVIRONMENT}.acme.workers.dev}"' check "the subdomain the Supabase project's Auth Site URL is built from" \ "$acme" infra/terraform/supabase/component.yaml ' workersDevSubdomain: your-workers-subdomain' \ ' workersDevSubdomain: acme' @@ -106,10 +111,6 @@ check "a wiring token names the component, not the baseline" \ check "the upstream example's home is upstream's" \ "$acme" README.md '[Next.js and Supabase Starter](https://github.com/vercel/next.js/tree/canary/examples/with-supabase)' \ '[Next.js and Supabase Starter](https://github.com/vercel/next.js/tree/canary/examples/with-supabase)' -check "…and so is its Deploy to Vercel link, every parameter of it" \ - "$acme" apps/web/components/deploy-button.tsx \ - 'href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F"' \ - 'href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fwith-supabase&project-name=nextjs-with-supabase&demo-url=https%3A%2F%2Fdemo-nextjs-with-supabase.vercel.app%2F"' echo "── rebrand: a written value is not rewritten, in any later pass" contains='{"reponame":"supabase-starter-2","productname":"Next.js Supabase Starter 2","productdomain":"supabase-starter.example.com.au","githuborg":"sourceplane","subdomain":"your-workers-subdomain-2"}' @@ -156,7 +157,7 @@ verify "a leftover worker name fails" \ verify "a leftover code identifier fails (no rule renames it — so nothing may spell it)" \ "$acme" apps/web/app/x.ts 'export class SupabaseStarter {}' fail --values verify "the upstream example's links are not residue" \ - "$acme" apps/web/README.md 'the [example](https://github.com/vercel/next.js/tree/canary/examples/with-supabase) and its demo-nextjs-with-supabase.vercel.app' pass --values + "$acme" apps/web/README.md 'the [example](https://github.com/vercel/next.js/tree/canary/examples/with-supabase)' pass --values verify "a clean product passes" \ "$acme" package.json '"name": "acme-notes"' pass --values diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index 1aecaa7..da52f3b 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -11,8 +11,8 @@ // project's Auth Site URL is built from too) — to the values in a values // file, and leaves *org-owned* identity alone (the orun state backend, the // `sourceplane.io` manifest apiVersion, company mailboxes) and the UPSTREAM -// template's own links (the Next.js example, its demo, its Vercel deploy -// button: they name where the code came from, not this product). +// template's own links (the Next.js example the code came from: it names +// where the code came from, not this product). // // The engine is Cirrus's (sourceplane/cirrus-baseline tooling/rebrand): the // FROM side declared in `.baseline/identity.json`, every written value held @@ -204,21 +204,19 @@ function trackedFiles() { // ── The upstream template's identity (never rewritten) ───────── // -// This tree IS Vercel's `with-supabase` example. Where the code names its -// upstream — the header's "Deploy to Vercel" button, the tutorial's links, -// the app's README — it points at the example's own home, its demo and its -// deploy page, which a product's visitors may follow. None spells this -// baseline's slug today; they are protected all the same, so a rule written -// later cannot point them at a repository that does not exist, and they are -// allowed by the leftover sweep. +// This tree IS Vercel's `with-supabase` example. Where the docs name its +// upstream — the READMEs' first line — they point at the example's own home. +// It does not spell this baseline's slug; it is protected all the same, so a +// rule written later cannot point it at a repository that does not exist, and +// it is allowed by the leftover sweep. (The header's "Deploy to Vercel" button, +// which cloned the example to Vercel, is gone: a product on Cloudflare does not +// offer its visitors that.) // -// ENCLOSING FIRST: the masks are taken in this order and put back in it, so a -// link that CONTAINS another (the deploy link names the demo) must be masked -// whole before the one inside it is looked for. +// ENCLOSING FIRST, should a second link ever join this list: the masks are +// taken in this order and put back in it, so a link that CONTAINS another +// must be masked whole before the one inside it is looked for. const UPSTREAM = [ - /vercel\.com\/new\/clone\?[^\s"')]+/g, // the "Deploy to Vercel" link, every parameter of it /github\.com\/vercel\/next\.js\/tree\/canary\/examples\/with-supabase\b/g, // the example's home - /demo-nextjs-with-supabase\.vercel\.app/g, // its demo ]; // ── Protected literals (org-owned identity, never rewritten) ───