Skip to content

test(clerk-js): Add tests for varying token TTL across refreshes#8100

Merged
nikosdouvlis merged 2 commits intomainfrom
nikos/test-varying-token-ttl
Mar 18, 2026
Merged

test(clerk-js): Add tests for varying token TTL across refreshes#8100
nikosdouvlis merged 2 commits intomainfrom
nikos/test-varying-token-ttl

Conversation

@nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Mar 17, 2026

With the upcoming work to allow emergency TTL overrides from clerk_go (see clerk/clerk_go#17599), we want to be confident that clerk-js handles consecutive tokens with different TTLs correctly.

The token cache already computes refresh timers dynamically from each token's own exp - iat, so varying TTL works out of the box. But there were no tests covering the chained scenario where Token A refreshes into Token B with a different TTL.

This adds 5 tests to tokenCache.test.ts:

  • 60s token replaced by 200s token: refresh timer correctly moves from 43s to 183s
  • 200s token replaced by 60s token: refresh timer correctly moves from 183s to 43s
  • Full chain (60s -> 200s -> 60s): each step schedules the right timer based on its own TTL
  • Old deletion timer doesn't interfere with replacement token (identity check in deleteKey)
  • Token remains readable through TTL transitions

Test plan

  • All 42 tokenCache tests pass (37 existing + 5 new)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests for token caching covering consecutive TTL transitions, refresh-timer adaptation, on-refresh behavior, lifecycle edge cases, async resolution, and multi-session/broadcast isolation.
  • Chores
    • Added a minimal changeset metadata file (non-functional) for release tracking.

…freshes

Verify that the token cache correctly adapts refresh timers when consecutive
tokens have different TTLs (e.g. 60s -> 200s -> 60s). Each token's refresh
timer is computed from its own exp-iat, not a fixed interval.
@vercel
Copy link

vercel bot commented Mar 17, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 17, 2026 5:52pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: 10358e4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8100

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8100

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8100

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8100

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8100

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8100

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8100

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8100

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8100

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8100

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8100

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8100

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8100

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8100

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8100

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8100

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8100

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8100

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8100

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8100

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8100

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8100

commit: 10358e4

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: e01a3311-a2b4-4f46-9d8e-ca5764a70f63

📥 Commits

Reviewing files that changed from the base of the PR and between 6038676 and 10358e4.

📒 Files selected for processing (1)
  • .changeset/gold-heads-float.md

📝 Walkthrough

Walkthrough

A new test suite was added to the tokenCache test file to validate timer behavior across consecutive tokens with varying TTLs. Tests cover TTL transitions (60s ↔ 200s and combinations), verify refresh-timer adaptation and onRefresh invocations, ensure replacements preserve or extend validity, and check that old deletion timers don’t remove longer-lived tokens. Additional scenarios validate token readability during transitions, async resolution lifecycles, broadcast behavior, and multi-session isolation. No production code was changed.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding tests for varying token TTL behavior across consecutive token refreshes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

@nikosdouvlis nikosdouvlis merged commit 1e36aec into main Mar 18, 2026
43 checks passed
@nikosdouvlis nikosdouvlis deleted the nikos/test-varying-token-ttl branch March 18, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants