Skip to content

Close the twelve mutations that still survived the suite - #118

Merged
imshashank merged 5 commits into
mainfrom
tests/residual-mutation-gaps
Aug 7, 2026
Merged

Close the twelve mutations that still survived the suite#118
imshashank merged 5 commits into
mainfrom
tests/residual-mutation-gaps

Conversation

@imshashank

Copy link
Copy Markdown
Contributor

Twelve guards that already exist in production code had nothing holding
them up. Each one could be deleted and the whole suite stayed green, so
the regression would have shipped without a red build anywhere.

Every test here was watched failing first: the guard it covers was
deliberately broken, the named tests went red, and the break was
reverted before the next one started. No production code changes.

Slack, in packages/services

The suite seeded one workspace with one Slack integration, which can
prove team scoping and can never prove workspace scoping.

Mutation Killed by
resolveSlackTargets drops eq(slackChannelSync.organizationId, organizationId) 3 tests
resolveSlackContext drops eq(integration.organizationId, organizationId) 3 tests
resolveSlackContext drops eq(integration.provider, 'slack') 2 tests

A second workspace with its own Slack team and its own token now exists
in the fixture, so an issue on workspace A's Engineering team can be
shown never to resolve into workspace B's channel, and the dispatch
records the authorization header it actually sent. A workspace whose
only integration is GitHub resolves to no Slack context at all.

resolveCycle, in packages/mcp-server

The one resolver tests/resolve.test.ts skipped. Replacing the whole
match with cycles[0] passed the suite, and so did deleting the
active shortcut. An agent told to file into Sprint 3 would have filed
into Sprint 1.

Engineering now has three sprints and only the first is running, design
and operations have one each, and operations has its sprint closed so
the empty active case lands somewhere. cycles[0] kills 5 tests,
dropping the active branch kills 1.

The session sweep, in packages/realtime-server

sweepSessions is the fail-closed sweep that closes a socket whose
session went away with no control message to announce it, and it had no
test at all. Returning early from it passed 68 tests, and so did
dropping gt(session.expiresAt, now) from liveSessionIds. A signed
out tab would have kept streaming until the process restarted.

A hub with a short sweep interval now finds an expired session and a
deleted one, closes each with session_revoked, and leaves a live
session subscribed across a dozen sweeps. The early return kills 2
tests, the expiry filter kills 1.

Labels, in packages/core

getLabel, updateLabel and deleteLabel each scope their where
clause to the caller's workspace, and every label test ran inside one
workspace, so all three clauses could be deleted with 553 tests green.
Any admin could have renamed or deleted a label in a workspace they
have never belonged to.

A same named label now sits in each of two workspaces and each reaches
for the other. The three clauses kill 1, 2 and 1 test respectively.

useToggleReaction and the Slack webhook, in apps/web

useToggleReaction was the only exported hook in use-comments with
no test, so it could have posted anywhere and 1045 tests stayed green.
It now proves the endpoint it asks, the emoji it sends, the optimistic
add and the optimistic remove, and the rollback behind the error toast.

The webhook picks the bot token by Slack team id, and every fixture
workspace had exactly one integration, so the argument could be dropped
with nothing failing. One workspace now has two Slack teams, and the
recording client keeps the token it was constructed with.

Verification

bun run verify exits 0 against main merged in: lint, comment
policy, byte policy, typecheck, and 2291 tests.

…aring

resolveSlackTargets and resolveSlackContext each filter on
organizationId, and resolveSlackContext also filters on provider. The
suite seeded one workspace with one slack integration, so all three
clauses could be deleted with 436 tests still green: a workspace could
have been offered another workspace channel, and dispatched with
another workspace bot token.

Seed a second workspace with its own slack team and its own token, plus
a workspace whose only integration is github, and record the
authorization header the dispatch actually sends.
resolveCycle was the one resolver with no test, so it could return
cycles[0] regardless of the reference and drop the "active" shortcut
entirely with the suite still green. An agent asked to move an issue
into Sprint 3 would have moved it into Sprint 1.

Give engineering three sprints, design and operations one each, and
close the operations sprint so the empty active case has something to
land on.
The sweep is what closes a socket whose session went away without a
control message ever announcing it, and it had no test. sweepSessions
could return before doing anything, and liveSessionIds could stop
filtering on the expiry, with the whole suite green either way: a
signed out tab would have kept streaming.

Run a hub with a short sweep interval and let it find an expired
session and a deleted one, while a live session stays connected.
…leting

getLabel, updateLabel and deleteLabel each scope their where clause to
the caller workspace, and every label test ran inside a single
workspace, so all three clauses could be deleted with 553 tests green.
Any admin could have renamed or deleted a label belonging to a
workspace they have never been a member of.

Put a same named label in each of two workspaces and let each one
reach for the other.
useToggleReaction was the one exported hook in use-comments with no
test, so it could have posted to any url at all and 1045 tests stayed
green. Assert the endpoint it asks, the emoji it sends, the optimistic
add and remove, and the rollback behind the error toast.

The slack webhook picks the bot token by slack team id, and every
fixture workspace had exactly one integration, so the argument could be
dropped without a failure. Give one workspace a second slack team and
record the token the client was constructed with.
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 6, 2026 4:16pm

Request Review

@greptile-apps greptile-apps 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.

imshashank has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR expands test coverage for Slack workspace scoping, comment reactions, label isolation, cycle resolution, and realtime session cleanup.

Changes

Slack workspace routing

