Skip to content

ci: verify live Clerk sessions and invitations - #158

Merged
allisonmahmood merged 2 commits into
mainfrom
auth/143-live-clerk-vitest-tier
Sep 6, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
auth/143-live-clerk-vitest-tier

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

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 test offline.

pnpm test:clerk loads the developer's keys, exercises /company through real RequireSession, and creates, lists, revokes and re-sends invitations. Fixtures are run-scoped and swept after testing, with an additional always() sweep in CI. The job runs on same-repository PRs except Dependabot and on main; 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

  • Local live tier: 2 tests passed; repeated cleanup confirmed zero run users.
  • Offline suite: 322 tests passed, fetch guard silent.
  • Lint, typechecking, formatting and packed CLI e2e passed.
  • Missing-secret failures and the workflow gate's main/same-repo/fork/Dependabot cases checked locally.
  • Standards and Spec reviews completed; the secret-handling finding was fixed and rechecked.

Marking clerk-live required 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.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines labels Sep 5, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed origin/auth/142-cli-login-logout...f8839efa676e1c4e856efdf697287cbf1fc8e77d against #143, one pass, no subagents. Merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The exit-hook patch supports the issue's fail-not-green requirement; it is not speculative scope.

Spec

  1. [P2 · intent] Make clerk-live a required check before merging. docs/DEVELOPMENT.md:328–329 leaves this as a maintainer step, but ci: the live Clerk tier in vitest against the CI application #143 explicitly requires the job to be “required in branch protection.” This is still missing: GitHub's branches/main/protection/required_status_checks endpoint returns 404 / Branch not protected, and rules/branches/main returns []. The live job runs, but a failing result does not prevent a merge, so the required live tier is not enforced. Have a maintainer require clerk-live on main through branch protection or an active ruleset before treating ci: the live Clerk tier in vitest against the CI application #143 as complete. This is a repository-setting prerequisite, not a request for more test machinery.

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 — clerk-live is not enforced as a required check.

@allisonmahmood allisonmahmood left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.layerTest would 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.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review disposition

Read both the Astra issue-comment review and the Reviews-tab review, and checked their findings against f8839efa676e1c4e856efdf697287cbf1fc8e77d.

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 f8839ef.

Confirmed gap — maintainer action

clerk-live is green but is not enforced as required. gh pr checks 158 --required reports no required checks. This is a real repository-policy gap, not something a green run fixes. The implementation instructions explicitly said not to change branch protection and to leave marking clerk-live required to a maintainer; that constraint still applies. The existing documentation is accurate. A maintainer must make clerk-live required on main before the issue's enforcement criterion can be signed off. I have not changed repository protection or merged this PR.

Kept as is, with reasons

  • Postgres exit-hook patch and regression: load-bearing, not speculative scope. Without it a failed suite could exit 0. Re-ran the regression: the child preserves exit 7 and the test passes. Splitting it out would leave this live tripwire capable of false greens.
  • --cleanup, two sweep paths and run-id defaults: Vitest teardown covers ordinary completion; CI's explicit always() step and the documented local command cover recovery. Wrapper and direct-config entrypoints each need a default, and ??= preserves a shared run id. Serial files keep Backend API traffic bounded.
  • Dev-loop skill/docs: required by the repository's Hit-every-surface guidance. The live tier stays opt-in; adding it to test:all would introduce real credentials/network into the existing offline workflow. Playwright remains ci: Playwright specs login-door and patchy-login #144.
  • Effect helpers, teardown boundary, injected settings and entrypoint exemptions: match existing test/framework seams. Credentials stay out of ProvidedContext and use Config.redacted. Keep the runner's explicit provider: it loads dev.env after an earlier Effect run, so cleanup must read the refreshed environment. Global setup starts with CI's environment already present.
  • Direct config in CI, in-memory /company, closed configuration and notify: true: exercise the requested real Session/RequireSession and InviteMail boundaries without adding a server/browser seam. The token has absent/null azp while authorized parties are configured; the current test name refers to the token, not an unset allowlist. Wording changes are optional, not a correctness fix.
  • Invitation sweep concern: no demonstrated query miss; API failures are not swallowed. Exact-email matching protects other runs, and live tests verify pending/revoked/re-invited states. No speculative polling or cleanup abstraction added.

Latest-head evidence

CI run 33966864764 completed successfully for head f8839ef. All seven reported checks pass: clerk-live, cli-smoke, lint, test (22), test (24), dependency-review, and label.

The live job log shows both tests passing and both cleanup sweeps reporting zero users for 33966864764-1. Fresh local probes with each Clerk key absent exit 1 before setup. GitHub reports the stacked PR mergeable and clean.

Code and CI are ready; required-check enforcement remains the sole escalation. Passing checks are not the same as configured required checks.

@vsrikar08

Copy link
Copy Markdown
Collaborator

lgtm. just checks right

@vsrikar08

Copy link
Copy Markdown
Collaborator

lgtm just checks

@allisonmahmood
allisonmahmood force-pushed the auth/142-cli-login-logout branch from 612021a to 7185d4f Compare September 6, 2026 13:06
Base automatically changed from auth/142-cli-login-logout to main September 6, 2026 13:09
Implement #143 with fail-fast live configuration, scoped cleanup, and same-repository CI gating. Preserve test failures through the embedded Postgres exit hook.
@allisonmahmood
allisonmahmood force-pushed the auth/143-live-clerk-vitest-tier branch from f8839ef to c89c326 Compare September 6, 2026 13:09
@allisonmahmood
allisonmahmood merged commit f90bad5 into main Sep 6, 2026
7 checks passed
@allisonmahmood
allisonmahmood deleted the auth/143-live-clerk-vitest-tier branch September 6, 2026 13:14
allisonmahmood added a commit that referenced this pull request Sep 6, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: the live Clerk tier in vitest against the CI application

2 participants