Skip to content

test: Add full unit coverage for MongoTransform#10560

Open
dblythy wants to merge 4 commits into
parse-community:alphafrom
dblythy:fix/coverage-mongotransform
Open

test: Add full unit coverage for MongoTransform#10560
dblythy wants to merge 4 commits into
parse-community:alphafrom
dblythy:fix/coverage-mongotransform

Conversation

@dblythy

@dblythy dblythy commented Jul 5, 2026

Copy link
Copy Markdown
Member

Issue

src/Adapters/Storage/Mongo/MongoTransform.js sat at 88.61% coverage (74 uncovered lines).

Approach

Brings it to 100%, split into two parts:

Real tests for the reachable code (63 lines) - added unit tests to spec/MongoTransform.spec.js, which already unit-tests the exported transform functions directly. Covers the previously-missed paths across every export: built-in key mapping (sessionToken/lastUsed/timesUsed), date-field coercion in transformWhere and parseObjectToMongoObjectForCreate, transformConstraint error + geo/$maxDistance branches, transformUpdate operator validation, and mongoObjectToParseObject atom/pointer/Polygon edge cases.

istanbul ignore for the genuinely unreachable code (11 lines, no runtime change). transformInteriorAtom never returns the CannotTransform sentinel, so the array/__op tail of transformInteriorValue is dead - which in turn makes transformUpdateOperator's flatten=true branches unreachable (their only caller is that dead tail). isAllValuesRegexOrNone's empty guard is short-circuited by its only caller (isAnyValueRegex). These are marked with ignore if/ignore next and a reason, leaving the covered else branches still tracked. Verified locally: MongoTransform.js reports 100% (639/639) in the full suite.

Tasks

  • Add tests

Summary by CodeRabbit

  • Tests
    • Expanded unit coverage for query/update value transformations, including nested Bytes handling (including inside arrays), date coercion/built-in key handling, pointer class mismatch checks, and Long/Double/Binary conversions.
    • Added edge-case tests for invalid atoms/operators, geo constraints validation, unsupported commands, and malformed query/update shapes.
  • Bug Fixes
    • Improved correctness and validation for update-operator handling, including delete/unset behavior, array fragment generation, and stricter constraint/atom rejection.
  • Maintenance
    • Refined transformation control flow to make recursion and update-operator behavior more predictable.

Bring src/Adapters/Storage/Mongo/MongoTransform.js from 88.61% to 100%.

Adds unit tests to spec/MongoTransform.spec.js exercising the previously
uncovered reachable paths across every exported function: built-in key
mapping, date-field coercion in transformWhere / parseObjectToMongoObjectForCreate,
transformConstraint error and geo/maxDistance branches, transformUpdate
operator validation, and mongoObjectToParseObject atom/pointer/Polygon edge
cases.

The remaining lines are genuinely unreachable and are marked with
/* istanbul ignore */ (code left unchanged): transformInteriorAtom never
returns the CannotTransform sentinel, so transformInteriorValue's array/op
tail is dead, which in turn makes transformUpdateOperator's flatten=true
branches unreachable; and isAllValuesRegexOrNone's empty guard is
short-circuited by its only caller.
@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec7a284a-8b9d-4dce-a5b6-e2305a79db66

📥 Commits

Reviewing files that changed from the base of the PR and between abdecb8 and 7aa6a92.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Mongo/MongoTransform.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Adapters/Storage/Mongo/MongoTransform.js

📝 Walkthrough

Walkthrough

MongoTransform refactors nested-value and update-operator handling and adds edge-case tests for coercion, constraints, BSON conversion, polygon handling, and pointer schema validation.

Changes

MongoTransform behavior

