test: add regression tests for #8156 (secondaryStorage with auto-deserialized JSON)#8430
test: add regression tests for #8156 (secondaryStorage with auto-deserialized JSON)#8430
Conversation
…rialized JSON) Add tests covering the scenario where secondaryStorage (e.g. @vercel/kv) returns already-parsed objects instead of strings, causing expiresAt to be a string rather than a Date. The root cause was fixed in #8248 via reviveDates in safeJSONParse. These tests prevent regression.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for issue #8156 where secondaryStorage implementations that return already-parsed JSON objects (e.g. @vercel/kv) previously caused crashes during session refresh due to expiresAt being a string instead of a Date.
Changes:
- Add an adapter-level regression test ensuring
updateUser/updateUserByEmailrefresh sessions correctly when secondary storage returns parsed objects. - Add a route-level regression test verifying
authClient.updateUser()propagates changes and sessions remain valid under the same secondary storage behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/better-auth/src/db/internal-adapter.test.ts | Adds adapter-level regression test simulating KV-style auto-deserialization. |
| packages/better-auth/src/api/routes/update-user.test.ts | Adds end-to-end regression test validating update propagation + session validity with KV-style storage behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }, | ||
| } satisfies BetterAuthOptions; | ||
|
|
||
| (await getMigrations(testOpts)).runMigrations(); |
There was a problem hiding this comment.
runMigrations() is async (returns a Promise) but isn't awaited here. That can lead to a race where init(testOpts) runs before tables are created, causing intermittent failures. Await the runMigrations() call (or await (await getMigrations(testOpts)).runMigrations()).
| (await getMigrations(testOpts)).runMigrations(); | |
| await (await getMigrations(testOpts)).runMigrations(); |
Summary
Closes #8156
The root cause of this issue was already fixed in #8248 (
reviveDatesinsafeJSONParse), which correctly converts ISO 8601 date strings back toDateinstances when secondary storage (e.g.@vercel/kv) returns already-parsed objects instead of strings.This PR adds regression tests to prevent the issue from recurring:
internal-adapter.test.ts): Simulates@vercel/kvbehavior whereget()returns a parsed object. Verifies thatupdateUserandupdateUserByEmailcorrectly refresh sessions without crashing onexpiresAt.getTime().update-user.test.ts): End-to-end test via the auth client confirming thatupdateUserpropagates changes and sessions remain valid when secondary storage auto-deserializes JSON.Both tests verify the precondition (
typeof expiresAt === "string"in the store) before exercising the code path that previously crashed.Test plan
npx vitest packages/better-auth/src/db/internal-adapter.test.ts --run— 34 tests passnpx vitest packages/better-auth/src/api/routes/update-user.test.ts --run— 22 tests passbiome checkpasses on changed files