Repository navigation
Closed
Labels
wayfinder:grillingWayfinder ticket: grilling
Description
Question
pnpm dev and the vitest suite must keep working without a browser and, ideally, without a Clerk account. With the sign-in research and the door decision in hand:
- Keys.
pnpm devreads the Clerk development keys from the developer's environment and passes them through; with none set the server still boots, the CLI path works through the seeded machine token, and the door fails closed with a message that names the variables. ➡️ That; no dev-bypass flag. - The seed. One company (
Patchy Dev, handlepatchy-dev), one admin user, one machine token — the same rows in the dev runner and the vitest template, as today. ➡️ That. - Tests. Sessions are signed with a test keypair and verified through
jwtKey, so no test touches Clerk; the door's tests drive cookies and redirects throughNodeHttpServer.layerTest. ➡️ That, if the research confirmedjwtKeyis supported for it. - The packed-CLI e2e.
patchy loginis exercised against the real server up to the handoff (URL and code printed as JSON); the confirm half is a server test, not an e2e. ➡️ That. - Docs and skills.
docs/DEVELOPMENT.md, thepatchy-dev-loopskill and the env registry name the new variables. ➡️ A checklist line on the build ticket.
From the prototype (#119, resolved 2026-09-03)
Question 3 is answered offline on the branch: sessions signed by an RSA-2048 test keypair verify through CLERK_JWT_KEY with zero network (a fetch guard fails any call), the door is driven in memory with HttpRouter.toHttpEffect and on a socket with redirect: "manual", and a pk_live_ fake key reproduces the production shape, return leg included. The session should also decide:
- The seeded vitest template is dead everywhere, not just in the
it.layerpath:Testing.layercreates an empty database and the template's only consumer has no callers (pre-existing; the dev-loop bullet inCLAUDE.mdis wrong). ➡️ EitherTesting.layerclones the seeded template, or every suite seeds through a shared fixture like the prototype's@patchy/auth/testing. - The packed-CLI e2e dies at its build step until the door's code passes the Effect diagnostics, then fails
assertVieweron status and oncache-control. ➡️ It follows The login door on a tier 0 page #120 item 13: publish a public patch for the existing table and add one doored case; CI never has Clerk keys, so the doored case uses the keypair fixture. CLERK_JWT_KEY. The runner already forwards everyCLERK_*name; the key survivesdev.envin any quoted form (a one-line\nform needs double quotes; unquoted or single-quoted one-line values yield garbage and a silent sign-in loop);clerk env pullnever writes it. The SDK's own JWKS cache makes it a nicety (one 46–227 ms fetch per process per five minutes). ➡️ Do not ship it as configuration, or validate it withcreatePublicKeyat boot if kept; the "no-clobber on re-pull" claim was not tested.CLERK_AUTHORIZED_PARTIESstays unset locally: two worktrees with per-port lists evict each other's session on every sign-in.- Headless sign-in helpers must send a real Chrome user agent on http (FAPI omits
Securefor HeadlessChrome and Safari UAs on an httpredirect_url; not on https) and retype the email code when the portal drops it; Playwright'scontext.requestwithholdsSecurecookies onhttp://127.0.0.1.
From the door (The login door on a tier 0 page, resolved 2026-09-03)
- Question 1 changes: the Clerk keys are required at startup, like the bootstrap token. There is no boot-without-keys and no door that fails closed at request time.
pnpm devalready hands the keys through; a developer without~/.config/patchy-cloud/dev.envgets a startup error naming the variables. - The doored shell loads Clerk's headless frontend script from the Frontend API host, which does the token refresh. Offline door tests (question 3, item 6) cover the server half: verification through the keypair, the handshake redirect, the 401 shape, the CSP with the FAPI host. Nothing in vitest runs the shell's script.
- Item 7: the packed-CLI e2e publishes a public patch for the existing viewer assertions and adds one doored case asserting the 401 with
no-storefrom the keypair fixture. - Item 8 and 9 stand;
CLERK_AUTHORIZED_PARTIESis still per host, and the domain ADR notes that a per-company subdomain later needs one entry per host.
From company and user (Company and user: the minimum that ships, and where the company lives, resolved 2026-09-03)
- Question 2 stands: one company, one admin user, one machine token; no seeded invites.
- Inviting calls Clerk's Backend API to send the email, so the invite tests need a Clerk client layer they can swap: an alternate layer that records the call and one that fails, never a network call and never a mock. Create-or-join and deactivation touch no Clerk API and test offline through the keypair sessions.
From the data model (Data model, packages and migration, resolved 2026-09-04)
- Question 2 sharpens: the seeded token is the seeded admin user's machine token (
operator = false), and the operator token isPATCHY_BOOTSTRAP_API_TOKENas today. The operator cannot publish, sopnpm seed:devand the packed-CLI e2e publish as the seeded user throughPATCHY_API_TOKEN. - The migrator is called in four places, not three: the server, the dev runner,
test/postgres.tsandapps/server/src/test/server.ts. Item 6's answer must cover all four. - The baselines are rewritten (companies 1, auth 2, patches 3); nothing is deployed.
Metadata
Metadata
Assignees
Labels
wayfinder:grillingWayfinder ticket: grilling
Activity
allisonmahmood commentedon Sep 4, 2026
Resolution
Grilled on 2026-09-04 in two rounds, with one research pass over Clerk's OpenAPI specs (bapi, fapi), clerk.com/docs and the
clerk/javascriptsource. The findings are at the end of this comment; nothing was branched.One seed, cloned by every test (questions 1, 6).
Testing.layerclones the seeded vitest template instead of creating an empty database, so everyit.layersuite and the server test layer start with Patchy Dev, its admin user and its machine token; package fixtures add their own rows on top, aspackages/patches/src/test/fixtures.tsdoes today. The migrations argument goes, since the template already carries all three baselines;packages/sqlkeeps one empty-database layer for its own migrator tests; the deadcreatePostgresTestDatabaseis deleted. The migrator then has three call sites (server, dev runner,test/postgres.ts), not the four counted on Data model, packages and migration, andAGENTS.md's dev-loop bullet becomes true again.The seed (questions 2, 13). One company (
Patchy Dev, handlepatchy-dev), one admin user with a fixedclerk_user_id(user_dev), email[email protected], namePatchy Dev, and that user's machine token (patchy-dev-token,operator = false). The Clerk user id is overridable: the runner reads an optionalPATCHY_DEV_CLERK_USER_IDfromdev.env; when set, the seeded admin is the developer's own Clerk user, so signing in to the local instance lands in Patchy Dev as its admin, owning what the CLI publishes. Unset (tests, fresh clones) the fixed id stands and a real sign-in lands on create-or-join, which is itself a path worth walking locally. No real Clerk key or token is ever committed; offline fixtures use fake keys whose Frontend API host is under.invalid.The operator locally (question 14). The runner hands the server a fixed
PATCHY_BOOTSTRAP_API_TOKEN, and.local/dev/envexports it asPATCHY_OPERATOR_TOKENbesidePATCHY_API_TOKEN, which stays the seeded user's machine token because that is what the CLI publishes with. Server tests keep bootstrappingdev-token. What the operator token is for, unchanged from Device login and the data-model ticket: the moderation loop (read a flagged patch and who holds it, list that principal's patches, disable, revoke the token) and pin/unpin. It cannot publish. Thepatchy-mint-tokenskill is deleted.Where the seed lives (questions 3, 16).
@patchy/authgains two entries.@patchy/auth/seedholdsDEV_SEEDandapplyDevSeed, imported by the dev runner,test/postgres.tsand the packed-CLI e2e; Auth depends on Companies, so the seed writes the company and user rows as well as the token.@patchy/auth/testingholds the RSA-2048 keypair,clerkEnv, the session signer and the fetch guard, installed on import, that refuses and records any request not aimed at loopback. Two entries because the runner must never import a module that rewiresfetch.CLERK_JWT_KEY(question 4). Kept as optional config, validated withcreatePublicKeyat boot so a mangled PEM fails at startup instead of causing a silent sign-in loop. Documented as test-facing; a developer leaves it unset. The offline suite sets it throughConfigProvider; the tested session layer is the production one, only its configuration differs.CLERK_AUTHORIZED_PARTIESstays unset locally.CI, two tiers, both required (questions 10, 11, 12).
main, gated ongithub.event.pull_request.head.repo.full_name == github.repository. Two jobs against a dedicated CI Clerk application, never the developer's instance. (a) A live vitest config: create a+clerk_testuser named for the run id, mint a session through the Backend API (POST /v1/sessions, testing-only and refused on production instances, thenPOST /v1/sessions/{id}/tokens), send that JWT through the real door verifying against Clerk's JWKS with noCLERK_JWT_KEY, exercise invitation create, list, revoke and re-invite, and delete the user in analways()step. (b) Playwright: sign in at the Account Portal with a+clerk_testaddress and code424242behind a Testing Token, land on a doored patch (login-doorspec), and confirm apatchy loginfrom the signed-in browser (patchy-loginspec). One spec per workflow, sign-ins few and serial because the Frontend API limits sign-ins per IP and GitHub runners share IPs. A skipped gated job satisfies a required check, so Dependabot RC bumps pass on the offline tier.CLERK_SECRET_KEYandCLERK_PUBLISHABLE_KEYfrom the environment;pnpm test:clerksourcesdev.envso a developer runs them against their own development instance, where the run-namespaced+clerk_testusers are swept the same way. One code path, two key sources.pnpm teststays offline. Nothing requires local testing; everything allows it.The packed-CLI e2e (question 6). Applies the dev seed to its own embedded Postgres, publishes as the seeded user's machine token, exercises
patchy login --jsonup to the handoff, and adds one doored case: a company-scope patch fetched with no cookies answers 401 withcache-control: private, no-store, a local answer that needs no key. The self-service minting cases go. One e2e per workflow, never one spanning everything.Invites (questions 7, 15). No HTTP-level fake of Clerk. Companies owns an
InviteMailservice over@clerk/backend's invitations, with a live layer, a recording layer and a failing layer; the offline suite swaps, the live tier runs the real one. The live layer always sends (notify: true), as production must. The live test invitesci-<run>[email protected]; whether Clerk suppresses invitation mail to+clerk_testaddresses is undocumented, and a bounce to a.testdomain is the accepted worst case, checked on the first live run.Browser helpers (question 8). The prototype's headless portal helpers do not ship. The Playwright specs replace them.
Docs (questions 9, 17). A checklist line on the build tickets, not a decision:
docs/DEVELOPMENT.mdnames the two Clerk keys as required at startup,CLERK_JWT_KEYas optional and test-facing, the two dev tokens in.local/dev/env,PATCHY_DEV_CLERK_USER_ID, and how to run the live tiers locally; thepatchy-dev-loopskill gets the two-token env line;ci.ymlgains the gated jobs; the CLI README is untouched.Clerk facts the decisions rest on (verified 2026-09-04)
POST /v1/sessions(user_id) is "intended only for use in testing, and is not available for production instances";POST /v1/sessions/{id}/tokensreturns{ jwt }withexpires_in_seconds30–315360000. Together: a real signed session for a real user, no browser, no Frontend API.POST /v1/sign_in_tokensalso exists (ticket exchangeable at the Frontend API withstrategy=ticket), unused here.+clerk_testsubaddress takes code424242and sends no mail; test mode is on by default on development instances. Verification links still send. Test addresses are exempt from the 20 SMS / 100 emails per month cap. docsPOST /v1/testing_tokens,__clerk_testing_tokenquery param) bypass bot detection only, usable from plainfetch; production instances supported since 2025-08-19.@clerk/testing'ssetupClerkTestingTokenis a Playwright route interceptor that appends the param and flipscaptcha_bypass; nothing in it helps a Node test. overview@clerk/backendhas no official test or mock mode; the monorepo'spackages/mswis a private example.jwtKeyis documented as networkless verification (authenticate-request); the publishable-key format (pk_test_+ base64 of<frontend-api>$) is source-only (packages/shared/src/keys.ts).POST /v1/invitationstakesnotify(default true, the only no-send switch),ignore_existing,expires_in_days; list withstatusandquery;POST /v1/invitations/{id}/revoke; an existing user cannot be invited. Rate limit 100 per hour.DELETE /v1/users/{id}in a loop); Backend API 100 requests per 10 s per secret key; Frontend API per IP, 5 sign-in creates and 3 factor attempts per 10 s. system-limits Whether+clerk_testusers count toward the 100 is undocumented; assume yes and sweep. Two concurrent runs share every budget, so fixtures are namespaced by run id.github-actions(rotate-api-keys). A leakedsk_test_key is a total compromise of its instance.Carried to the other tickets
Testing.layerand the three migrator call sites; the seed's rows,PATCHY_DEV_CLERK_USER_IDandPATCHY_OPERATOR_TOKEN; the two@patchy/authentries;CLERK_JWT_KEYas boot-validated optional config; the two CI tiers with the gate expression and thepnpm test:clerkscript; the live vitest config and the two Playwright specs as build tickets of their own, blocked on the CI application task below; the packed e2e's seed, handoff and doored case;InviteMail's three layers; the docs checklist above; thepatchy-mint-tokenskill's deletion.Resolved above; decision indexed on the auth map.
allisonmahmood commentedon Sep 4, 2026
Resolved above; decision indexed on the auth map.
allisonmahmood commentedon Sep 4, 2026
Addendum, 2026-09-04. The operator-as-token parts of this resolution (the
operatorkind of/api/me, thetok_operatorrow withuser_id NULLand theoperatorflag,PATCHY_OPERATOR_TOKENin the dev loop) are reopened on The operator is a company, not a token. Read that ticket's resolution over these lines; the rest of this resolution stands.allisonmahmood commentedon Sep 4, 2026
Addendum, 2026-09-04. Resolved on The operator is Patchy, not a token: the operator is Patchy with its own later login and dashboards, so every operator-as-token part of this resolution is gone — the
operatorkind of/api/me(one shape now),tok_operator, the nullableuser_idandoperatorflag (user_id NOT NULL),PATCHY_BOOTSTRAP_API_TOKENandPATCHY_OPERATOR_TOKEN, theadminscope, and the moderation and pin routes.revokestays only as the bearer revoking itself. The rest stands.