fix(sdk): validate positive numeric round IDs (#256) - #345
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The functional changes align with the stated acceptance criteria, and the remaining feedback is limited to minor test naming and error-message clarity improvements.
Pull request overview
This PR tightens normalizeRoundId’s input validation so round IDs consistently follow a positive-integer contract across bigint and number inputs (matching the existing string behavior), aligning the SDK with issue #256’s requirements.
Changes:
- Rejects
bigintround IDs that are0nor negative. - Rejects
numberround IDs that are non-finite, fractional, unsafe, zero, or negative before converting tobigint. - Adds boundary-focused tests covering invalid numeric/bigint inputs and ensuring valid inputs remain unchanged.
File summaries
| File | Description |
|---|---|
| packages/sdk/src/ids.ts | Adds validation for bigint and strengthens number validation to positive safe integers before BigInt conversion. |
| packages/sdk/src/ids.test.ts | Adds boundary tests asserting rejection of invalid numeric/bigint inputs and preservation of valid ones. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+41
to
+45
| for (const value of [0, -0, -1, 1.5, NaN, Infinity, -Infinity, Number.MAX_SAFE_INTEGER + 1, 0n, -1n]) { | ||
| it(`rejects ${String(value)} (${typeof value})`, () => { | ||
| assert.throws(() => normalizeRoundId(value), /roundId must be a positive/); | ||
| }); | ||
| } |
Comment on lines
+16
to
18
| if (!Number.isSafeInteger(value) || value < 1) { | ||
| throw new Error(`roundId must be a positive safe integer, got ${JSON.stringify(value)}`); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #256.
Rejects zero/negative bigint IDs and unsafe, fractional or non-finite numeric IDs before conversion. Keeps arbitrary-precision positive bigint and string inputs intact.
Validation: SDK suite: 197 tests pass; SDK typecheck passes on the combined verification branch.