Layer / File(s) Summary
Workspace-scoped Slack dispatch
packages/services/tests/slack/dispatch.test.ts
Configurable fixtures and assertions cover workspace-specific Slack integrations, channels, users, and bot tokens.
Originating-team unfurl tokens
apps/web/tests/app/api/webhooks/slack/route.test.ts
Webhook tests verify that each unfurl uses the token configured for its originating Slack team.

Comment reactions

Layer / File(s) Summary
Reaction mutation behavior
apps/web/tests/lib/query/use-comments.test.tsx
Tests cover optimistic reaction changes, request payloads, settlement, rollback, preservation of other reactions, and error toasts.

Label workspace isolation

Layer / File(s) Summary
Workspace-bound label operations
packages/core/tests/work/label-service.test.ts
Tests verify cross-workspace rejection for label reads and mutations, while owned-label operations succeed.

Cycle resolution

Layer / File(s) Summary
Cycle fixture and resolver coverage
packages/mcp-server/tests/resolve.test.ts
Fixtures and tests cover cycle lookup by name, number, ID, and active status, plus normalization, team scoping, unknown references, and closed teams.

Realtime session sweeps

Layer / File(s) Summary
Session sweep lifecycle coverage
packages/realtime-server/tests/hub.test.ts
Tests verify that expired or deleted sessions close and that live sessions retain connections and subscriptions across sweeps.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the twelve regression tests, affected components, fixture changes, and verification results.
Title check ✅ Passed The title clearly summarizes that the pull request adds tests to eliminate twelve mutations that survived the existing suite.
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.
✨ 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 tests/residual-mutation-gaps

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.

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

🧹 Nitpick comments (2)
packages/services/tests/slack/dispatch.test.ts (2)

32-85: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Return integrationId only when the fixture inserts a Slack integration.

If options.botToken is undefined, seedWorkspace inserts no Slack integration but still returns integrationId. The returned ID then points to no row. A later test that passes that ID to connectSlackChannel fails on the foreign key, or worse, asserts against a phantom integration. Make the field optional so the type reflects reality.

♻️ Proposed fix
 interface Fixture {
   readonly organizationId: string;
-  readonly integrationId: string;
+  readonly integrationId: string | null;
   readonly userId: string;
   readonly teamA: string;
   readonly teamB: string;
 }
@@
-  const integrationId = `int_${suffix}`;
+  let integrationId: string | null = null;
   if (options.botToken !== undefined) {
+    integrationId = `int_${suffix}`;
     await tx.insert(integration).values({
       id: integrationId,

Note that this change requires the call sites that pass fixture.integrationId to narrow the value first.

🤖 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 `@packages/services/tests/slack/dispatch.test.ts` around lines 32 - 85, Update
the Fixture type and seedWorkspace so integrationId is optional and is returned
only when the Slack integration is inserted for a defined botToken. Narrow
fixture.integrationId at every call site that passes it to connectSlackChannel
or otherwise requires an existing integration, while preserving unconditional
fixture fields.

480-562: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the two-workspace setup used by both dispatch tests.

Both tests seed Acme and Globex with the same options and connect one channel per workspace. A shared helper removes the repetition and keeps the assertions in focus.

♻️ Proposed fix
+async function seedTwoWorkspaces(
+  tx: TestTransaction,
+): Promise<{ readonly acme: Fixture; readonly globex: Fixture }> {
+  const acme = await seedWorkspace(tx, {
+    name: 'Acme',
+    slackTeamId: 'T-acme',
+    botToken: 'xoxb-acme',
+  });
+  const globex = await seedWorkspace(tx, {
+    name: 'Globex',
+    slackTeamId: 'T-globex',
+    botToken: 'xoxb-globex',
+  });
+  return { acme, globex };
+}
🤖 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 `@packages/services/tests/slack/dispatch.test.ts` around lines 480 - 562,
Extract the repeated Acme/Globex workspace seeding and channel connections from
both tests into a shared setup helper near the dispatch tests. Have the helper
return the seeded workspace data needed by each test, while preserving the
existing workspace-specific channel configuration and keeping each test’s
dispatch inputs and assertions unchanged.
🤖 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 `@packages/services/tests/slack/dispatch.test.ts`:
- Around line 32-85: Update the Fixture type and seedWorkspace so integrationId
is optional and is returned only when the Slack integration is inserted for a
defined botToken. Narrow fixture.integrationId at every call site that passes it
to connectSlackChannel or otherwise requires an existing integration, while
preserving unconditional fixture fields.
- Around line 480-562: Extract the repeated Acme/Globex workspace seeding and
channel connections from both tests into a shared setup helper near the dispatch
tests. Have the helper return the seeded workspace data needed by each test,
while preserving the existing workspace-specific channel configuration and
keeping each test’s dispatch inputs and assertions unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ff21f87e-be1d-4659-8954-d70220937039

📥 Commits

Reviewing files that changed from the base of the PR and between 5952ad4 and aee85aa.

📒 Files selected for processing (6)
  • apps/web/tests/app/api/webhooks/slack/route.test.ts
  • apps/web/tests/lib/query/use-comments.test.tsx
  • packages/core/tests/work/label-service.test.ts
  • packages/mcp-server/tests/resolve.test.ts
  • packages/realtime-server/tests/hub.test.ts
  • packages/services/tests/slack/dispatch.test.ts

@imshashank
imshashank merged commit 468980e into main Aug 7, 2026
11 of 15 checks passed
@imshashank
imshashank deleted the tests/residual-mutation-gaps branch August 7, 2026 18:54
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