Skip to content

feat: update invite link blocker#94

Merged
ro80t merged 11 commits into
mainfrom
fix-invite-link
Jun 27, 2026
Merged

feat: update invite link blocker#94
ro80t merged 11 commits into
mainfrom
fix-invite-link

Conversation

@ro80t

@ro80t ro80t commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Improved invite-link detection across more Discord URL formats, including additional app schemes and redirect-based links.
    • Added broader URL protocol handling during link checks.
  • Bug Fixes

    • Duplicate invite and regular links are now removed from extracted results.
    • Invite detection now checks both the final destination and redirect headers more reliably.
  • Tests

    • Expanded coverage for invite-link matching, redirect handling, and URL deduplication.
    • Updated existing tests to reflect the new unique-link behavior.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ro80t, we couldn't start this review because you've reached your PR review rate limit.

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 @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 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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fd0f0bb5-f709-4e92-a884-a56a05554bbf

📥 Commits

Reviewing files that changed from the base of the PR and between a60bc84 and 61cb38d.

📒 Files selected for processing (4)
  • src/infrastructure/http/src/invite.test.ts
  • src/infrastructure/http/src/invite.ts
  • src/infrastructure/http/src/safefetch.test.ts
  • src/infrastructure/http/src/safefetch.ts
📝 Walkthrough

Walkthrough

The PR deduplicates extracted invite URLs, updates Message.includeInviteLink to return unique links, and rewrites Discord invite detection to parse URLs by protocol, host, and path while allowing discord:// redirects in safeFetch.

Changes

Invite URL deduplication

Layer / File(s) Summary
Domain URL extraction and tests
src/domain/service/src/url.ts, src/domain/service/src/url.test.ts
findUrlsSync uses sets for invite and normal URLs, returns arrays from those sets, and the tests cover repeated Discord invite and example URLs.
Message invite list deduplication
src/application/core/src/Message.ts
includeInviteLink now declares Promise<string[]> and returns the invite link array without duplicates.

Discord invite detection

Layer / File(s) Summary
HTTP protocol helper and redirect option
src/infrastructure/http/src/url.ts, src/infrastructure/http/src/safefetch.ts, src/infrastructure/http/src/safefetch.test.ts
isHttpProtocol is added, safeFetch accepts detectDiscordProtocol, redirect handling allows discord:// responses when enabled, and the url mock preserves original exports.
Discord invite matching
src/infrastructure/http/src/invite.ts, src/infrastructure/http/src/invite.test.ts
DISCORD_INVITE_LINK_START includes discord:// prefixes, isInviteLink checks parsed response URLs and Location headers against allowed Discord protocols and hosts, and the tests cover the legacy prefixes and constant coverage.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ThunLights/distopia#64: Adds the safeFetch redirect handling that this PR extends with Discord protocol detection.
  • ThunLights/distopia#75: Touches Message.includeInviteLink, the same consumer updated here to return unique invite links.

Poem

🐰 I hopped through links by moonlight blue,
and found each invite only once or two—
but one became one, and the duplicates flew,
while Discord trails glimmered in protocol dew.
Hoppy tidy trails!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: updating the invite link blocker.
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 fix-invite-link

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.

@github-actions

Copy link
Copy Markdown
Contributor

github-actions Bot pushed a commit that referenced this pull request Jun 27, 2026

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

🧹 Nitpick comments (1)
src/infrastructure/http/src/invite.test.ts (1)

204-215: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for the real safeFetch redirect branch.

These cases mock safeFetch, so they cannot catch regressions in detectDiscordProtocol handling. Add a safeFetch test with a 3xx Location: discord://discord.com/invite/abc123 response 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

📥 Commits

Reviewing files that changed from the base of the PR and between c30a9c6 and a60bc84.

📒 Files selected for processing (8)
  • src/application/core/src/Message.ts
  • src/domain/service/src/url.test.ts
  • src/domain/service/src/url.ts
  • src/infrastructure/http/src/invite.test.ts
  • src/infrastructure/http/src/invite.ts
  • src/infrastructure/http/src/safefetch.test.ts
  • src/infrastructure/http/src/safefetch.ts
  • src/infrastructure/http/src/url.ts

Comment on lines +69 to +70
if (options?.detectDiscordProtocol && url.protocol === "discord://") {
return response;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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);
JS

Repository: 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);
}
JS

Repository: 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.

@github-actions

Copy link
Copy Markdown
Contributor

github-actions Bot pushed a commit that referenced this pull request Jun 27, 2026
@ro80t ro80t merged commit bb4564a into main Jun 27, 2026
26 checks passed
@ro80t ro80t deleted the fix-invite-link branch June 27, 2026 04:59
github-actions Bot pushed a commit that referenced this pull request Jun 27, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jun 30, 2026
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