Skip to content

improve doc and tests - #6

Merged
gaissmai merged 2 commits into
mainfrom
devel
Jul 11, 2026
Merged

improve doc and tests#6
gaissmai merged 2 commits into
mainfrom
devel

Conversation

@gaissmai

@gaissmai gaissmai commented Jul 11, 2026

Copy link
Copy Markdown
Owner

@coderabbitai

Summary by CodeRabbit

  • Documentation

    • Added comprehensive documentation covering IP range concepts, supported APIs, algorithms, and repository structure.
    • Updated contribution guidelines for documentation language, identifier naming, formatting, and testing practices.
  • Examples

    • Expanded examples for parsing, prefix handling, merging, removal, comparison, and text/JSON serialization.
  • Tests

    • Improved binary and text serialization tests with broader round-trip, validation, and error coverage.
  • Refactor

    • Clarified API documentation and reorganized existing range-processing logic without changing behavior.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@gaissmai, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 58beb6aa-5540-4370-8891-a4f733ef48f4

📥 Commits

Reviewing files that changed from the base of the PR and between fe5a81e and ad78df8.

📒 Files selected for processing (4)
  • .greptile/codebase_summary.md
  • README.md
  • iprange.go
  • iprange_test.go

Walkthrough

The change adds package reference documentation and contribution rules, expands API comments, reformats existing range algorithms without changing their behavior, revises Go examples, and strengthens binary and text marshaling tests.

Changes

IPRange package refresh

Layer / File(s) Summary
Repository reference and contribution guidance
.greptile/codebase_summary.md, .greptile/rules.md
Documents package structure, API semantics, algorithms, English-only communication, formatting, and testing conventions.
API documentation and preserved range algorithms
iprange.go
Expands API and marshaling comments and restructures Merge and Remove branching while retaining existing behavior.
Examples and serialization validation
example_test.go, iprange_test.go
Adds and revises examples for constructors, range operations, comparison, and JSON marshaling; adds structured binary and text roundtrip and error tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

I’m a rabbit with ranges to trace,
Hopping through docs at a brisk pace.
CIDRs bloom, examples gleam,
Marshaled bytes flow like a stream.
Tests thump softly—clear and bright,
While IP bounds rest snugly tonight.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the changes, but it is too vague to describe the specific documentation and test updates. Rename it to reflect the main change, such as updating iprange documentation and example/binary/text tests.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves the package documentation and expands serialization coverage. The main changes are:

  • Added a codebase summary for the iprange package.
  • Expanded README usage examples and API descriptions.
  • Reworked Go examples for parsing, merging, removal, prefixes, comparison, and JSON serialization.
  • Clarified IPRange API comments and marshaling behavior.
  • Expanded binary and text marshal/unmarshal tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
iprange.go Clarified package, constructor, range operation, comparison, and marshaling documentation without changing implementation behavior.
iprange_test.go Expanded binary and text serialization tests with round trips, empty inputs, invalid inputs, nil receivers, and non-zero receiver cases.
example_test.go Expanded executable examples across the main parsing, conversion, range operation, comparison, and JSON serialization APIs.
README.md Reworked the README with clearer package overview, installation guidance, examples, and API summary.
.greptile/rules.md Expanded repository guidance for language, formatting, and test structure.
.greptile/codebase_summary.md Added a package overview covering structure, core APIs, serialization, and range algorithms.

Reviews (5): Last reviewed commit: "update README" | Re-trigger Greptile

Comment thread iprange.go Outdated
Comment on lines +286 to +287
// If text is empty, it clears the receiver to the zero IPRange.
// It returns an error if the receiver is nil or is not the zero value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Empty Text Clearing Contract

This comment says empty text clears the receiver, but UnmarshalText rejects non-zero receivers before the empty-text check and then returns without assigning anything. Callers reading the public docs can expect empty input to reset an existing value, while the changed contract documents behavior the method does not provide.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
iprange.go (2)

222-255: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Remove switch logic is correct and well-structured.

The reformatted switch (disjoint → covers → left-overlap → right-overlap) correctly handles all exclusion/range relationships. The post-switch guards for !r.first.IsValid() and r.last.Less(r.first) properly terminate on overflow or full consumption. Same note about panic("unreachable") as in Merge — consider a defensive fallback.

♻️ Optional: replace panic with defensive break
 		default:
