Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/rdyrct-email/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Browser preview is the fast loop; a real inbox is the truth.
3. Narrow-window check: drag the browser to ~380px. The card is `max-width:
520px` and must stay inside the viewport without horizontal scroll.
4. For a real-inbox check, send it to yourself through the dev flow (`bun run
dev` + `bun run mail`, read at `https://mail.rdyrct.localhost`), or paste
dev`, read at `bun scripts/dev-hosts.ts mail`), or paste
the HTML into Resend's Broadcast editor, which renders a preview before you
send.

Expand Down
5 changes: 3 additions & 2 deletions .claude/skills/ship-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ That decides the tool, too. A seeded user is already verified and shares one
password, so `bunx agent-browser` can just sign in:

```sh
APP=$(bun scripts/dev-hosts.ts app) # this checkout's dev URL
bunx agent-browser set viewport 1280 900
bunx agent-browser open https://rdyrct.localhost/login
bunx agent-browser open "$APP/login"
bunx agent-browser eval "localStorage.setItem('rdyrct:consent:v2','granted')"
bunx agent-browser fill 'input[type="email"]' someone@seed.test
bunx agent-browser fill 'input[type="password"]' seed-password-123
bunx agent-browser click 'button[type="submit"]'
bunx agent-browser open https://rdyrct.localhost/members
bunx agent-browser open "$APP/members"
bunx agent-browser screenshot shots/members.png
```

Expand Down
31 changes: 18 additions & 13 deletions .dev.vars.local.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Copy to .dev.vars (gitignored) for local dev.
# `bun run dev` copies this to .dev.vars (gitignored) on its first run, with
# an auth secret of its own. The worker tests read this file, not .dev.vars.

BETTER_AUTH_SECRET=dev-only-secret-change-in-prod
SUPERADMIN_EMAIL=you@example.com
APP_URL=https://rdyrct.localhost
APP_HOST=rdyrct.localhost
SHARED_LINK_HOST=rdyrct.localhost
# APP_URL, APP_HOST, SHARED_LINK_HOST, RESEND_BASE_URL and GOOGLE_EMULATOR_URL
# are not set here: `bun run dev` works them out for each checkout
# (scripts/dev-hosts.ts) and refuses to start if this file sets them.

# Email: point at the emulate.dev Resend emulator (bun run mail)
# Email: `bun run dev` starts the emulate.dev Resend emulator and points the
# Worker at it.
RESEND_API_KEY=re_local_emulated
RESEND_BASE_URL=https://mail.rdyrct.localhost
MAIL_FROM=rdyrct <no-reply@localhost>
# The founder's welcome email. Leave unset to send none.
WELCOME_FROM=Andrea at rdyrct <andrea@localhost>

# Polar (sandbox): https://sandbox.polar.sh
# Any value here switches billing on, placeholder included: plan limits and
# the billing page work, and the scenarios rely on that. Checkout itself
# fails until this is a real sandbox token and the product ids below match.
POLAR_ACCESS_TOKEN=polar_oat_replace_me
POLAR_WEBHOOK_SECRET=polar_whs_replace_me
# POLAR_WEBHOOK_SECRET: leave it out locally. `bun run dev` uses the secret
# `polar listen` signs forwarded webhooks with (`bun run polar:listen`).
POLAR_PRO_PRODUCT_ID=replace_me
POLAR_HOBBY_PRODUCT_ID=replace_me
# Yearly products, priced 10% below twelve months
Expand Down Expand Up @@ -55,13 +60,13 @@ WEB_RISK_API_KEY=

# Google sign-in. Leave all three blank to hide the "Continue with Google"
# button. For local dev, `bun run dev` starts the emulate google service
# behind portless at https://google.emulate.localhost, so the values below
# work as-is (the client id/secret are arbitrary, the emulator accepts any).
# behind portless and points the Worker at it, so the values below work
# as-is (the client id/secret are arbitrary, the emulator accepts any).
# It's seeded from google.emulate.yaml with two accounts: testuser@gmail.com
# (a regular account) and admin@gmail.com. Set SUPERADMIN_EMAIL above to the
# latter to test the platform admin locally through the emulator.
# In production, leave GOOGLE_EMULATOR_URL blank and set the real Google
# (a regular account) and admin@gmail.com. For the platform admin, the
# `admin` scenario at /__dev/scenarios is quicker; setting SUPERADMIN_EMAIL
# above to admin@gmail.com makes the emulator's account the admin instead.
# In production, leave GOOGLE_EMULATOR_URL unset and set the real Google
# OAuth client id/secret; the worker then uses Google's discovery URL.
GOOGLE_CLIENT_ID=test-client
GOOGLE_CLIENT_SECRET=test-secret
GOOGLE_EMULATOR_URL=https://google.emulate.localhost
25 changes: 5 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,8 @@ jobs:
key: node_modules-${{ runner.os }}-${{ hashFiles('bun.lock') }}
- name: Install dependencies
run: bun install --frozen-lockfile
# Worker tests read secrets (BETTER_AUTH_SECRET, TURNSTILE_SECRET_KEY, ...) out of
# the ambient miniflare env, which wrangler builds from .dev.vars. Without
# it those bindings are empty, so auth/rate-limit code 500s instead of
# behaving: same reason the old single-job workflow copied this before
# running verify.
- name: Configure worker test environment
run: cp .dev.vars.local.example .dev.vars
# No .dev.vars step: vitest.config.ts binds .dev.vars.local.example's
# values itself, so CI and every checkout run the same secrets.
- name: bun run ${{ matrix.suite }}
run: bun run ${{ matrix.suite }}

Expand Down Expand Up @@ -136,19 +131,9 @@ jobs:
key: node_modules-${{ runner.os }}-${{ hashFiles('bun.lock') }}
- name: Install dependencies
run: bun install --frozen-lockfile
# Both of them. .env carries the VITE_PUBLIC_POSTHOG_* pair that
# src/app/lib/posthog.ts reads, and CI used to run without it: the
# analytics path was never exercised here, and in dev mode a missing
# token makes the loader throw on every capture. A developer with a
# .env therefore ran a different suite from CI, which is how a green
# local run reached a red pipeline.
#
# The token is the placeholder from .env.build.example, so nothing lands in
# a real project, and the funnel test blocks the requests anyway.
- name: Configure browser test environment
run: |
cp .dev.vars.local.example .dev.vars
cp .env.build.example .env
# No .dev.vars or .env step: playwright.config.ts sets the worker's
# values (.dev.vars.playwright) and the build's (BUILD_ENV, with the
# placeholder PostHog token) itself, so a local run and CI match.
# On a PR, leanest runs only the specs this diff could affect and hands
# them to playwright unchanged. It fails open: a judge error or a
# low-confidence answer runs the full suite, and so does any change to
Expand Down
70 changes: 57 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,49 @@ path is **KV**; custom domains use **Cloudflare for SaaS**. Product host:

Always use **bun**, never npm/npx.

**Setting up and running the app is in the README's "Local development"**
(what you need, first run, day to day, LAN mode, integrations, and what to
do when something is off). Read it once; the rules below are the parts an
agent needs while working.

```sh
bun install
bun run dev # vite dev (Worker + SPA) via portless: https://rdyrct.localhost, plus the Google OAuth emulator at https://google.emulate.localhost
bun run mail # local Resend inbox via portless: https://mail.rdyrct.localhost (read: curl https://mail.rdyrct.localhost/emails -H 'authorization: Bearer test_token_admin')
bun run db:migrate:local # apply migrations to local D1
bun run dev # first run creates .dev.vars and migrates; starts app + mail inbox + Google emulator behind portless; prints the URLs
bun scripts/dev-hosts.ts # print this checkout's dev URLs (`... app` for one; read mail: curl "$(bun scripts/dev-hosts.ts mail)/emails" -H 'authorization: Bearer test_token_admin')
bun run db:reset:local # wipe local D1 + KV, re-apply migrations (start from scratch; restart dev after)
bun add <pkg> # dependencies
bunx agent-browser # real-browser checks: screenshots, clicking through pages. Use it for any visual verification; do not hand-roll headless Chrome
bun run db:seed:local # seed local D1/KV with fake data (run dev server first)
bun run db:seed:local # seed local D1/KV with fake data (run dev server first; finds this checkout's server itself)
bun run polar:listen # forward Polar sandbox webhooks to this checkout (needs the Polar CLI)
bun run deploy # build, apply D1 migrations, deploy; VITE_RDYRCT_SITE=1 (in .env) for rdyrct.com, otherwise a self-hosted copy
```

**Account states, one link each.** With the dev server running and the seed
loaded, `/__dev/scenarios` lists them: Pro, Hobby and Free owners, a
brand-new account, a member, a viewer, an org over its plan, one past its
grace period, a read-only org, one at the click cap, and a platform admin.
`/__dev/scenarios/<name>?to=/links` signs in as the seeded account in that
state and opens the page. Use it to check a UI change in every state before
calling it done. It exists only in dev builds (`src/worker/dev-scenarios.ts`)
and only signs in as `@seed.test` accounts.
loaded, `<app URL>/__dev/scenarios` lists them. The names:

| Name | Signs in as |
| ------------- | ----------------------------------- |
| `pro-owner` | a Pro owner |
| `hobby-owner` | a Hobby owner |
| `free-owner` | a Free owner |
| `fresh` | a brand-new account, no links |
| `member` | a member of someone else's org |
| `viewer` | a read-only viewer |
| `over-plan` | an org over its plan, in its grace |
| `grace-ended` | an org past its 30-day grace period |
| `locked-org` | a read-only (locked) org |
| `click-cap` | an org at its click cap |
| `admin` | the platform admin |

`<app URL>/__dev/scenarios/<name>?to=/links` signs in as that account and
opens the page. Use it to check a UI change in every state before calling it
done. Browser tests that need a signed-in account but are not about sign-up
use `signUpAndVerify` (`tests/e2e/resend.ts`), which calls
`POST /__dev/test-account` and skips the form (6 to 7 seconds a test); a
spec about sign-up itself uses `signUpThroughForm`. All of `/__dev` exists
only in dev builds (`src/worker/dev-scenarios.ts`); scenarios only sign in
as `@seed.test` accounts, and the test account route only creates new
addresses, never the `SUPERADMIN_EMAIL` one.

**Rolling back a release.** `bun run deploy` migrates before it deploys.
Wrangler has no down migrations, so a rollback is two steps:
Expand Down Expand Up @@ -71,8 +94,29 @@ run uses `.dev.vars.self-host`, not your `.dev.vars`: no email, no Polar,
no Google, so it also covers sign-up without a code, no billing and the
`/admin` warning.

**Dev addresses.** Rules for agents; the README explains the same for
people. `bun run dev` (`scripts/dev.ts`) names everything after the checkout: `rdyrct`, `rdyrct-mail` and `rdyrct-google` in the main
checkout, `rdyrct-<branch>`, `rdyrct-<branch>-mail` and so on in a git
worktree, so any number of checkouts run at once. portless picks the TLD:
`https://rdyrct.localhost` normally, `https://rdyrct.local` once its proxy
runs in LAN mode (`sudo portless service install --lan`), which is how a
second computer or a phone on the same network opens the dev server. Every
name is one DNS label because Windows finds only single-label `.local`
names on a network. The launcher hands the Worker its addresses (`APP_URL`,
`APP_HOST`, `SHARED_LINK_HOST`, `RESEND_BASE_URL`, `GOOGLE_EMULATOR_URL`;
`scripts/dev-host-keys.ts`), so `.dev.vars` must not set them: its values
would win, and the launcher refuses to start if it does. It also creates
`.dev.vars` from the example on a first run and applies the local D1
migrations. Never hard-code a dev URL (`rdyrct.localhost`, a port) in a
script, a doc or a test: ask `bun scripts/dev-hosts.ts` (`app`, `mail`,
`google`). Open the URL it prints, never `localhost:<port>`: sign-in
actions answer "Invalid origin" from any other address.
Sandbox billing webhooks: run `bun run polar:listen` beside it. When
`.dev.vars` sets no `POLAR_WEBHOOK_SECRET`, `bun run dev` hands the Worker
the one `polar listen` signs with, so forwarded events verify as they are.

**Local Cloudflare state**: while `bun run dev` runs, the Explorer API at
`https://rdyrct.localhost/cdn-cgi/explorer/api` exposes the local KV, R2, D1,
`<app URL>/cdn-cgi/explorer/api` exposes the local KV, R2, D1,
Durable Objects, and Workflows. Fetch that URL for the OpenAPI schema, then use
it to list, query, and manage local resources (e.g. inspect D1 rows or KV keys
without wrangler CLI calls).
Expand All @@ -83,7 +127,7 @@ without wrangler CLI calls).
bun run check # app + shared, worker, worker tests (three bun check runs)
bun run test # unit tests (bun test, tests/)
bun run test:worker # worker tests (vitest-pool-workers, tests/worker/)
bun run e2e:smoke # browser tests (playwright, tests/e2e/); needs .dev.vars
bun run e2e:smoke # browser tests (playwright, tests/e2e/); bring their own env, whatever your .dev.vars and .env say
bun run e2e:self-host # browser tests against a self-hosted build (own dist/, so not alongside e2e:smoke)
bun run verify # static checks + unit + worker tests, no e2e: the local gate
bun run verify:e2e # verify + the full e2e:smoke suite: what CI runs
Expand Down
Loading
Loading