Skip to content

Typecheck the code examples in doc comments in CI - #763

Open
Nicolapps wants to merge 1 commit into
graphite-base/763from
nicolas/check-doc-examples
Open

Nicolapps wants to merge 1 commit into
graphite-base/763from
nicolas/check-doc-examples

Conversation

@Nicolapps

@Nicolapps Nicolapps commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

The broken httpCookies example fixed in #734 got through CI because tsc doesn't read code in doc comments, and nothing else checked it. TypeDoc copies these examples into the API reference and the shipped .d.ts.

This adds pnpm check:doc-examples (scripts/checkDocExamples.ts) and runs it in the TypeScript workflow after pnpm build. The script finds every ```ts / ```tsx block in a /** */ comment under packages/core/src and typechecks each one as a module of a sample app.

The sample app: packages/doc-examples

A private Convex app (not an example to copy) that installs every component and sets up every sign-in method in one convex/auth.ts, including a generic setupOauth provider ("acme"). Its _generated/ is committed, and the existing codegen workflow keeps it up to date. A Next-style root auth.ts with setupConvexAuthServer is reachable as @/auth.

Thus api, internal, components, env and ctx in the examples have their real generated types, not any.

How an example is checked

  • tsx examples go in the app's src/, examples from ssr/ go in app/, and the rest go in convex/, so ../convex/_generated/api, ./_generated/server and @/auth resolve to real files. The app's tsconfig.json is used.
  • If an example uses a name it doesn't import, the script adds an import from the first module that exports it: the commented file's own entry point of @convex-dev/auth, the other entry points, react, convex/*, the app's _generated/api and _generated/server, and then the commented file itself.
  • A small prelude declares ctx (the app's QueryCtx), app (its convex.config.ts), the component definitions, react-router's Navigate, and expo-secure-store.
  • ```ts skip-check opts a block out. It's used once, for the internal buildCallbackRouter example, which refers to names of a component.

With the old httpCookies example put back, the check reports the unknown authApi option and the RefreshResult being passed as a token bundle. Putting api.auth.startSignInAcmee, env.RESEND_KEY, or components.authPassword (in place of authGoogle) into an example also makes it fail.

Examples fixed

The examples that the check found broken are fixed in the PRs below this one, one PR per fix: #767, #768, #769, #770, #771, #772, #773.

The script also runs in preversion, and AGENTS.md describes it and the sample app.

A finding

setupOauth takes the user callbacks as a direct argument, not through attachUserCallbacks. As a result, passing internal.users.createUserAcme from a module that is part of api fails with TS7022 (the type of api depends on itself). The sample app works around it with makeFunctionReference. Apps that use the generic OAuth method would hit the same error.

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
auth-v2 Ready Ready Preview Oct 21, 2026 1:31am UTC
1 Skipped Deployment
Project Deployment Actions Updated
convex-auth-docs Ignored Ignored Oct 21, 2026 1:31am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 11 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/checkDocExamples.ts">

<violation number="1" location="scripts/checkDocExamples.ts:308">
P2: Diagnostics for the prelude and stubs are never collected. `getPreEmitDiagnostics(program, sourceFile)` only returns errors for that example file, so a broken `PRELUDE` type silently degrades to `any`. Also collect `getPreEmitDiagnostics` for `prelude.d.ts` and the stub files and report them as errors.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

return new Map(
examples.map((e) => [
e,
ts.getPreEmitDiagnostics(program, program.getSourceFile(e.path)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Diagnostics for the prelude and stubs are never collected. getPreEmitDiagnostics(program, sourceFile) only returns errors for that example file, so a broken PRELUDE type silently degrades to any. Also collect getPreEmitDiagnostics for prelude.d.ts and the stub files and report them as errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/checkDocExamples.ts, line 308:

<comment>Diagnostics for the prelude and stubs are never collected. `getPreEmitDiagnostics(program, sourceFile)` only returns errors for that example file, so a broken `PRELUDE` type silently degrades to `any`. Also collect `getPreEmitDiagnostics` for `prelude.d.ts` and the stub files and report them as errors.</comment>

<file context>
@@ -0,0 +1,360 @@
+  return new Map(
+    examples.map((e) => [
+      e,
+      ts.getPreEmitDiagnostics(program, program.getSourceFile(e.path)),
+    ]),
+  );
</file context>

@Nicolapps
Nicolapps marked this pull request as draft October 21, 2026 00:17
@Nicolapps
Nicolapps marked this pull request as ready for review October 21, 2026 00:25

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 11 files

Re-trigger cubic

@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 116b875 to 80bd8cc Compare October 21, 2026 00:27
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 80bd8cc to de4ff77 Compare October 21, 2026 00:34
@Nicolapps
Nicolapps force-pushed the nicolas/ssr-refresh-result-docs branch from 14153bb to b360f3e Compare October 21, 2026 00:34
@Nicolapps
Nicolapps changed the base branch from nicolas/ssr-refresh-result-docs to graphite-base/763 October 21, 2026 00:37
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from de4ff77 to 6a4301b Compare October 21, 2026 00:38
@cursor
cursor Bot changed the base branch from graphite-base/763 to reboot October 21, 2026 00:38
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 6a4301b to d656d8f Compare October 21, 2026 00:38
@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@convex-dev/auth@763

commit: c246f43

@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-ssr-auth-import branch from 293ee8d to 491a982 Compare October 21, 2026 00:58
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from f5f2ac6 to 85ae2f0 Compare October 21, 2026 00:59
@Nicolapps
Nicolapps changed the base branch from nicolas/doc-fix-ssr-auth-import to graphite-base/763 October 21, 2026 01:08
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 85ae2f0 to 8e7fe50 Compare October 21, 2026 01:08
@Nicolapps
Nicolapps changed the base branch from graphite-base/763 to nicolas/doc-fix-username-passkey October 21, 2026 01:08
@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-username-passkey branch from e6a21a6 to 0c503ed Compare October 21, 2026 01:14
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 8e7fe50 to 18427c0 Compare October 21, 2026 01:14
Nicolapps added a commit that referenced this pull request Oct 21, 2026
The `useCompleteSignUp` example used `emailCode` without declaring it. This puts the example in a component that takes the code as a prop, like the `useCompletePasswordRecovery` example.

Found by the doc example check in #763.
@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-username-passkey branch from 0c503ed to 82143a8 Compare October 21, 2026 01:17
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 18427c0 to d247a91 Compare October 21, 2026 01:17
Nicolapps added a commit that referenced this pull request Oct 21, 2026
The `setupEmailPassword` example imported `env` from `../../components/email/_generated/server`, a path inside this package. An app imports it from `./_generated/server`, like `examples/react-email-password` does.

It also renames the callback to `internal.users.createUserEmailPassword`, in line with the examples of the other methods (`createUserPassword`, `createUserGoogle`, …).

Found by the doc example check in #763.
@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-username-passkey branch from 82143a8 to 376dedf Compare October 21, 2026 01:21
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from d247a91 to 1442743 Compare October 21, 2026 01:21
Nicolapps added a commit that referenced this pull request Oct 21, 2026
The `setupGoogle`, `setupApple` and `setupGithub` examples passed `auth` without declaring it. They now start with `const auth = setupConvexAuth({ component: components.auth })` and export `signOut`, `refreshSession` and `isAuthenticated`, like the examples of the other methods.

Found by the doc example check in #763.
@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-username-passkey branch from 376dedf to 579d462 Compare October 21, 2026 01:25
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 1442743 to 6b5b73a Compare October 21, 2026 01:25
Nicolapps added a commit that referenced this pull request Oct 21, 2026
The sign-in route examples (`convexProxyHandler` in `ssr/signInProxy.ts` and `ssr/setup.ts`) used `auth.convexProxyHandler` without a declaration. They now import `auth` from `@/auth`, the Next.js module of the app that calls `setupConvexAuthServer`, with a comment that says so.

The main `setupConvexAuthServer` example now names that file (`// auth.ts`), so `@/auth` points to something on the page. The sign-in route, which used to be in the same code block without an import, is now its own block with the import.

Found by the doc example check in #763.
@Nicolapps
Nicolapps force-pushed the nicolas/doc-fix-username-passkey branch from 579d462 to 9766d3b Compare October 21, 2026 01:29
tsc does not read the code in a doc comment, thus the broken httpCookies
example fixed in #734 passed every check. Add `pnpm check:doc-examples`,
which typechecks each ts/tsx code block in the doc comments of
packages/core/src, and run it in CI.

The examples compile as modules of packages/doc-examples, a private Convex
app that installs every component and sets up every sign-in method, with
committed codegen. Thus api, internal, components, env and ctx have their
real generated types, and @/auth resolves to its SSR setup.

Fix the examples that the check finds: undeclared variables (the OAuth
examples now declare their own `auth`, the SSR examples import it from
@/auth), pseudo-code JSX, a top-level return, and a wrong import path for
`env`.
@Nicolapps
Nicolapps force-pushed the nicolas/check-doc-examples branch from 6b5b73a to c246f43 Compare October 21, 2026 01:30
@cursor
cursor Bot changed the base branch from nicolas/doc-fix-username-passkey to graphite-base/763 October 22, 2026 21:31

This branch was successfully deployed

1 active deployment
Preview – auth-v2 — c246f43f Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant