Repository navigation
ci: verify live Clerk sessions and invitations - #158
Conversation
Astra reviewReviewed StandardsNo merge-blocking method or YAGNI findings. The exit-hook patch supports the issue's fail-not-green requirement; it is not speculative scope. Spec
Evidence: The live CI job reports both tests passing and both cleanup sweeps reporting zero remaining users. Locally exercised the runner with both keys absent and the direct config with each key absent: all exited 1 before global setup. An embedded-Postgres import preserved exit code 7. No live Clerk resources were created by this review. Summary: Standards: 0 blockers. Spec: 1 blocker — |
allisonmahmood
left a comment
There was a problem hiding this comment.
Code review — PR 158 vs #143
Two-axis review of origin/auth/142-cli-login-logout...HEAD (696604f, f8839ef). Extra passes: issue intent, method/YAGNI, Effect conventions, CI/secrets, and Hit-every-surface.
Standards
No Effect service findings.
No UI consistency findings.
Asked seams (not violations)
liveClient as Effect.gen (packages/auth/live/fixtures.ts:33-41). Correct as a module helper. Promoting it to Context.Service would break “a capability with one consumer stays a module” (effect-service-conventions / CLAUDE.md). Two call sites (sweep, Clerk.live.ts) still do not earn a service.
test/clerk.ts:16 Effect.runPromise(sweep) without ConfigProvider.layer. Not a hidden-runtime or missing-env bug. ConfigProvider is a Context.Reference whose defaultValue is fromEnv(). sweep → liveClient therefore reads the keys from the environment. scripts/test-clerk.ts:30-32 is explicit, not required. runPromise here is a vitest globalSetup teardown seam, same class as test/postgres.ts:56 — allowed application/framework boundary. The eslint rule only matches *.test.ts / *.spec.ts; this file is out of its scope by design.
inject("clerk") at module top (Clerk.live.ts:21). Matches inject("postgres") in packages/sql/src/testing.ts. Credentials stay out of provided context (LiveSettings is run id / emails / URLs); keys stay on the closed ConfigProvider (Clerk.live.ts:22-32, 44).
eslint process.env exemptions (vitest.clerk.config.ts, test/clerk.ts, scripts/test-clerk.ts). Same entrypoint pattern as cli.test.ts / render.test.ts. fixtures.ts takes env as a parameter and does not touch process.env. Clerk.live.ts uses Effect Config.
notify: true (InviteMail.ts:70). Clerk’s CreateParams.notify already defaults to true. Production mail behavior is unchanged; the flag documents the live tier. Not a product-shape change.
Judgement call (smell)
Possible Shotgun Surgery — patches/[email protected] + scripts/dev/src/postgres.test.ts + pnpm-workspace.yaml. Unrelated to Clerk sessions/invitations except that failed Vitest must not exit 0. “One concern per PR” would split it; it is load-bearing for this runner, tested, and noted in docs/DEVELOPMENT.md:275-276. Not a hard Effect or lint breach.
Dev-loop surfaces (DEVELOPMENT.md, patchy-dev-loop, AGENTS.md test tiers) are updated. Auth CONTEXT.md vocabulary is unchanged. Offline tests keep recording/failing InviteMail layers; live uses InviteMail.layer.
Spec
(a) Missing or partial
Branch protection “required” is not enacted in git. Spec: “required in branch protection; a skipped run satisfies the check so fork and Dependabot PRs pass on the offline tier.” docs/DEVELOPMENT.md records this as a maintainer step. The if: gate and skip-as-success behaviour are in ci.yml; the required-check box is not.
Nothing else from #143 is missing. Playwright is correctly left to #144.
(b) Scope creep
[email protected] patch + scripts/dev/src/postgres.test.ts. Not in #143. Embedded Postgres’ beforeExit hook was forcing exit 0 after a failed Vitest run; the patch keeps the child’s eventCode, and the new offline test asserts exit 7. It applies to all pnpm test, not just the live tier.
--cleanup. Spec asked for “an always() sweep that deletes the run’s users.” Vitest globalSetup teardown already sweeps. The extra pnpm test:clerk --cleanup flag is the CI always() step and a documented local recovery path, not a spec surface.
.agents/skills/patchy-dev-loop/SKILL.md is outside the spec’s listed surfaces (DEVELOPMENT.md, ci.yml, AGENTS.md).
(c) Looks implemented — is it wrong?
CI runs pnpm exec vitest run --config vitest.clerk.config.ts, not pnpm test:clerk. Intended fail-fast, not a miss. Spec: “failing at once when either is absent (the job decides whether to run; the config never skips itself)” and “pnpm test:clerk: sources dev.env when no key is in the environment.” The job must not source dev.env. Config load calls liveSettings() and throws on a blank secret. pnpm test:clerk is the local wrapper (dev.env + --cleanup).
RequireSession on /company is exercised, not over a socket. Spec: “send the JWT through the real RequireSession on /company” and “The door itself is the Playwright ticket’s.” The live test uses HttpRouter.toHttpEffect(AuthPages.layer) — same as CompanyPage.test.ts. GET /company is RequireSession.withViewer → Session.authenticate. A 200 with company HTML is the first-party page. A socket is not required for JWKS cookie verify.
CLERK_JWT_KEY is excluded. Spec: “with no CLERK_JWT_KEY (JWKS verification).” Closed ConfigProvider loads only CLERK_SECRET_KEY / CLERK_PUBLISHABLE_KEY from the environment; jwtKey is None, so Clerk fetches JWKS.
Fetch guard / offline include. Clerk config omits test/setup.ts (no fetch guard). Offline vitest.config.ts is **/src/**/*.test.ts only; packages/auth/live/**/*.live.ts cannot run under pnpm test.
notify: true is on production InviteMail.layer, not a test double. Spec: “through the live InviteMail layer (notify: true…).” Offline tests still use recording/failing layers. Clerk’s default was already true; this makes it explicit.
Mint path is SDK createSession + getToken = POST /v1/sessions then POST /v1/sessions/{id}/tokens. Emails are ci-<run>[email protected]. azp is asserted null. Job gate, secrets, CLERK_AUTHORIZED_PARTIES, AGENTS.md one-liner, and DEVELOPMENT.md CI app name match #124/#133.
Intent (#143)
#143 is a live tripwire, not coverage. Offline Session tests verify with a PEM and a fetch guard; InviteMail is a recorder. Production does neither: it fetches Clerk JWKS and POSTs invitations with mail on. The ticket exists so those two contracts can fail CI (and a laptop) without putting network in pnpm test, without waiting on Playwright’s door (#144), and without a skip-if-unset job that is green while testing nothing.
What landed maps onto that risk. Separate config, fail-fast on empty keys, Backend-API mint, real RequireSession.withViewer on /company, production InviteMail with notify: true, run-id-scoped sweep, closed config so an ambient CLERK_JWT_KEY cannot take the PEM path.
This cannot prove a browser session. Backend-API tokens have null azp; clerk-js cookies will not. Handshake, Account Portal, and device login remain #144. It infers JWKS from “no PEM”; it does not observe the fetch. “Required in branch protection” still has no merge teeth. Extra to the issue: the async-exit-hook patch (failed suite → exit 0) and keeping secrets out of vitest provide. Both kill false-greens.
Method and YAGNI
The method is the small one. Offline /company already goes through HttpRouter.toHttpEffect; the live file swaps PEM cookies for a Backend-API JWT and InviteMail.layer. A separate vitest.clerk.config.ts is the isolation: it omits test/setup.ts, so the fetch guard cannot fail a JWKS GET.
- A running server would fight “not your running dev instance.”
- Playwright is #144.
- Mock JWKS is the offline tier.
NodeHttpServer.layerTestwould assert a port, not JWKS.
The closed ConfigProvider is the load-bearing idea: only secret/publishable come from env; everything else (including an ambient PEM) cannot. Exact-email sweep is the real constraint, not ceremony. liveClient stays a module. --cleanup, dual sweep, and the 1–40 run-id regex all earn their keep (CI cancel, local recovery, Clerk’s 64-char email cap).
Taste, not a defect: the session case is named “without an authorized party” while CLERK_AUTHORIZED_PARTIES is set. It is a null-azp token with parties configured — the harder case, and what CI actually sets. Session.ts already documents Clerk 3.17 rejecting null azp when authorizedParties is passed to the SDK, then applying Patchy’s null-or-matching-origin rule.
Tiny cuts if you want them: the extra randomUUID() assignment (config and wrapper both do it) and fileParallelism: false (one file). I would not replace the method.
The async-exit-hook pin is extra to #143 and is the one YAGNI question. It is also the difference between a failed live suite and a green CI job, and it has a focused offline test. Keep it; it is not speculative generality.
CI / secrets (extra pass)
Empty GitHub secrets are ""; !secretKey?.trim() fails at config load. The job never sources dev.env. Eligible + missing secret fails the test step; always() then fails too (not a green sweep). f8839ef dropped keys from ProvidedContext. Backend calls on a normal run are well under 100/10s.
Judgement: sweep asserts zero users remain, then best-effort revokes pending invites. A query miss could leave a pending invite and still succeed. Isolation by run-id email still holds for other runs. Spec asked to delete the run’s users; this matches the letter.
always() is documented to run even when a started job is canceled. A job canceled before a runner starts never created fixtures.
Surfaces (extra pass)
Applied: dev loop (DEVELOPMENT.md, patchy-dev-loop, ci.yml, AGENTS.md), reverse states (create user → sweep; invite → revoke). N/A: wire contract, CLI, migrations, served pages, repo layout, glossary. packages/auth/live/ is not a package and is correctly not exported.
Optional drift, not a listed-surface miss: README still describes pnpm test / pnpm test:all; test:all.sh does not run or report test:clerk.
Summary: Standards 1 judgement (worst: shotgun-surgery of the Postgres exit-hook patch into this PR). Spec 1 partial + 3 extra-scope notes (worst: clerk-live is not yet a required branch-protection check). No hard standard violation; the live tripwire #143 asked for is in place.
Review dispositionRead both the Astra issue-comment review and the Reviews-tab review, and checked their findings against Fixed this pass: no new code changes. Neither review identifies a verified code defect requiring a patch, so there is no new commit or push; the already-pushed, tested head remains Confirmed gap — maintainer action
Kept as is, with reasons
Latest-head evidenceCI run 33966864764 completed successfully for head The live job log shows both tests passing and both cleanup sweeps reporting zero users for Code and CI are ready; required-check enforcement remains the sole escalation. Passing checks are not the same as configured required checks. |
|
lgtm. just checks right |
|
lgtm just checks |
612021a to
7185d4f
Compare
Implement #143 with fail-fast live configuration, scoped cleanup, and same-repository CI gating. Preserve test failures through the embedded Postgres exit hook.
f8839ef to
c89c326
Compare
The live Clerk tier did not exercise the Account Portal login door or a browser-confirmed `patchy login` end to end. Add serial Playwright specs for both workflows against an isolated, seeded server and the packed CLI. Cover session renewal, cross-company refusal, machine revocation and run-scoped Clerk cleanup. Run them through `pnpm test:clerk` and the gated `clerk-live` job, with local headed-run instructions. Stacked on #158 (`auth/143-live-clerk-vitest-tier`); this PR targets that branch, not `main`. Closes #144. Validation: combined live tier passed locally (2 Vitest tests and both browser specs), final device-login spec passed after review, and cleanup verified zero run-scoped users. All 322 offline tests, typechecking, lint and formatting passed. Standards and spec reviews completed; the 401 assertion finding was fixed. CI results for this PR are pending. Implemented with OpenAI GPT-6 Astra in the Oh My Pi harness.
Offline auth tests cannot prove that real Clerk sessions verify through JWKS or that Clerk accepts invitation delivery requests. This adds a separate live tier while keeping
pnpm testoffline.pnpm test:clerkloads the developer's keys, exercises/companythrough realRequireSession, and creates, lists, revokes and re-sends invitations. Fixtures are run-scoped and swept after testing, with an additionalalways()sweep in CI. The job runs on same-repository PRs except Dependabot and onmain; missing secrets fail immediately. Credentials stay out of the shared Vitest context.Verification also exposed an embedded Postgres exit-hook bug that turned failed suites into exit 0. A pinned dependency patch and regression test preserve the failure status.
Stacked on #157 (
auth/142-cli-login-logout). This PR targets that branch and contains only the live-tier changes.Verification
Marking
clerk-liverequired is a maintainer step. Branch protection was not changed; the CI application's repository secrets already exist.Closes #143.
Built with OpenAI GPT-6 Astra in the Oh My Pi harness.