issue-140: Implement the mongo_find tool with unit tests #157
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!157
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-140/implement-the-mongo-find-tool-with-unit-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
140: Implement the mongo_find tool with unit tests
Implements 140.
Generated in 5m 35s.
Review findings
Now let me verify the EJSON malformed-filter behavior that finding 1 targets, and check how the fake client is used elsewhere:The
bun -efailure was due to the bson v8 snapshot shim (only applied via bunfig preload underbun test). Let me verify the malformed-EJSON behavior through a temp test file run underbun test, then remove it:The probe confirmsEJSON.deserialize({ _id: { $oid: 123 } })throws aBSONError. Now let me remove the probe and check the sibling tools for consistency before fixing:Now I'll apply both fixes. First, the malformed-EJSON test infind.test.ts(finding 1), placed after the driver invalid-argument test:Now fix 2 — make the fake'sfinderror surface as an async rejection fromtoArray(), mirroring the real driver, and note it in the doc comment:Now re-run all detected gates:Extension gates pass (82 tests, +1 new; tsc clean). Now the repo root gate:All gates pass. Let me verify the final state of both files and confirm no temp files remain:Both findings are fixed, all gates are green, and only the two intended files are modified. Here is the annotated findings document.Review Findings — 140
Summary
Both Low-severity findings were resolved in a single pass. For the coverage gap, I added a tool-level test to
find.test.tsthat passes a malformed EJSON filter ({ _id: { $oid: 123 } }) tomongoFindTool.execute;EJSON.deserializethrows aBSONErrorbefore the driver is reached, and the test asserts aninvalid-query-categoryToolErrorplus thatcalls.findstayed empty (proving the failure came from the tool's own deserialization path, not the driver). For the sync-throw simplification, I changed the fake'sfindmock intestClient.tssofindErrorsurfaces as an async rejection from the cursor'stoArray()— mirroring the real driver, where query/server errors surface when the cursor is awaited — and added a doc comment explaining the design; a future refactor that movedtoArray()outside thetrywould now fail these tests.Gates re-run after the changes:
bun testinextensions/mongodb(82 pass / 0 fail, +1 new test),bun run check(tsc --noEmit, clean), and repo rootnpm test(58 pass / 0 fail). No lint tooling is configured anywhere in this repo (onlynode_moduleslint files exist), so there is no lint gate to run.Critical
High
Medium
Low
extensions/mongodb/src/tools/find.test.ts:126— Theinvalid-querycategory is only exercised via the driver'sMongoInvalidArgumentError. The other invalid-query path inside the tool — a bad EJSON filter throwingBSONErrorfromEJSON.deserializeatsrc/tools/find.ts:79(e.g.{ filter: { _id: { $oid: 123 } } }) — is covered only at theerrors.tsunit level, not through the tool. Suggested fix: add a test that passes a malformed EJSON filter totool.executeand asserts aninvalid-query-categoryToolError.extensions/mongodb/src/tools/testClient.ts:33— The fake'sfindmock throwsfindErrorsynchronously, so the new server/unexpected tests (and the pre-existing connection/auth tests) exercise a synchronous throw from.find(), whereas real server errors surface as async rejections fromawait cursor.toArray()(find.ts:89). Behavior under test is identical becausefind.tswraps both calls in the sametry, but the sync-throw simplification could mask a future refactor that movedtoArray()outside thetryblock. Suggested fix (optional): throw asynchronously (reject the promise returned bytoArray) for the server/unexpected overrides, or add a brief comment intestClient.tsnoting the deliberate sync-throw simplification.