Skip to content

test(node): add delete segments command unit tests - #4829

Open
armnkumar321-spec wants to merge 6 commits into
apache:masterfrom
armnkumar321-spec:test-4795-delete-segments
Open

armnkumar321-spec wants to merge 6 commits into
apache:masterfrom
armnkumar321-spec:test-4795-delete-segments

Conversation

@armnkumar321-spec

Copy link
Copy Markdown

Which issue does this PR address?

Closes #4795

Rationale

DELETE_SEGMENTS.serialize in 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 as create-user.command.test.ts). No production code changed.

  • Numeric stream/topic identifiers: compares the full payload against bytes written out by hand. topicId: 300 encodes as 2c 01 00 00, so the test also pins little-endian order.
  • String stream/topic identifiers: same check, with [2, length] followed by the name bytes.
  • Segments count 1 and 1000 are accepted, and the last four bytes hold the count.
  • Segments count 0 and 1001 throw. The tests only check that it throws, because the current message ("Topic partition_count must be between 1 and 1000") names the wrong field. Fixing that is a separate change.

The expected buffers are built with Buffer.concat from literal bytes and never call serializeIdentifier or uint32ToBuf. 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::validate accepts any u32. These tests lock in the SDK's 1..=1000 range as it is today.

Local Execution

In foreign/node on macOS, Node 24.22.2:

  • npm run test:unit: 971 tests passed, 0 failed. delete-segments.command.ts and segment.utils.ts now have 100% line, branch and function coverage.
  • npm run lint: passed.
  • npx tsc -p tsconfig.json --noEmit: passed.

Cover DELETE_SEGMENTS.serialize: exact bytes for numeric and string
stream/topic identifiers, and the 1..=1000 segment count bounds.
@github-actions

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

If AI assistance was used to create this PR, you are required to run the team-review skill before opening it.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.16%. Comparing base (ee7c918) to head (ef13758).
⚠️ Report is 15 commits behind head on master.

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           
Components Coverage Δ
Rust Core 93.50% <ø> (ø)
Java SDK 80.99% <ø> (ø)
C# SDK 86.43% <ø> (ø)
Python SDK 85.52% <ø> (ø)
PHP SDK 90.35% <ø> (ø)
Node SDK 97.35% <ø> (+0.09%) ⬆️
Go SDK 73.63% <ø> (ø)
C++ SDK 85.29% <ø> (ø)
see 2 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@justinmclean

Copy link
Copy Markdown
Member

Thanks @armnkumar321-spec, and welcome. You are right about the range. serializeSegmentsParams in the Node SDK rejects anything outside 1 to 1000, and its error message names partition_count, but the server's DeleteSegments::validate accepts any count. Could you open an issue for that, covering both the limit and the message? Keeping it out of this PR is fine.

@armnkumar321-spec

Copy link
Copy Markdown
Author

Thanks for the welcome! Opened #4850 for the segments-count range and the error message.

@justinmclean

Copy link
Copy Markdown
Member

@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.

@justinmclean

Copy link
Copy Markdown
Member

I ran the team-review skill on 20e5918, with the storage, perf, distsys and ecosystem reviewers.

Findings

  • [nit] foreign/node/src/wire/segment/delete-segments.command.test.ts:77 - The bound tests at lines 77 and 83 call assert.throws without a matcher, so any thrown error passes, not only the range check. Fix: pass a matcher for the expected error message. (raised: distsys; conf:M)

Pre-existing (does not block the merge)

  • foreign/node/src/wire/segment/segment.utils.ts:25 - Only the Node SDK rejects segmentsCount above 1000, and the new test at line 82 pins that limit. The server and the other SDKs accept any u32. fix(node): align delete segments count validation #4961 removes the limit, so whichever of the two merges second must change that test to expect 1001 to be accepted. (raised: ecosystem as warning, distsys as nit)
  • foreign/node/src/wire/segment/segment.utils.ts:26 - The error message names partition_count for segmentsCount. fix(node): align delete segments count validation #4961 fixes it. (raised: ecosystem)

Verdict: APPROVE

Reason: the test pins the wire layout that the server decoder expects.

Counts: critical 0, warning 0, nit 1, simplify 0
Verification: CI for 20e5918 passed (25 pass, 14 skipped). No local commands ran.

@spetz spetz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification: the numeric fixture concatenates four literal buffers. keep the same byte groups in one Buffer.from array.

@hubcio hubcio added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author PR is waiting on author response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node SDK: add unit tests for the delete segments command

4 participants