Skip to content

test: strengthen worklet runtime guardrails#2373

Merged
Yradex merged 10 commits intolynx-family:mainfrom
Yradex:wt/move-mts-runtime-2-20260319
Mar 26, 2026
Merged

test: strengthen worklet runtime guardrails#2373
Yradex merged 10 commits intolynx-family:mainfrom
Yradex:wt/move-mts-runtime-2-20260319

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented Mar 24, 2026

Summary by CodeRabbit

  • Tests
    • Expanded worklet compilation test coverage with new validation scenarios for distinct worklet ID generation and runtime behavior.
    • Added comprehensive bundler output test suite validating worklet-runtime injection and registration lifecycle.
    • Consolidated worklet testing infrastructure with centralized test configuration.

Summary

  • strengthen the worklet transform guardrails with targeted positive and negative assertions around runtime injection
  • add bundler guardrails for worklet-runtime emission, single runtime-body injection, and unique main-thread worklet registrations
  • expand runtime and testing-library guardrails for duplicate registration behavior and multiple main-thread worklets under background-thread mode

Testing

  • CI=true pnpm vitest run __test__/fixture.spec.js -t worklet
  • CI=true pnpm vitest run --project webpack/react test/worklet-runtime.test.ts test/cases.test.ts -t worklet-runtime
  • CI=true pnpm vitest run __test__/workletRuntime.test.js __test__/runOnMainThread.test.js __test__/runOnBackground.test.js
  • CI=true pnpm vitest run src/__tests__/worklet.test.jsx

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 24, 2026

⚠️ No Changeset found

Latest commit: cdf5f12

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

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

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b27850d4-7e57-47c1-8d85-60b8abf72f0b

📥 Commits

Reviewing files that changed from the base of the PR and between 421ce08 and cdf5f12.

📒 Files selected for processing (1)
  • packages/react/worklet-runtime/__test__/workletRuntime.test.js
✅ Files skipped from review due to trivial changes (1)
  • packages/react/worklet-runtime/test/workletRuntime.test.js

📝 Walkthrough

Walkthrough

Tests added across multiple packages to verify worklet compilation into distinct instances, worklet registration overwriting behavior, and bundler integration correctly including or excluding worklet-runtime based on usage patterns. Test logic migrated from scattered test case files to a centralized bundler guardrails test suite.

Changes

Cohort / File(s) Summary
Testing-library worklet tests
packages/react/testing-library/src/__tests__/worklet.test.jsx
Added test asserting multiple main-thread worklet handlers compile into distinct worklets with unique IDs and trigger only their respective callbacks.
Transform test suite
packages/react/transform/__test__/fixture.spec.js
Extended test assertions to verify runtime injection (loadWorkletRuntime, registerWorkletInternal) presence for LEPUS/MIXED targets and absence for JS target; added quantitative occurrence validation.
Worklet-runtime unit tests
packages/react/worklet-runtime/__test__/workletRuntime.test.js
Added test validating that registering the same worklet ID overwrites prior registration, ensuring only the latest handler executes.
Webpack plugin test case restructuring
packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/chunk/{a.jsx, index.js, test.config.cjs}, packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/not-using/{index.js, test.config.cjs}
Migrated test logic from test case modules to centralized suite; added onLongPressMT handler in fixture; cleared bundlePath expectations to delegate assertions elsewhere.
Webpack plugin bundler guardrails test
packages/webpack/react-webpack-plugin/test/worklet-runtime.test.ts
Added comprehensive test suite validating worklet-runtime bundler integration: extracts worklet IDs from bundles, verifies initialization signature occurrence counts, and validates presence/absence of worklet-runtime chunks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • hzy
  • gaoachao
  • upupming

Poem

🐰 Worklets dancing, each unique and bright,
IDs compiled in the main-thread light,
Registration overwrites the old with new,
Bundler checks pass—our tests ring true!
Hopping forward, robust and right! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: strengthen worklet runtime guardrails' directly and clearly describes the main objective of the pull request—adding and enhancing test guardrails for worklet runtime behavior across multiple test files and bundles.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@packages/react/worklet-runtime/src/workletRuntime.ts`:
- Around line 18-20: The initWorklet reset only clears the top-level
workletCache but doesn’t address nested child contexts that
transformWorkletInner in runWorklet rewrites by replacing nested _wkltId entries
with bound functions (leaving stale child worklets in reused ctxs via
_c/params). Fix by preserving or cloning the original nested worklet ctx
templates before any transformation and/or maintaining a registry mapping of
original ctx templates keyed by _wkltId so initWorklet can rebuild nested ctxs
from those templates; update initWorklet to iterate the registry and restore
nested ctxs (or clear transformed children) so entries referenced by _c and
params are re-resolved against the fresh registry rather than calling pre-init
bound functions (refer to initWorklet, workletCache, runWorklet,
transformWorkletInner, _wkltId, _c, params, and globalThis.lynxWorkletImpl).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c3e325e-cb45-405e-af36-58d46ff07cdf

📥 Commits

Reviewing files that changed from the base of the PR and between 518c310 and 421ce08.

📒 Files selected for processing (10)
  • packages/react/testing-library/src/__tests__/worklet.test.jsx
  • packages/react/transform/__test__/fixture.spec.js
  • packages/react/worklet-runtime/__test__/workletRuntime.test.js
  • packages/react/worklet-runtime/src/workletRuntime.ts
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/chunk/a.jsx
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/chunk/index.js
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/chunk/test.config.cjs
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/not-using/index.js
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/not-using/test.config.cjs
  • packages/webpack/react-webpack-plugin/test/worklet-runtime.test.ts

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 24, 2026

Merging this PR will improve performance by ×4.3

⚡ 1 improved benchmark
✅ 62 untouched benchmarks
⏩ 21 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
basic-performance-large-css 67.9 ms 15.8 ms ×4.3

Comparing Yradex:wt/move-mts-runtime-2-20260319 (cdf5f12) with main (fcda36a)

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Mar 24, 2026

Web Explorer

#8398 Bundle Size — 724.73KiB (0%).

cdf5f12(current) vs 36b38eb main#8397(baseline)

Bundle metrics  Change 1 change
                 Current
#8398
     Baseline
#8397
No change  Initial JS 41.99KiB 41.99KiB
No change  Initial CSS 1.99KiB 1.99KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 150(+0.67%) 149
No change  Duplicate Modules 11 11
No change  Duplicate Code 34.75% 34.75%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8398
     Baseline
#8397
No change  Other 382.38KiB 382.38KiB
No change  JS 340.36KiB 340.36KiB
No change  CSS 1.99KiB 1.99KiB

Bundle analysis reportBranch Yradex:wt/move-mts-runtime-2-202...Project dashboard


Generated by RelativeCIDocumentationReport issue

@Yradex Yradex marked this pull request as ready for review March 25, 2026 06:54
@Yradex Yradex merged commit d162bda into lynx-family:main Mar 26, 2026
70 of 72 checks passed
@Yradex Yradex deleted the wt/move-mts-runtime-2-20260319 branch March 26, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants