Repository navigation
test(node): add delete segments command unit tests - #4829
armnkumar321-spec wants to merge 6 commits into
Conversation
Cover DELETE_SEGMENTS.serialize: exact bytes for numeric and string stream/topic identifiers, and the 1..=1000 segment count bounds.
|
Thanks for the PR. It is labeled If AI assistance was used to create this PR, you are required to run the Slash commands (own line, regular comment) move it around the queue:
See CONTRIBUTING.md for details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4829 +/- ##
=========================================
Coverage 92.15% 92.16%
Complexity 4355 4355
=========================================
Files 1574 1574
Lines 417626 417626
Branches 346178 346179 +1
=========================================
+ Hits 384880 384900 +20
+ Misses 27270 27250 -20
Partials 5476 5476
🚀 New features to boost your workflow:
|
|
Thanks @armnkumar321-spec, and welcome. You are right about the range. |
|
Thanks for the welcome! Opened #4850 for the segments-count range and the error message. |
|
@armnkumar321-spec #4961 fixes #4850 by removing the 1000 limit, so the 'throws on segments count > 1000' test here will fail once it merges. Please change it to expect 1001 to be accepted. |
|
I ran the Findings
Pre-existing (does not block the merge)
Verdict: APPROVEReason: the test pins the wire layout that the server decoder expects. Counts: critical 0, warning 0, nit 1, simplify 0 |
spetz
left a comment
There was a problem hiding this comment.
I checked the numeric and string identifier layouts and the order of the partition ID and segment count. I found no additional issue beyond the existing review.
| it('throws on segments count < 1', () => { | ||
| assert.throws( | ||
| () => DELETE_SEGMENTS.serialize({ ...params, segmentsCount: 0 }), | ||
| { message: 'Topic partition_count must be between 1 and 1000' } |
There was a problem hiding this comment.
warning: both count tests require the incorrect partition_count message, so a wording fix would fail both. assert only that each invalid count throws, as requested in #4795.
| segmentsCount: 5 | ||
| }); | ||
|
|
||
| const expected = Buffer.concat([ |
There was a problem hiding this comment.
simplification: the numeric fixture concatenates four literal buffers. keep the same byte groups in one Buffer.from array.
Which issue does this PR address?
Closes #4795
Rationale
DELETE_SEGMENTS.serializein the Node SDK had no unit test, so a change to the payload layout or to the segments count bounds would go unnoticed.What changed?
Adds
foreign/node/src/wire/segment/delete-segments.command.test.ts(node:test+node:assert/strict, same layout ascreate-user.command.test.ts). No production code changed.topicId: 300encodes as2c 01 00 00, so the test also pins little-endian order.[2, length]followed by the name bytes.The expected buffers are built with
Buffer.concatfrom literal bytes and never callserializeIdentifieroruint32ToBuf. I made sure the tests fail if the partition id and segments count are swapped or the upper bound changes.One thing to confirm, outside this PR: the SDK rejects counts above 1000, but the server's
DeleteSegments::validateaccepts anyu32. These tests lock in the SDK's 1..=1000 range as it is today.Local Execution
In
foreign/nodeon macOS, Node 24.22.2:npm run test:unit: 971 tests passed, 0 failed.delete-segments.command.tsandsegment.utils.tsnow have 100% line, branch and function coverage.npm run lint: passed.npx tsc -p tsconfig.json --noEmit: passed.