Skip to content

Draft#1928

Closed
sagzy wants to merge 0 commit into
mainfrom
improve-undo-handler
Closed

Draft#1928
sagzy wants to merge 0 commit into
mainfrom
improve-undo-handler

Conversation

@sagzy

@sagzy sagzy commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a3cc5bf-7662-4276-b8aa-b01dabab9e27

📥 Commits

Reviewing files that changed from the base of the PR and between e072342 and 3a0bc62.

📒 Files selected for processing (2)
  • src/dispatchers.ts
  • src/dispatchers.unit.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/dispatchers.ts
  • src/dispatchers.unit.test.ts

Walkthrough

In createUndoHandler within src/dispatchers.ts, two early-exit guards were added to prevent spoofed Undo activities from being processed. For Undo(Follow), the handler now compares undo.actorId against the wrapped Follow's actorId before performing any account lookup or unfollow recording. For Undo(Announce), it checks that object.actorId matches undo.actorId before resolving the announce sender or removing a repost. Corresponding unit tests in src/dispatchers.unit.test.ts verify both the legitimate execution paths and the spoofed-actor rejection behavior for each case.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding validation to Undo activity handling.
Description check ✅ Passed The description accurately describes the Undo validation changes and added unit tests.
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 improve-undo-handler

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.

@sagzy sagzy force-pushed the improve-undo-handler branch 2 times, most recently from e9bb063 to 0460e30 Compare June 24, 2026 08:42

@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 (2)
src/dispatchers.unit.test.ts (2)

1340-1343: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use an interface for the mock shape.

This inline object type defines a reusable object shape; moving it to an interface keeps the test aligned with the TypeScript guideline.

♻️ Proposed refactor
+interface MockGlobalDb {
+    get: ReturnType<typeof vi.fn>;
+    set: ReturnType<typeof vi.fn>;
+}
+
     describe('createUndoHandler', () => {
@@
-        let mockGlobalDb: {
-            get: ReturnType<typeof vi.fn>;
-            set: ReturnType<typeof vi.fn>;
-        };
+        let mockGlobalDb: MockGlobalDb;

As per coding guidelines, **/*.{ts,tsx}: "Prefer interface for defining object shapes in TypeScript."

🤖 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/dispatchers.unit.test.ts` around lines 1340 - 1343, The mock shape for
mockGlobalDb is currently defined inline as an object type, which should be
moved to an interface to match the TypeScript style guideline. Define a reusable
interface for this shape near the test helpers or alongside the relevant setup
in dispatchers.unit.test.ts, then update mockGlobalDb to use that interface
while keeping the same get and set vi.fn members.

Source: Coding guidelines


1384-1391: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid AP ID string comparisons in the mock implementation.

The mock branches on AP IDs with direct === checks. Prefer ordered mock responses plus explicit call assertions, or the same AP-ID helper used by production code.

♻️ Proposed refactor
-                vi.mocked(
-                    mockAccountService.getAccountByApId,
-                ).mockImplementation(async (apId: string) => {
-                    if (apId === aliceUrl.href) {
-                        return { id: 10 } as AccountType;
-                    }
-                    if (apId === ghostUserUrl.href) {
-                        return { id: 1 } as AccountType;
-                    }
-                    return null;
-                });
+                vi.mocked(mockAccountService.getAccountByApId)
+                    .mockResolvedValueOnce({ id: 10 } as AccountType)
+                    .mockResolvedValueOnce({ id: 1 } as AccountType);

As per coding guidelines, src/**/*.ts: "Never use direct string comparisons for ActivityPub IDs."

🤖 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/dispatchers.unit.test.ts` around lines 1384 - 1391, The mock in the test
setup is using direct ActivityPub ID string comparisons inside the mocked
lookup, which violates the AP ID guideline. Refactor the mock around the
affected lookup helper (the mocked function in src/dispatchers.unit.test.ts) to
avoid branching on apId with direct === checks; instead use ordered mock return
values or assert the expected call sequence explicitly, and if you need to
distinguish IDs, rely on the same AP-ID helper used by production code rather
than raw string equality.

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.

Inline comments:
In `@src/dispatchers.ts`:
- Line 511: The Undo actor validation in dispatchers should use URI
normalization instead of comparing .href directly. Update the actor checks in
the Undo handling logic around the undo.actorId and follow.actorId comparison to
use isEqual() from src/helpers/uri.ts, keeping the existing guard behavior but
making the URI comparison consistent with the rest of the codebase.

---

Nitpick comments:
In `@src/dispatchers.unit.test.ts`:
- Around line 1340-1343: The mock shape for mockGlobalDb is currently defined
inline as an object type, which should be moved to an interface to match the
TypeScript style guideline. Define a reusable interface for this shape near the
test helpers or alongside the relevant setup in dispatchers.unit.test.ts, then
update mockGlobalDb to use that interface while keeping the same get and set
vi.fn members.
- Around line 1384-1391: The mock in the test setup is using direct ActivityPub
ID string comparisons inside the mocked lookup, which violates the AP ID
guideline. Refactor the mock around the affected lookup helper (the mocked
function in src/dispatchers.unit.test.ts) to avoid branching on apId with direct
=== checks; instead use ordered mock return values or assert the expected call
sequence explicitly, and if you need to distinguish IDs, rely on the same AP-ID
helper used by production code rather than raw string equality.
🪄 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: d9d85f5f-02bc-4e52-9d8e-460c10db500e

📥 Commits

Reviewing files that changed from the base of the PR and between 09a98bc and e072342.

📒 Files selected for processing (2)
  • src/dispatchers.ts
  • src/dispatchers.unit.test.ts

Comment thread src/dispatchers.ts Outdated
@sagzy sagzy force-pushed the improve-undo-handler branch from 0460e30 to 3a0bc62 Compare June 24, 2026 09:14
@sagzy sagzy closed this Jun 24, 2026
@sagzy sagzy force-pushed the improve-undo-handler branch from 3a0bc62 to d7f80ca Compare June 24, 2026 09:17
@sagzy sagzy deleted the improve-undo-handler branch June 24, 2026 09:17
@sagzy sagzy changed the title Improve Undo activity handling Draft Jun 24, 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