Implement src/defaults.ts with unit tests (FIND_LIMIT, OUTPUT_BYTE_CAP) #137
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#137
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Summary
Implement
extensions/mongodb/src/defaults.ts— the shared constants (FIND_LIMIT,OUTPUT_BYTE_CAP) and theapplyDefaultAndCaphelper used bymongo_find's limit handling — with unit tests.Background
Depends on: #133
These numbers bound how much data the tools return, protecting the LLM's context window from unbounded results. They are deliberately conservative working defaults (tunable constants), not the result of load testing.
mongo_find(a later step) appliesFIND_LIMITto itslimitparameter;src/serialize.ts(the sibling step in this milestone) usesOUTPUT_BYTE_CAPfor its byte cap. No external packages are used by this module — pure logic.Implementation Details
Rules, applied uniformly:
undefined→default(100).max(1000) → clamped tomax— not rejected (keeps the call ergonomic while bounding result size).0is an explicit value — must return0, NOT fall through to the default. Guard against??-vs-falsy bugs: usevalue === undefinedchecks, never truthiness.Write co-located tests in
src/defaults.test.ts(bun test) covering each rule, including the0case.Acceptance Criteria
undefinedlimit → returns the default (100).limitabovemax→ clamped tomax(1000).limitwithin range → unchanged.limit: 0→ returns0(explicit value, not the default).bun testinextensions/mongodb/is green forsrc/defaults.ts.Test Plan
Closing — all acceptance criteria verified:
extensions/mongodb/src/defaults.tscommitted (commit9bd85ee) withFIND_LIMIT = { default: 100, max: 1000 },OUTPUT_BYTE_CAP = 100_000, andapplyDefaultAndCap().undefined→ default (viavalue === undefinedcheck, not truthiness), above max → clamped to max, within range → unchanged, explicit0→ returns0. Bonus: negative/NaN fall back to the default.src/defaults.test.tscover every rule including the0case —bun test src/defaults.test.ts: 9 pass, 0 fail.