Skip to content

test(elysia): split tests by function and add basic coverage - #247

Merged
halvaradop merged 3 commits into
masterfrom
test/split-elysia-tests
Aug 2, 2026
Merged

test(elysia): split tests by function and add basic coverage#247
halvaradop merged 3 commits into
masterfrom
test/split-elysia-tests

Conversation

@halvaradop

@halvaradop halvaradop commented Aug 2, 2026

Copy link
Copy Markdown
Member

Description

This pull request reorganizes the test suite by splitting tests into dedicated files for each function and adding basic test coverage for the individual modules exposed by the @aura-stack/auth core package.

Previously, most Stateful session tests were contained in a single file that continued to grow as new features and test cases were added. This made the test suite increasingly difficult to navigate, understand, and maintain. To improve the testing structure, the tests have been reorganized into smaller, function-specific files.

In addition to the reorganization, this PR introduces basic coverage for the newly separated modules to ensure each function has an initial set of tests.

Key Changes

  • Split Stateful session tests into dedicated files by function.
  • Reorganized the test suite to improve readability and maintainability.
  • Added basic test coverage for individual authentication modules.
  • Improved the overall structure of the core package test suite.

Note

During this refactor, it became apparent that some modules do not yet have comprehensive edge case or complex scenario coverage. Addressing those cases is intentionally out of scope for this PR. The primary goal is to improve the organization of the test suite and establish a solid baseline of coverage. Additional test cases will be added in future pull requests.

@coderabbitai ignore

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
auth Skipped Skipped Aug 2, 2026 11:29pm

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@halvaradop, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ea325ac-6738-40e5-87c8-18a94babc409

📥 Commits

Reviewing files that changed from the base of the PR and between b2a719b and a402452.

📒 Files selected for processing (11)
  • package.json
  • packages/elysia/.env.example
  • packages/elysia/test/stateful/disconnectProvider.test.ts
  • packages/elysia/test/stateful/getProviderTokens.test.ts
  • packages/elysia/test/stateful/getSession.test.ts
  • packages/elysia/test/stateful/isProviderConnected.test.ts
  • packages/elysia/test/stateful/signIn.test.ts
  • packages/elysia/test/stateful/signOut.test.ts
  • packages/elysia/test/stateful/updateSession.test.ts
  • packages/elysia/test/utils.ts
  • packages/elysia/vitest.config.ts
📝 Walkthrough

Walkthrough

The PR reorganizes Elysia test execution into Stateful and stateless Vitest projects, adds Stateful coverage for authentication and provider operations, updates test fixtures, and reformats the generated TanStack route tree without changing routing behavior.

Changes

Stateful authentication tests

Layer / File(s) Summary
Stateful test execution and fixtures
packages/elysia/package.json, packages/elysia/vitest.config.ts, packages/elysia/test/stateful/setup.ts, packages/elysia/test/utils.ts, packages/elysia/test/stateful/app.ts
Vitest now separates Stateful and stateless projects. Test cleanup, session-token parsing, and a revocation-enabled GitHub provider were added.
OAuth, credential, and sign-up flows
packages/elysia/test/stateful/signIn.test.ts, packages/elysia/test/stateful/signInCredentials.test.ts, packages/elysia/test/stateful/signUp.test.ts
Stateful tests cover OAuth redirects and callbacks, credential sign-in, CSRF failures, validation, session creation, and duplicate-user prevention.
Session lifecycle operations
packages/elysia/test/stateful/getSession.test.ts, packages/elysia/test/stateful/signOut.test.ts, packages/elysia/test/stateful/updateSession.test.ts
Stateful tests cover session retrieval, expiration, revocation, deleted users, concurrent sessions, sign-out, updates, and CSRF handling.
Provider connection and token operations
packages/elysia/test/stateful/isProviderConnected.test.ts, packages/elysia/test/stateful/getProviderTokens.test.ts, packages/elysia/test/stateful/revokeToken.test.ts, packages/elysia/test/stateful/disconnectProvider.test.ts, packages/elysia/test/stateful/refreshUserInfo.test.ts
Stateful tests cover provider connection status, token retrieval and revocation, provider disconnection, and user-information refresh authentication paths.

