Repository navigation
test(frontend): replace JSON structuredClone polyfill with faithful one - #1241
Conversation
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis change replaces the JSON round-trip polyfill for ChangesstructuredClone polyfill replacement
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Test as deepClone test
participant Global as globalThis.structuredClone
participant Polyfill as structuredClonePolyfill
Test->>Global: structuredClone(value, options)
Global->>Global: check options.transfer
alt transfer provided
Global-->>Test: throw Error
else no transfer
Global->>Polyfill: structuredClonePolyfill(value)
Polyfill-->>Global: cloned value
Global-->>Test: cloned value
end
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
b03f7a5 to
1c8e712
Compare
|
@coderabbitai review |
Rate Limit Exceeded
|
Adversarial review of #1241 found two stale/misleading comments about the new structuredClone polyfill: - utils.test.ts said "via Node's MessageChannel serializer" -- left over from an earlier draft that used MessageChannel; the actual polyfill is @ungap/structured-clone. Update to name the real package. - setup.ts claimed the polyfill "must run inside the jsdom sandbox" so instanceof works. In practice @ungap delegates to Node's native structuredClone when present; instanceof works because jsdom-on-jest shares Date/Map/Set primordials with Node, not because of any sandbox effect. Describe the real mechanism instead. No behavior change.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Adversarial review of #1241 found two stale/misleading comments about the new structuredClone polyfill: - utils.test.ts said "via Node's MessageChannel serializer" -- left over from an earlier draft that used MessageChannel; the actual polyfill is @ungap/structured-clone. Update to name the real package. - setup.ts claimed the polyfill "must run inside the jsdom sandbox" so instanceof works. In practice @ungap delegates to Node's native structuredClone when present; instanceof works because jsdom-on-jest shares Date/Map/Set primordials with Node, not because of any sandbox effect. Describe the real mechanism instead. No behavior change.
|
Rebased onto origin/main (31 commits ahead). Conflicts resolved in
Gates passed:
New head: df9bd84 |
|
@coderabbitai review |
Rate Limit Exceeded
|
The Jest setup polyfilled structuredClone for jsdom with a JSON.parse(JSON.stringify(...)) round-trip, which drops undefined-valued properties, stringifies Dates, degrades Map/Set to plain objects, and throws on cycles. Deep-clone tests guarding the deep-copy-state invariant therefore validated weaker semantics than production browsers. Replace the JSON round-trip with @ungap/structured-clone, a faithful implementation of the HTML structured clone algorithm, applied only when the environment does not already provide a native structuredClone. The polyfill runs inside the jsdom sandbox so cloned objects keep sandbox-realm prototypes and instanceof assertions work (a Node-realm clone such as worker_threads MessageChannel round-trip would break them). Unsupported transfer lists now fail loud instead of being silently ignored. Add regression tests asserting real structured clone semantics (undefined preservation, Date/Map/Set fidelity, cyclic references, throw on functions); all five fail against the previous JSON polyfill and pass now. Also update the stale test comment that claimed undefined preservation could not be asserted under jsdom. Closes #1160
Adversarial review of #1241 found two stale/misleading comments about the new structuredClone polyfill: - utils.test.ts said "via Node's MessageChannel serializer" -- left over from an earlier draft that used MessageChannel; the actual polyfill is @ungap/structured-clone. Update to name the real package. - setup.ts claimed the polyfill "must run inside the jsdom sandbox" so instanceof works. In practice @ungap delegates to Node's native structuredClone when present; instanceof works because jsdom-on-jest shares Date/Map/Set primordials with Node, not because of any sandbox effect. Describe the real mechanism instead. No behavior change.
df9bd84 to
63f2515
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Merge-prep: rebased onto origin/main (27fdb06). Gates: |
|
✅ Action performedReview finished.
|
|
Merged on the substantive CI signal (all Lint/Unit/Integration/Security/Build/E2E/Validate-Terraform green; only the non-blocking tflint pre-commit flake red) closes #1160. |
Problem
TEST-07 (docs/reviews/codebase-review-2026-06-10.md): the Jest setup polyfilled
structuredClonefor jsdom withJSON.parse(JSON.stringify(val)), which dropsundefined-valued properties, stringifiesDates, degradesMap/Setto plain objects, and throws on cycles. Tests guarding the deep-copy-state invariant therefore passed against JSON semantics, not browser semantics, so clone tests could stay green while runtime types drifted in the browser.Fix
frontend/src/__tests__/setup.ts: keep the existing native-first guard (typeof globalThis.structuredClone === 'undefined'), but when polyfilling, delegate to@ungap/structured-clone, a faithful implementation of the HTML structured clone algorithm. It runs inside the jsdom sandbox, so cloned objects keep sandbox-realm prototypes andinstanceofassertions keep working (a Node-realm clone, e.g. aworker_threadsMessageChannel round-trip, deserializes with Node-realm prototypes and breaksinstanceof Date/Map). Unsupportedtransferlists now throw instead of being silently ignored.frontend/src/__tests__/ungap-structured-clone.d.ts: typed module declaration (the package ships no types).frontend/src/__tests__/utils.test.ts: newdeepClone (TEST-07)regression suite asserting real semantics:undefinedpreservation,Dateinstance fidelity,Map/Setfidelity, cyclic references, throw on functions. Also removes the stale comment claimingundefinedpreservation could not be asserted under jsdom.frontend/package.json/package-lock.json: add@ungap/structured-cloneas a devDependency (it was already in the tree as an eslint transitive dep).Test evidence
Tests: 5 failed, 86 skipped, 91 total).Test Suites: 77 passed, 77 total; Tests: 1 skipped, 2558 passed, 2559 total(the skip is pre-existing).npm run typecheckclean;npm run buildsucceeds.Closes #1160
Summary by CodeRabbit
Bug Fixes
undefinedvalues.Tests