Skip to content

feat(ip): normalize IPv4-mapped IPv6 addresses#29

Merged
Yusuke4869 merged 1 commit into
mainfrom
feat/normalize-ip-addresses
Jun 13, 2026
Merged

feat(ip): normalize IPv4-mapped IPv6 addresses#29
Yusuke4869 merged 1 commit into
mainfrom
feat/normalize-ip-addresses

Conversation

@Yusuke4869

@Yusuke4869 Yusuke4869 commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

リリースノート

  • New Features

    • IP アドレスのログ記録で IPv4 マップド IPv6 形式が IPv4 に正規化されるようになりました。
  • Tests

    • IP アドレス正規化機能のテストを追加しました。

Copilot AI review requested due to automatic review settings June 13, 2026 02:43

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

新しい IP 正規化ユーティリティ normalizeIpAddress を実装し、IPv4-mapped IPv6 アドレスを IPv4 に変換する機能を提供。包括的なテストケースを追加し、既存のロギングフォーマッタ(formatAccessLogformatApiLog)に統合してアクセスログと API ログのフッター IP を正規化。

Changes

IP 正規化とロギング統合

Layer / File(s) Summary
IP正規化ユーティリティ実装
src/util/ip.ts
normalizeIpAddress 関数を実装。undefined 値の処理、::ffff: 接頭辞の検出と削除、ドット記法(::ffff:192.0.2.1)と 16 進ブロック形式(::ffff:7f00:1)の両方の IPv4-mapped IPv6 から IPv4 への変換、一致しないアドレスの直接通過を実装。
IP正規化関数のテスト
src/util/ip.test.ts
IPv4(127.0.0.1)、IPv4-mapped IPv6 ドット記法(::ffff:127.0.0.1)、IPv4-mapped IPv6 16進形式(::ffff:7f00:1)、通常の IPv6(2001:db8::1)について各々 assertEquals で検証。
ロギングフォーマッタへの統合
src/service/logging/formatter.ts
normalizeIpAddress をインポート。formatAccessLogformatApiLog の両関数内で Discordウェブフック embeds の footer IP を info.remote.address から normalizeIpAddress(info.remote.address) に変更。

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 新しいユーティリティが IP を整えて
マップドアドレスを IPv4 に変換し
ロギングのフッターで整然と表示
テストが四つの形を確かめ
ウェブフックへ正規化された IP が流れる

🚥 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 PRのタイトルは、新しく追加された normalizeIpAddress 機能とそのIPv4マップIPv6アドレス正規化の主な目的を明確に反映しており、変更セット全体の主要な目的と完全に一致しています。
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/normalize-ip-addresses

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 and usage tips.

@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: 2

🧹 Nitpick comments (1)
src/util/ip.test.ts (1)

5-33: ⚡ Quick win

境界値(undefined と空文字)のテストを追加してください。

今回の機能目的にある未定義値処理の回帰防止のため、normalizeIpAddress(undefined)normalizeIpAddress("") の期待値を固定するテストを追加するのが安全です。

追加入力例
 Deno.test("normalizeIpAddress keeps normal IPv6 as-is", () => {
   assertEquals(normalizeIpAddress("::1"), "::1");
   assertEquals(normalizeIpAddress("fc00:db8::1"), "fc00:db8::1");
 });
+
+Deno.test("normalizeIpAddress handles undefined and empty string", () => {
+  assertEquals(normalizeIpAddress(undefined), undefined);
+  assertEquals(normalizeIpAddress(""), "");
+});
🤖 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 `@src/util/ip.test.ts` around lines 5 - 33, Add a new Deno.test that asserts
normalizeIpAddress handles undefined and empty-string inputs to prevent
regressions: call normalizeIpAddress(undefined) and assertEquals the result to
undefined, and call normalizeIpAddress("") and assertEquals the result to ""
(use the existing test pattern and the normalizeIpAddress symbol to locate where
to add the test).
🤖 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 `@src/service/logging/formatter.ts`:
- Around line 63-65: The footer currently inserts "undefined" when
normalizeIpAddress(info.remote.address) returns undefined; update the formatting
logic used in the footer (and the similar occurrence at the other block) to fall
back to "Unknown" when info.remote.address is missing or normalizeIpAddress
returns a falsy/undefined value — i.e., compute a safeIp =
normalizeIpAddress(info.remote?.address) || "Unknown" and use safeIp in the text
template (references: normalizeIpAddress, info.remote.address, formatTimestamp).

In `@src/util/ip.ts`:
- Line 5: The current guard treats empty string as undefined because it uses `if
(!address) return;`; change this to only early-return for actual undefined by
replacing the condition with a strict undefined check (e.g., `address ===
undefined`) so that "" is not treated as missing; update the guard that
references the `address` variable in this module (`src/util/ip.ts`) accordingly.

---

Nitpick comments:
In `@src/util/ip.test.ts`:
- Around line 5-33: Add a new Deno.test that asserts normalizeIpAddress handles
undefined and empty-string inputs to prevent regressions: call
normalizeIpAddress(undefined) and assertEquals the result to undefined, and call
normalizeIpAddress("") and assertEquals the result to "" (use the existing test
pattern and the normalizeIpAddress symbol to locate where to add the test).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73311c77-79e4-42fd-be0a-564edaff433f

📥 Commits

Reviewing files that changed from the base of the PR and between e915d3a and f5df5a5.

📒 Files selected for processing (3)
  • src/service/logging/formatter.ts
  • src/util/ip.test.ts
  • src/util/ip.ts

Comment thread src/service/logging/formatter.ts
Comment thread src/util/ip.ts
@Yusuke4869 Yusuke4869 merged commit 39e0128 into main Jun 13, 2026
6 checks passed
@Yusuke4869 Yusuke4869 deleted the feat/normalize-ip-addresses branch June 13, 2026 02:49
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.

2 participants