Layer / File(s) Summary
Transformation flow and update operators
src/Adapters/Storage/Mongo/MongoTransform.js
Simplifies nested-value recursion, removes flattened update-operator handling, updates regex-array inspection, and consistently returns Mongo update fragments with validation.
Nested value conversion coverage
spec/MongoTransform.spec.js
Verifies nested Parse Bytes values convert to Mongo binary values during create and update transformations.
Schema, constraint, and BSON edge cases
spec/MongoTransform.spec.js
Covers built-in keys, date and objectId coercion, constraint and update errors, BSON conversion, pointer filtering, polygon handling, and pointer target-class validation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: moumouls


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Engage In Review Feedback ❓ Inconclusive Repo shows follow-up commits, but no review thread/comments or response trace, so engagement with feedback can't be verified here. Provide the PR review thread or linked discussion showing the feedback comment, your reply, and the commit that addressed or resolved it.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required test: prefix and accurately summarizes the added MongoTransform unit test coverage.
Description check ✅ Passed The description follows the template with Issue, Approach, and Tasks sections and is detailed enough for review.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Security Check ✅ Passed Only a _bsontype fast-path was added; the real instanceof mongodb.Binary guard remains, so I see no new security-sensitive trust boundary.
✨ 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.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.60%. Comparing base (cce91e5) to head (7aa6a92).
⚠️ Report is 44 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10560      +/-   ##
==========================================
+ Coverage   92.66%   93.60%   +0.93%     
==========================================
  Files         193      192       -1     
  Lines       16981    16814     -167     
  Branches      248      248              
==========================================
+ Hits        15736    15738       +2     
+ Misses       1224     1051     -173     
- Partials       21       25       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dblythy
dblythy requested review from a team and Moumouls July 20, 2026 09:52
@mtrezza

mtrezza commented Jul 20, 2026

Copy link
Copy Markdown
Member

@dblythy Please let CR review first before requesting a human review, thanks.

@mtrezza
mtrezza removed the request for review from a team July 20, 2026 10:51
@dblythy

dblythy commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 20, 2026
@dblythy
dblythy requested a review from a team July 20, 2026 11:02
Comment thread src/Adapters/Storage/Mongo/MongoTransform.js Outdated

@mtrezza mtrezza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblythy

dblythy commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai please provide a very thorough and careful review of the dead code removals - mongoTransform is load bearing so we need to be very sure

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Changed MongoTransform hunks ==='
git diff --unified=80 HEAD^ HEAD -- src/Adapters/Storage/Mongo/MongoTransform.js

echo
echo '=== MongoTransform structural outline ==='
ast-grep outline src/Adapters/Storage/Mongo/MongoTransform.js --items all

echo
echo '=== Definitions and call sites for affected helpers ==='
rg -n -C 8 \
  '\b(isAllValuesRegexOrNone|transformInteriorValue|transformUpdateOperator)\s*\(' \
  --glob '*.js' \
  --glob '!node_modules/**' \
  .

echo
echo '=== Coverage / Istanbul configuration ==='
rg -n -C 5 'istanbul|coverage' \
  --glob 'package.json' \
  --glob 'jest.config.*' \
  --glob '.nycrc*' \
  --glob 'babel.config.*' \
  --glob '!node_modules/**' \
  . || true

Length of output: 27255


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Current transform implementations and exports ==='
sed -n '1,210p' src/Adapters/Storage/Mongo/MongoTransform.js
sed -n '430,610p' src/Adapters/Storage/Mongo/MongoTransform.js
sed -n '930,1125p' src/Adapters/Storage/Mongo/MongoTransform.js

echo
echo '=== Parent revision: removed behavior and its call sites ==='
git show HEAD^:src/Adapters/Storage/Mongo/MongoTransform.js | \
  rg -n -C 10 '\b(transformInteriorValue|transformInteriorAtom|transformUpdateOperator|module\.exports|exports\.)\b'

echo
echo '=== Current module imports / calls through exported MongoTransform API ==='
rg -n -C 6 \
  "(require\(['\"][^'\"]*MongoTransform|from ['\"][^'\"]*MongoTransform|\.transformUpdate\b|\.transformWhere\b|\.parseObjectToMongoObjectForCreate\b)" \
  --glob '*.js' \
  --glob '!node_modules/**' \
  .

echo
echo '=== MongoTransform tests exercising nested values or update operators ==='
rg -n -C 5 \
  '(transformInterior|transformUpdate|__op|AddUnique|SetOnInsert|Increment|Delete|Remove|nested)' \
  spec/MongoTransform.spec.js