-			panic("unreachable")
+			// Defensive fallback: should be unreachable given Merge invariants.
+			break
 		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iprange.go` around lines 222 - 255, In the remove-range switch, replace the
defensive panic in the default branch with a safe termination path, such as
breaking or returning the accumulated result, while preserving the existing
disjoint, covered, and overlap handling in the surrounding switch.

169-193: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Merge switch logic is correct and well-structured.

The reworked switch ordering (adjacency → disjoint → covers → partial overlap) correctly handles all cases. Adjacency is checked before disjoint because topic.last.Next() == r.first implies topic.last < r.first, which would also match isDisjunctLeft. Covers is checked before partial overlap to avoid extending when the current range is already a subset. The panic("unreachable") is genuinely unreachable given the sort invariant, but consider replacing it with a defensive fallback (e.g., append r) to avoid a production crash if the logic is ever modified.

♻️ Optional: replace panic with defensive append
 		default:
-			panic("unreachable")
+			// Defensive fallback: should be unreachable given sort invariants.
+			out = append(out, r)
 		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iprange.go` around lines 169 - 193, Replace the panic in the merge switch
within the range-merging logic with a defensive fallback that appends the
current range r to out. Preserve the existing adjacency, disjoint, covers, and
partial-overlap branches unchanged, using the out slice and current range
variables already in scope.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.greptile/codebase_summary.md:
- Around line 14-18: Update the file references in .greptile/codebase_summary.md
to use repository-relative paths instead of
file:///home/gaissmai/project/iprange/... URLs, preserving each linked filename
and description; use paths such as ../iprange.go, ../iprange_test.go,
../example_test.go, ../go.mod, ../go.sum, and rules.md as appropriate.

In `@iprange_test.go`:
- Around line 713-714: Correct the t.Errorf message in the UnmarshalText
empty-input test by removing the extra quote from the displayed []byte("")
expression, matching the formatting used by the nearby line.

In `@iprange.go`:
- Around line 330-333: Update the UnmarshalBinary documentation to state that it
also returns an error when the decoded last IP is less than the first IP,
matching the existing last.Less(first) validation.

---

Nitpick comments:
In `@iprange.go`:
- Around line 222-255: In the remove-range switch, replace the defensive panic
in the default branch with a safe termination path, such as breaking or
returning the accumulated result, while preserving the existing disjoint,
covered, and overlap handling in the surrounding switch.
- Around line 169-193: Replace the panic in the merge switch within the
range-merging logic with a defensive fallback that appends the current range r
to out. Preserve the existing adjacency, disjoint, covers, and partial-overlap
branches unchanged, using the out slice and current range variables already in
scope.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fd9a15bb-dab3-40fd-ad0f-f2d5e512ce42

📥 Commits

Reviewing files that changed from the base of the PR and between becdb8c and fe5a81e.

📒 Files selected for processing (5)
  • .greptile/codebase_summary.md
  • .greptile/rules.md
  • example_test.go
  • iprange.go
  • iprange_test.go

Comment thread .greptile/codebase_summary.md Outdated
Comment thread iprange_test.go Outdated
Comment thread iprange.go Outdated
Comment thread iprange.go
Comment on lines 288 to 308
@@ -309,7 +294,6 @@ func (r *IPRange) UnmarshalText(text []byte) error {
return errors.New("refusing to Unmarshal into non-zero IPRange")
}

// do nothing
if len(text) == 0 {
return nil
}
@@ -323,7 +307,9 @@ func (r *IPRange) UnmarshalText(text []byte) error {
return nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Empty text still errors The empty-text path still does not clear an existing value. When a caller has a populated IPRange and calls UnmarshalText(nil) or UnmarshalText([]byte("")), the non-zero receiver guard runs first, returns refusing to Unmarshal into non-zero IPRange, and leaves the old range in place. That contradicts the documented clearing behavior for the exact state callers need cleared.

Suggested change
func (r *IPRange) UnmarshalText(text []byte) error {
if r == nil {
return errors.New("UnmarshalText on nil receiver")
}
if len(text) == 0 {
*r = zeroValue
return nil
}
if *r != zeroValue {
return errors.New("refusing to Unmarshal into non-zero IPRange")
}
res, err := FromString(string(text))
if err != nil {
return err
}
*r = res
return nil
}

@gaissmai

Copy link
Copy Markdown
Owner Author

@greptileai review

@gaissmai
gaissmai merged commit 0936223 into main Jul 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant