test(server): cover ipUtils IP matching helpers - #1049
Conversation
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.
|
@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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Vitest coverage for ChangesIP utility test coverage
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/src/lib/ipUtils.test.ts (1)
1-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueGroup 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.mockcalls 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
📒 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.
|
Addressed the import-grouping nitpick in e977582 — the |
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