test: Add full unit coverage for MongoTransform#10560
Conversation
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.
|
🚀 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
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughMongoTransform refactors nested-value and update-operator handling and adds edge-case tests for coercion, constraints, BSON conversion, polygon handling, and pointer schema validation. ChangesMongoTransform behavior
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 inconclusive)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@dblythy Please let CR review first before requesting a human review, thanks. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai please provide a very thorough and careful review of the dead code removals - |
|
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/**' \
. || trueLength 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.jsLength 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^)" HEADLength of output: 9657
I specifically traced the formerly “unreachable” paths rather than accepting the coverage annotations at face value:
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. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/Adapters/Storage/Mongo/MongoTransform.js
… plain objects instead of binary data
Issue
src/Adapters/Storage/Mongo/MongoTransform.jssat 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 intransformWhereandparseObjectToMongoObjectForCreate,transformConstrainterror + geo/$maxDistancebranches,transformUpdateoperator validation, andmongoObjectToParseObjectatom/pointer/Polygon edge cases.istanbul ignorefor the genuinely unreachable code (11 lines, no runtime change).transformInteriorAtomnever returns theCannotTransformsentinel, so the array/__optail oftransformInteriorValueis dead - which in turn makestransformUpdateOperator'sflatten=truebranches unreachable (their only caller is that dead tail).isAllValuesRegexOrNone's empty guard is short-circuited by its only caller (isAnyValueRegex). These are marked withignore if/ignore nextand a reason, leaving the coveredelsebranches still tracked. Verified locally: MongoTransform.js reports 100% (639/639) in the full suite.Tasks
Summary by CodeRabbit
Byteshandling (including inside arrays), date coercion/built-in key handling, pointer class mismatch checks, and Long/Double/Binary conversions.