Skip to content

test(server): cover ipUtils IP matching helpers - #1049

Open
mariazuheros wants to merge 2 commits into
rybbit-io:masterfrom
mariazuheros:test/ip-utils
Open

test(server): cover ipUtils IP matching helpers#1049
mariazuheros wants to merge 2 commits into
rybbit-io:masterfrom
mariazuheros:test/ip-utils

Conversation

@mariazuheros

@mariazuheros mariazuheros commented Jul 14, 2026

Copy link
Copy Markdown

Adds unit tests for the IP-matching helpers in server/src/lib/ipUtils.ts, which had no direct coverage.

Covered:

  • validateIPPattern — empty/whitespace patterns, single IPv4/IPv6, CIDR (both families), IPv4 ranges, and the error paths (malformed address, unsupported IPv6 range, missing range endpoint).
  • matchesCIDR — address inside/outside an IPv4 and IPv6 subnet, mismatched families returning false, and unparseable input.
  • matchesRange — address inside an IPv4 range, inclusive lower/upper bounds, out-of-range addresses, unsupported IPv6 ranges, and unparseable input.

The logger (pino-pretty transport) is stubbed so the tests stay deterministic. Run with cd server && npx vitest run src/lib/ipUtils.test.ts — 17 tests pass.

Summary by CodeRabbit

  • Tests
    • Added automated test coverage for IP address pattern validation, CIDR matching, and range matching.
    • Verifies behavior across IPv4 and IPv6 inputs, including malformed patterns, whitespace/empty handling, CIDR include/exclude cases, and inclusive IPv4 dash-range matching.
    • Confirms unsupported IPv6 range syntax and unparseable inputs correctly return failure.

Add unit tests for validateIPPattern, matchesCIDR and matchesRange:
IPv4/IPv6 single addresses, CIDR membership across families, inclusive
IPv4 range bounds, unsupported IPv6 ranges, and malformed input.
@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

@mariazuheros is attempting to deploy a commit to the goldflag's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68d22aed-6e10-4800-9904-b4fd0ab5e24f

📥 Commits

Reviewing files that changed from the base of the PR and between f54a3a5 and e977582.

📒 Files selected for processing (1)
  • server/src/lib/ipUtils.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/src/lib/ipUtils.test.ts

📝 Walkthrough

Walkthrough

Adds Vitest coverage for validateIPPattern, matchesCIDR, and matchesRange, including IPv4/IPv6 inputs, invalid patterns, family mismatches, unsupported IPv6 ranges, and mocked logger functions.

Changes

IP utility test coverage

Layer / File(s) Summary
IP utility behavior coverage
server/src/lib/ipUtils.test.ts
Tests valid and invalid IP patterns, IPv4/IPv6 CIDR matching, inclusive IPv4 ranges, unsupported IPv6 ranges, unparseable inputs, and mocked logger methods.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the new server test coverage for ipUtils IP matching helpers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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

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.

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

🧹 Nitpick comments (1)
server/src/lib/ipUtils.test.ts (1)

1-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Group imports together at the top of the file.

As per coding guidelines, group imports by external dependencies first, then internal modules. You can safely group the internal import with the external import at the top; Vitest automatically hoists vi.mock calls above all imports during execution.

♻️ Proposed refactor
 import { describe, expect, it, vi } from "vitest";
+import { matchesCIDR, matchesRange, validateIPPattern } from "./ipUtils.js";
 
 // The logger uses a pino-pretty transport (a worker thread); stub it so these
 // pure-logic tests stay deterministic and quiet.
 vi.mock("./logger/logger.js", () => ({
   logger: { warn: vi.fn(), info: vi.fn(), error: vi.fn(), debug: vi.fn() },
 }));
-
-import { matchesCIDR, matchesRange, validateIPPattern } from "./ipUtils.js";
🤖 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 `@server/src/lib/ipUtils.test.ts` around lines 1 - 9, Reorder the imports in
the test file so the external Vitest import and internal ipUtils import are
grouped together at the top, before the vi.mock declaration. Keep the logger
mock unchanged; Vitest hoisting preserves its behavior.

Source: Coding guidelines

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

Nitpick comments:
In `@server/src/lib/ipUtils.test.ts`:
- Around line 1-9: Reorder the imports in the test file so the external Vitest
import and internal ipUtils import are grouped together at the top, before the
vi.mock declaration. Keep the logger mock unchanged; Vitest hoisting preserves
its behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7bc6ee40-4dc5-465b-94ae-942419f66982

📥 Commits

Reviewing files that changed from the base of the PR and between 5177ba4 and f54a3a5.

📒 Files selected for processing (1)
  • server/src/lib/ipUtils.test.ts

Move the ipUtils import up with the vitest import; the logger vi.mock
still applies since Vitest hoists it above the imports.
@mariazuheros

Copy link
Copy Markdown
Author

Addressed the import-grouping nitpick in e977582 — the ipUtils import is now grouped with the Vitest import at the top, and the vi.mock for the logger still applies since Vitest hoists it above the imports. All 17 tests still pass locally (cd server && npx vitest run src/lib/ipUtils.test.ts). Ready for review — thanks! 🙏

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