Skip to content

fix(template): process-scope cloneWorkerDatabase memo for Jest setupFiles - #31

Merged
simoncrypta merged 3 commits into
mainfrom
08-09-fix_template_unique_cloneworkerdatabase_names_for_jest_setupfiles
Aug 10, 2026
Merged

fix(template): process-scope cloneWorkerDatabase memo for Jest setupFiles#31
simoncrypta merged 3 commits into
mainfrom
08-09-fix_template_unique_cloneworkerdatabase_names_for_jest_setupfiles

Conversation

@simoncrypta

@simoncrypta simoncrypta commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Store cloneWorkerDatabase process-once memo on globalThis (Symbol.for) so it survives Jest setupFiles module reloads.
  • Keep boring defaults (JEST_WORKER_ID / VITEST_POOL_ID / pid) — one clone per worker, not one per file.
  • Removes the unique-name / retain-default approach that papered over module-scoped memo amnesia.

Test plan

  • vp test tests/template-mode.test.ts (includes reload-survival case)
  • vp check
  • CI green on PR

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 42 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5e1cb726-8c8e-42da-9122-d0c72c333a84

📥 Commits

Reviewing files that changed from the base of the PR and between 2aced98 and 66ddde5.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/adapters/jest-template.ts
  • src/adapters/template-mode.ts
  • tests/template-mode.test.ts
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Clone databases now receive unique default names, preventing naming conflicts during repeated test setup and module reloads.
    • Existing behavior for explicitly named clones remains supported.
    • Clone operations continue to reuse the same generated name within a process where appropriate.
  • Documentation

    • Added guidance for configuring test database settings and choosing setup hooks.
    • Clarified clone naming, memoization, and per-call uniqueness behavior.

Walkthrough

Changes

Clone database naming

Layer / File(s) Summary
Default clone name generation
src/adapters/template-mode.ts, CHANGELOG.md
defaultCloneWorkerName combines the worker ID, process ID, and base-36 timestamp. Unnamed clones use this generated name.
Clone behavior validation and setup guidance
tests/template-mode.test.ts, src/adapters/jest-template.ts
Tests cover generated names, explicit names, memoization, and conflicting options. Jest comments describe setup-file reload behavior.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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 describes the Jest setupFiles memoization issue, which is related to the changes but does not identify the primary unique-name change.
Description check ✅ Passed The description discusses cloneWorkerDatabase, Jest setupFiles, memoization, and clone naming, so it is related to the changeset despite conflicting with the documented implementation summary.

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: 1

🤖 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 `@src/adapters/template-mode.ts`:
- Around line 81-93: Make unnamed clone names collision-resistant across module
reloads while generating one default name per module load for stable
memoization: update defaultCloneWorkerName/resolveWorkerName and clear the
retained name when cloning fails. Update tests/template-mode.test.ts:174-182 to
cover identical timestamps or a frozen clock, and
tests/template-mode.test.ts:211-238 to verify unnamed calls at different times
reuse the same memoized operation. Align the uniqueness and memoization
statements in src/adapters/template-mode.ts:68-75 and 99-106, CHANGELOG.md:5-7,
and src/adapters/jest-template.ts:23-28 with the corrected guarantee.
🪄 Autofix

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 491505d6-cfc1-4816-9ab4-3928eee966e8

📥 Commits

Reviewing files that changed from the base of the PR and between fd06aec and 2aced98.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/adapters/jest-template.ts
  • src/adapters/template-mode.ts
  • tests/template-mode.test.ts

Comment thread src/adapters/template-mode.ts Outdated
…ule load

Unnamed cloneWorkerDatabase calls regenerated Date.now() each time, so a second
call in a later ms threw instead of hitting process memo; entropy also avoids
same-ms collisions across Jest setupFiles reloads.
Module-scoped memo died under Jest setupFiles reloads, causing duplicate
clones on the same worker id. Store the memo on globalThis and keep boring
worker-id defaults instead of unique-per-reload names.
@simoncrypta simoncrypta changed the title fix(template): unique cloneWorkerDatabase names for Jest setupFiles fix(template): process-scope cloneWorkerDatabase memo for Jest setupFiles Aug 10, 2026
@simoncrypta
simoncrypta merged commit def3ddc into main Aug 10, 2026
2 checks passed
@simoncrypta
simoncrypta deleted the 08-09-fix_template_unique_cloneworkerdatabase_names_for_jest_setupfiles branch August 10, 2026 02:46
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