Generated route tree formatting

Layer / File(s) Summary
Route tree formatting
apps/tanstack-start/src/routeTree.gen.ts
The generated route tree keeps its route mappings, type registrations, child registration, and React Start registration while changing formatting and declaration layout.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the Elysia test split and the addition of basic coverage.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/split-elysia-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🧹 Nitpick comments (8)
packages/elysia/test/stateful/getProviderTokens.test.ts (1)

6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Both titles state 404 while the assertions require 401.

Correct the titles to match the asserted status.

♻️ Proposed fix
-    test("returns 404 when no session cookie is present", async () => {
+    test("returns 401 when no session cookie is present", async () => {
-    test("returns 404 when session cookie is invalid", async () => {
+    test("returns 401 when session cookie is invalid", async () => {

Also applies to: 11-11

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/getProviderTokens.test.ts` at line 6, Update
the test titles in the relevant test cases, including the one beginning “returns
404 when no session cookie is present,” to state 401 instead of 404, matching
their existing assertions.
packages/elysia/test/utils.ts (1)

3-10: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Guard against a missing session cookie instead of using a non-null assertion.

If the response contains no aura-auth.session_token cookie, cookie is undefined. parseSetCookie(cookie!) then throws an opaque error inside the parser. A guard produces a clear assertion failure in the calling test.

♻️ Proposed fix
 export const getSessionToken = (response: Response) => {
     const cookie = response.headers.getSetCookie()?.find((cookie) => cookie.startsWith("aura-auth.session_token="))
-    const parsed = parseSetCookie(cookie!)
+    if (!cookie) {
+        return { cookie: undefined, tokenValue: undefined }
+    }
+    const parsed = parseSetCookie(cookie)
     return {
         cookie,
         tokenValue: parsed?.value,
     }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/utils.ts` around lines 3 - 10, Update getSessionToken to
explicitly assert that the aura-auth.session_token cookie was found before
calling parseSetCookie, replacing the non-null assertion with a clear failure
for missing cookies while preserving the existing parsed token return.
packages/elysia/test/stateful/signIn.test.ts (2)

74-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse getSessionToken from @test/utils.

These four lines re-implement the helper added in packages/elysia/test/utils.ts. Import the helper and remove the duplicated cookie lookup and parsing.

♻️ Proposed fix
+import { getSessionToken } from "`@test/utils`"
-        const sessionToken = request.headers.getSetCookie()?.find((cookie) => cookie.startsWith("aura-auth.session_token="))
-        expect(sessionToken).toBeDefined()
+        const { cookie: sessionToken, tokenValue } = getSessionToken(request)
+        expect(sessionToken).toBeDefined()
-        const parsed = parseSetCookie(sessionToken!)
         const session = await app.handle(
             new Request("http://localhost:3000/api/auth/session", {
-                headers: { Cookie: `aura-auth.session_token=${parsed.value}` },
+                headers: { Cookie: `aura-auth.session_token=${tokenValue}` },
             })
         )

Also applies to: 103-103, 238-238, 241-241

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/signIn.test.ts` at line 74, Update the sign-in
tests to import and reuse getSessionToken from `@test/utils`, replacing the
duplicated session-token cookie lookup and parsing at each affected location.
Remove the local implementations while preserving the existing assertions and
test behavior.

96-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Do not hardcode the library version in the User-Agent assertion.

Aura Auth/0.8.1 breaks on every version bump of the core package. Read the version from the package manifest or match with a regular expression.

♻️ Proposed fix
-                "User-Agent": `Aura Auth/0.8.1`,
+                "User-Agent": expect.stringMatching(/^Aura Auth\/\d+\.\d+\.\d+/),

Also applies to: 231-231

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/signIn.test.ts` at line 96, Update the
User-Agent assertions in the sign-in tests to derive the Aura Auth version from
the package manifest or match the version portion with a regular expression,
instead of hardcoding “0.8.1”.
packages/elysia/test/stateful/signOut.test.ts (1)

7-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Align the test title with the asserted status.

The title states "returns 401 or clears session". The assertion requires 403. Name the expected behavior exactly.

♻️ Proposed fix
-    test("returns 401 or clears session when no active session cookie is present", async () => {
+    test("returns 403 when no active session cookie is present", async () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/signOut.test.ts` around lines 7 - 13, Update
the test title in the sign-out test to state that it returns 403 when no active
session cookie is present, matching the existing response.status assertion and
removing the inaccurate 401 or session-clearing wording.
packages/elysia/test/stateful/getSession.test.ts (1)

170-170: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename this duplicate test title.

Line 97 already declares "returns 401 for revoked session". This test verifies soft revocation with deleteStrategy: soft. A distinct title makes failures identifiable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/getSession.test.ts` at line 170, Rename the
test at the duplicate title near the soft-revocation case to clearly identify
that it covers revoked sessions with deleteStrategy: soft, while leaving the
existing test title near line 97 unchanged.
packages/elysia/vitest.config.ts (1)

49-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Skipping the stateful project in CI removes all new coverage from CI.

The new stateful suites never run in CI. Regressions in OAuth, session, and provider flows will not be detected by the pipeline. If the suites need a database, gate them on a service container or a dedicated CI job instead of disabling them.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/vitest.config.ts` around lines 49 - 60, Update the Vitest
project configuration around statefulProject so the stateful test suites run in
CI instead of being skipped. Keep their database-dependent requirements explicit
by wiring them to an available service container or dedicated CI job, while
preserving the existing stateless project configuration and coverage for OAuth,
session, and provider flows.
packages/elysia/test/stateful/isProviderConnected.test.ts (1)

15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Two tests share the title "returns false when provider is not connected".

The test at line 15 covers a user with no account. The test at line 50 covers a user with a credentials-only account. Distinct titles make failures identifiable.

♻️ Proposed fix
-    test("returns false when provider is not connected", async () => {
+    test("returns false when the user has only a credentials account", async () => {
         const user = await adapter.createUser({
             name: "John Doe",
             email: "john.doe@example.com",
         })

Also applies to: 50-50

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/elysia/test/stateful/isProviderConnected.test.ts` at line 15, Rename
the duplicate test titles in isProviderConnected.test.ts so the no-account case
and credentials-only-account case have distinct, descriptive names; preserve
each test’s existing behavior and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/elysia/test/stateful/disconnectProvider.test.ts`:
- Around line 38-69: Update the session setup in the “fails when provider is not
connected” test to store the hash of the session token via the existing
createHash helper, while keeping the raw token value in the request cookie.
Ensure session lookup succeeds so the test reaches and verifies the
provider-not-connected response path.

In `@packages/elysia/test/stateful/getSession.test.ts`:
- Around line 70-88: Fix the session fixtures to follow the endpoint token
contract: in packages/elysia/test/stateful/getSession.test.ts lines 70-88 and
102-120, and packages/elysia/test/stateful/signOut.test.ts lines 72-101, store
the single hash of each raw cookie token as tokenHash; in
packages/elysia/test/stateful/getProviderTokens.test.ts lines 22-55, hash the
raw token once for storage and send the unhashed token in the cookie so each
test exercises its intended session path.
- Line 198: Update the session status assertion in the test to use Vitest’s
toHaveProperty matcher with status set to "REVOKED" instead of haveOwnProperty.
Handle a possible null result from prismaClient.session.findUnique before
applying the property assertion.

In `@packages/elysia/test/stateful/updateSession.test.ts`:
- Line 6: Rename the affected test titles in updateSession.test.ts, including
the tests around the no-session-cookie and related cases, from “returns 404” to
“returns 400” so each title matches its asserted status code.

In `@packages/elysia/vitest.config.ts`:
- Around line 13-29: Update the statefulProject selection in vitest.config.ts so
the CI === "true" branch omits the project configuration rather than returning
an empty object, and adjust the projects array construction to exclude that
entry in CI while retaining the configured stateful project locally.

---

Nitpick comments:
In `@packages/elysia/test/stateful/getProviderTokens.test.ts`:
- Line 6: Update the test titles in the relevant test cases, including the one
beginning “returns 404 when no session cookie is present,” to state 401 instead
of 404, matching their existing assertions.

In `@packages/elysia/test/stateful/getSession.test.ts`:
- Line 170: Rename the test at the duplicate title near the soft-revocation case
to clearly identify that it covers revoked sessions with deleteStrategy: soft,
while leaving the existing test title near line 97 unchanged.

In `@packages/elysia/test/stateful/isProviderConnected.test.ts`:
- Line 15: Rename the duplicate test titles in isProviderConnected.test.ts so
the no-account case and credentials-only-account case have distinct, descriptive
names; preserve each test’s existing behavior and assertions.

In `@packages/elysia/test/stateful/signIn.test.ts`:
- Line 74: Update the sign-in tests to import and reuse getSessionToken from
`@test/utils`, replacing the duplicated session-token cookie lookup and parsing at
each affected location. Remove the local implementations while preserving the
existing assertions and test behavior.
- Line 96: Update the User-Agent assertions in the sign-in tests to derive the
Aura Auth version from the package manifest or match the version portion with a
regular expression, instead of hardcoding “0.8.1”.

In `@packages/elysia/test/stateful/signOut.test.ts`:
- Around line 7-13: Update the test title in the sign-out test to state that it
returns 403 when no active session cookie is present, matching the existing
response.status assertion and removing the inaccurate 401 or session-clearing
wording.

In `@packages/elysia/test/utils.ts`:
- Around line 3-10: Update getSessionToken to explicitly assert that the
aura-auth.session_token cookie was found before calling parseSetCookie,
replacing the non-null assertion with a clear failure for missing cookies while
preserving the existing parsed token return.

In `@packages/elysia/vitest.config.ts`:
- Around line 49-60: Update the Vitest project configuration around
statefulProject so the stateful test suites run in CI instead of being skipped.
Keep their database-dependent requirements explicit by wiring them to an
available service container or dedicated CI job, while preserving the existing
stateless project configuration and coverage for OAuth, session, and provider
flows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f87ccd97-8e01-4f05-8864-25011aa64b8d

📥 Commits

Reviewing files that changed from the base of the PR and between e247ed2 and b2a719b.

📒 Files selected for processing (18)
  • apps/tanstack-start/src/routeTree.gen.ts
  • packages/elysia/package.json
  • packages/elysia/test/stateful/app.ts
  • packages/elysia/test/stateful/disconnectProvider.test.ts
  • packages/elysia/test/stateful/getProviderTokens.test.ts
  • packages/elysia/test/stateful/getSession.test.ts
  • packages/elysia/test/stateful/index.test.ts
  • packages/elysia/test/stateful/isProviderConnected.test.ts
  • packages/elysia/test/stateful/refreshUserInfo.test.ts
  • packages/elysia/test/stateful/revokeToken.test.ts
  • packages/elysia/test/stateful/setup.ts
  • packages/elysia/test/stateful/signIn.test.ts
  • packages/elysia/test/stateful/signInCredentials.test.ts
  • packages/elysia/test/stateful/signOut.test.ts
  • packages/elysia/test/stateful/signUp.test.ts
  • packages/elysia/test/stateful/updateSession.test.ts
  • packages/elysia/test/utils.ts
  • packages/elysia/vitest.config.ts
💤 Files with no reviewable changes (1)
  • packages/elysia/test/stateful/index.test.ts

Comment thread packages/elysia/test/stateful/disconnectProvider.test.ts
Comment thread packages/elysia/test/stateful/getSession.test.ts
Comment thread packages/elysia/test/stateful/getSession.test.ts Outdated
Comment thread packages/elysia/test/stateful/updateSession.test.ts Outdated
Comment thread packages/elysia/vitest.config.ts Outdated
@halvaradop
halvaradop merged commit fda9604 into master Aug 2, 2026
7 checks passed
@halvaradop
halvaradop deleted the test/split-elysia-tests branch August 2, 2026 23:33
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