issue-141: Implement the mongo_count tool with unit tests #158
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!158
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-141/implement-the-mongo-count-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?
141: Implement the mongo_count tool with unit tests
Implements 141.
Generated in 5m 14s.
Review findings
The standalone script hit a Bun runtime limitation with
bson's node entry; let me verify how the actual test suite behaves and check the BSON error message via the test runner itself.Tests pass. Now let me inspect the actual BSON error message for the malformed-EJSON case:bun testworks but directbun -ehits a v8 snapshot limitation. Let me find the BSON error message from the installed source directly:The BSONObjectIdconstructor throws'Argument passed in does not match the accepted types'for a non-string$oid. Let me confirm the exact surfaced message via a temporary test:The malformed-EJSON case surfacesInvalid query: Argument passed in does not match the accepted types. I now have what I need to fix all three findings. Let me check the repo command conventions first:The mongodb extension has abun.lockpinning the installedbson7.3.2, so the error message is stable within the pinned dependency graph. Now let me apply the fixes:Now keep the mirrored test infind.test.tsin sync, per the finding's note:Now verify the changes and run the gates:All edits look correct. Now run the discovered gates:Gates pass. Now remove the temporary probe test and re-run, plus the root test gate:All gates pass (86 mongodb tests, tsc clean, 58 root tests). Let me confirm the final working-tree diff:All three findings are fixed and all gates pass. Final state:ObjectIdfrombsonand assertsexpect(filter._id).toBeInstanceOf(ObjectId); mirroredfind.test.ts:51updated in sync per the finding's note.Argument passed in does not match the accepted types, verified against installed bson 7.3.2 pinned viabun.lock). Note: the reviewer's examplestringContaining("$oid")does not match the actual message this version surfaces, so I used the real fragment.mongodbimport wrapped across lines.Gates re-run:
bun testinextensions/mongodb— 86 pass / 0 fail;bun run check(tsc --noEmit) — pass; rootnpm test— 58 pass / 0 fail.Review Findings — 141
Summary
All three Low findings resolved. The ObjectId assertion now uses the real BSON
ObjectIdtype (toBeInstanceOf(ObjectId)) instead of aconstructor.namestring check, with the mirroredfind.test.tstest updated in sync; the malformed-EJSON test now pins a fragment of the underlying BSON error (Argument passed in does not match the accepted types, confirmed against the pinned bson 7.3.2 viabun.lock) instead of only theInvalid query:prefix; and the over-lengthmongodbimport is wrapped for readability. Gates re-run and green:bun test(86 pass),bun run check/tsc --noEmit(pass), rootnpm test(58 pass). No acceptance criteria were provided on the issue; the tests satisfy the DESIGN.mdmongo_countcontract.Critical
(none)
High
(none)
Medium
(none)
Low
extensions/mongodb/src/tools/count.test.ts:67 — The ObjectId assertion
expect(filter._id.constructor.name).toBe("ObjectId")is a white-box/string check that would keep passing if a shaped plain object ever carried that constructor name, without proving the value is a real BSONObjectId. Suggested fix: importObjectIdfrom"bson"and assertObjectId.isValid(filter._id)(orexpect(filter._id).toBeInstanceOf(ObjectId)) for type-semantic coverage. Note this mirrors find.test.ts:51, so if kept, keep both in sync.extensions/mongodb/src/tools/count.test.ts:168 — The malformed-EJSON assertion only pins the prefix (
expect.stringContaining("Invalid query: ")), so it verifies the category routing but not that the actual BSON error surfaced. Suggested fix: if the pinnedbsonversion's message is stable, assert a fragment of the underlying error (e.g.stringContaining("$oid")); otherwise accept as intentional given cross-version message variability.extensions/mongodb/src/tools/count.test.ts:2 — The
mongodbimport line is 100 chars, the longest line in the file (no formatter is configured, and find.test.ts:19 already has a 104-char line, so this is optional). Suggested fix: wrap the import across two lines for readability if line-length tidiness is desired.