Length of output: 60704


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Diff integrity ==='
git diff --check HEAD^ HEAD
git diff --stat HEAD^ HEAD

echo
echo '=== Exact changed test additions ==='
git diff --unified=12 HEAD^ HEAD -- spec/MongoTransform.spec.js

echo
echo '=== Numbered lines for reviewed production changes ==='
nl -ba src/Adapters/Storage/Mongo/MongoTransform.js | sed -n '110,205p'
nl -ba src/Adapters/Storage/Mongo/MongoTransform.js | sed -n '940,995p'

echo
echo '=== All source imports/requires of MongoTransform, including dynamic-style filename references ==='
rg -n -C 3 \
  '(MongoTransform|Adapters/Storage/Mongo/MongoTransform)' \
  --glob '*.{js,cjs,mjs,ts,json}' \
  --glob '!node_modules/**' \
  .

Length of output: 1292


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Numbered reviewed production regions ==='
awk 'NR >= 110 && NR <= 205 { printf "%6d  %s\n", NR, $0 }' \
  src/Adapters/Storage/Mongo/MongoTransform.js
awk 'NR >= 940 && NR <= 995 { printf "%6d  %s\n", NR, $0 }' \
  src/Adapters/Storage/Mongo/MongoTransform.js

echo
echo '=== All repository references to MongoTransform ==='
rg -n -C 3 \
  '(MongoTransform|Adapters/Storage/Mongo/MongoTransform)' \
  --glob '*.{js,cjs,mjs,ts,json}' \
  --glob '!node_modules/**' \
  .

echo
echo '=== Commit-level files changed on the PR branch ==='
git diff --name-status "$(git merge-base HEAD origin/master 2>/dev/null || git merge-base HEAD origin/main 2>/dev/null || git rev-parse HEAD^)" HEAD

Length of output: 9657


@dblythy Focused review complete: no blocking issue found in the dead-code removals.

I specifically traced the formerly “unreachable” paths rather than accepting the coverage annotations at face value:

  • isAllValuesRegexOrNone guard removal — safe. At Line 152, the function is called only after $all is validated as an array; isAnyValueRegex(values) must also be true. That guarantees a non-empty array, so the removed null/non-array/empty handling was unreachable.
  • transformInteriorValue fallback removal — safe. At Line 186, transformInteriorAtom() either returns a value (including unchanged plain arrays/objects) or throws. It never returns CannotTransform, so the old fallback paths—including the nested update-operator flattening path—could not execute.
  • transformUpdateOperator(..., flatten) removal — safe. The helper at Line 950 is private, is not exported, and has exactly one in-repository caller (Line 131). That caller never passed true; the flattened output modes therefore had no reachable caller.
  • Behavior preservation. The revised nested-value path still recursively transforms arrays and plain objects, preserves Date instances, and returns primitives/null unchanged—the same behavior reachable through the previous implementation.
  • Integration surface. The only production consumer of the exported MongoTransform API is MongoStorageAdapter; neither deleted helper mode is part of that public module surface.
  • Hygiene. The diff passes git diff --check.

I did not execute the test suite because this review sandbox does not permit running repository code, but the static control-flow and call-graph evidence supports the removals.

@dblythy

dblythy commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@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/Storage/Mongo/MongoTransform.js`:
- Around line 184-196: Update transformInteriorValue so recursion into arrays or
objects occurs only when transformInteriorAtom returned the original value,
using the identity check value !== restValue. Preserve direct returns for
transformed atoms, including nested Bytes converted to mongodb.Binary, as well
as the existing Date handling.
🪄 Autofix (Beta)

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

Plan: Pro

Run ID: 8be1e4fe-7879-4f54-b5d1-95f882613001

📥 Commits

Reviewing files that changed from the base of the PR and between 3fd373c and 90566fb.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Mongo/MongoTransform.js

Comment thread src/Adapters/Storage/Mongo/MongoTransform.js
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 21, 2026
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.

2 participants