feat: update invite link blocker#94
Conversation
…d protocol coverage
|
Warning Review limit reached
More reviews will be available in 51 minutes and 36 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 credits. 🚦 How do rate 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 see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR deduplicates extracted invite URLs, updates ChangesInvite URL deduplication
Discord invite detection
Sequence Diagram(s)sequenceDiagram
participant isInviteLink
participant safeFetch
participant Response
participant isDiscordInviteLink
isInviteLink->>safeFetch: safeFetch(..., { detectDiscordProtocol: true })
safeFetch-->>isInviteLink: resolved Response
isInviteLink->>Response: read url and Location header
isInviteLink->>isDiscordInviteLink: check response.url
isInviteLink->>isDiscordInviteLink: check Location header when present
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
Preview deployed to: https://ThunLights.github.io/distopia/storybook/pr-preview-94 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/infrastructure/http/src/invite.test.ts (1)
204-215: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd coverage for the real
safeFetchredirect branch.These cases mock
safeFetch, so they cannot catch regressions indetectDiscordProtocolhandling. Add asafeFetchtest with a 3xxLocation: discord://discord.com/invite/abc123response to cover the new branch end-to-end.🤖 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/infrastructure/http/src/invite.test.ts` around lines 204 - 215, Add an end-to-end test for the redirect path in isInviteLink that uses the real safeFetch behavior instead of mocking it, so regressions in detectDiscordProtocol are covered. Extend the invite tests alongside the existing location header cases by asserting a 3xx response with Location set to discord://discord.com/invite/abc123 resolves to content: true, and keep the existing helper names (isInviteLink, detectDiscordProtocol, safeFetch) as the entry points for locating the change.
🤖 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/infrastructure/http/src/safefetch.ts`:
- Around line 69-70: The Discord redirect check in safefetch’s response handling
is comparing against the wrong URL protocol string, so the invite redirect
branch never triggers. Update the condition in the detectDiscordProtocol path to
match the actual protocol value returned by URL.protocol for discord invite
URLs, and keep the change localized to the response handling logic that returns
early before HeaderError is raised.
---
Nitpick comments:
In `@src/infrastructure/http/src/invite.test.ts`:
- Around line 204-215: Add an end-to-end test for the redirect path in
isInviteLink that uses the real safeFetch behavior instead of mocking it, so
regressions in detectDiscordProtocol are covered. Extend the invite tests
alongside the existing location header cases by asserting a 3xx response with
Location set to discord://discord.com/invite/abc123 resolves to content: true,
and keep the existing helper names (isInviteLink, detectDiscordProtocol,
safeFetch) as the entry points for locating the change.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c2bda132-e5a4-412f-b780-bbbb88b599d7
📒 Files selected for processing (8)
src/application/core/src/Message.tssrc/domain/service/src/url.test.tssrc/domain/service/src/url.tssrc/infrastructure/http/src/invite.test.tssrc/infrastructure/http/src/invite.tssrc/infrastructure/http/src/safefetch.test.tssrc/infrastructure/http/src/safefetch.tssrc/infrastructure/http/src/url.ts
| if (options?.detectDiscordProtocol && url.protocol === "discord://") { | ||
| return response; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
bun -e 'console.log(new URL("discord://discord.com/invite/abc123").protocol)'
# Expect: discord:Repository: ThunLights/distopia
Length of output: 198
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '--- src/infrastructure/http/src/safefetch.ts (relevant lines) ---\n'
sed -n '1,140p' src/infrastructure/http/src/safefetch.ts
printf '\n--- URL.protocol behavior in Node ---\n'
node - <<'JS'
const u = new URL('discord://discord.com/invite/abc123');
console.log(u.protocol);
JSRepository: ThunLights/distopia
Length of output: 248
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- src/infrastructure/http/src/safefetch.ts (relevant lines) ---'
sed -n '1,140p' src/infrastructure/http/src/safefetch.ts
echo
echo '--- URL.protocol behavior ---'
node - <<'JS'
const urls = [
'discord://discord.com/invite/abc123',
'https://example.com/path',
'mailto:test@example.com',
];
for (const raw of urls) {
const u = new URL(raw);
console.log(raw, '=>', u.protocol);
}
JSRepository: ThunLights/distopia
Length of output: 3365
Compare against discord: in the Discord redirect branch
URL.protocol returns discord: for discord://..., so this condition never matches and Discord invite redirects still fall through to HeaderError.
🤖 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/infrastructure/http/src/safefetch.ts` around lines 69 - 70, The Discord
redirect check in safefetch’s response handling is comparing against the wrong
URL protocol string, so the invite redirect branch never triggers. Update the
condition in the detectDiscordProtocol path to match the actual protocol value
returned by URL.protocol for discord invite URLs, and keep the change localized
to the response handling logic that returns early before HeaderError is raised.
|
Preview deployed to: https://ThunLights.github.io/distopia/storybook/pr-preview-94 |
Summary by CodeRabbit
New Features
Bug Fixes
Tests