Skip to content

Fix dead assertion in Slack private-channel audience test - #2748

Open
kapunahelewong wants to merge 1 commit into
BuilderIO:mainfrom
kapunahelewong:fix/private-channel-audience-test-assertion
Open

Fix dead assertion in Slack private-channel audience test#2748
kapunahelewong wants to merge 1 commit into
BuilderIO:mainfrom
kapunahelewong:fix/private-channel-audience-test-assertion

Conversation

@kapunahelewong

Copy link
Copy Markdown
Contributor

Problem

The test `"ignores Slack bot and app members when deriving a private-channel audience"` in templates/brain/server/lib/brain.test.ts asserted:

expect(
  mocks.rows.audienceMembers.map((member) => member.principalId),
).toEqual(["ada@example.test"]);

But ./audiences.js is fully mocked at the top of the same test file, and the mocked ensureCaptureAudience never writes to mocks.rows.audienceMembers — it always hardcodes kind: "org" and ignores whatever memberEmails/kind are actually passed in. So the real audience-membership logic in audiences.ts never runs during this test, and mocks.rows.audienceMembers is always []. The assertion could never pass — deterministic, not a flake.

This was blocking PR #2711 (an unrelated docs-only PR) from going green in CI.

Fix

Switched the assertion to the same convention already used by sibling tests in this describe block (e.g. around L2979/L3025/L3031): assert on what the mocked ensureCaptureAudience was actually called with, rather than reading back a mock table the stub never populates.

expect(vi.mocked(ensureCaptureAudience)).toHaveBeenCalledWith(
  expect.objectContaining({
    kind: "slack-private-channel",
    memberEmails: ["ada@example.test"],
    upstreamRefHash: "G123",
  }),
);

This matches what createSlackThreadCapture in connectors.ts actually passes through createCaptureensureCaptureAudience.

Verification

  • Target test passes in isolation.
  • Confirmed the test actually catches a regression: temporarily disabled the bot/app-user filter (is_bot/is_app_user/is_workflow_bot/deleted) in connectors.ts, reran, saw it fail, then restored the filter (git diff on connectors.ts shows no residual changes).
  • Full brain suite: 282/282 tests passing across 34 files.

Only one file changed — templates/brain/server/lib/brain.test.ts.

🤖 Generated with Claude Code

The test "ignores Slack bot and app members when deriving a
private-channel audience" asserted against mocks.rows.audienceMembers,
but ensureCaptureAudience is fully mocked in this file and never
writes to that array (it always hardcodes kind: "org" and ignores
memberEmails). The assertion could never pass and never actually
exercised the bot/app-member filtering it claimed to cover.

Switch to the same convention already used by sibling tests in this
describe block: assert on what the mocked ensureCaptureAudience was
called with (kind, memberEmails, upstreamRefHash), matching what
createSlackThreadCapture actually passes through createCapture.

Verified the fix catches a real regression: temporarily disabled the
bot/app-user filter in connectors.ts, confirmed this test fails, then
restored the filter. Full brain suite: 282/282 passing, 34 files.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netlify

This comment has been minimized.

@netlify

This comment has been minimized.

@netlify

This comment has been minimized.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Here's a visual recap of what changed:

Visual recap

Open the full interactive recap

@builder-io-integration builder-io-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Builder reviewed your changes — looks good ✅

Review Details

Code Review Summary

PR #2748 replaces a dead assertion in the Slack private-channel audience test with an assertion against the mocked ensureCaptureAudience call. This aligns the test with the actual mock boundary and verifies the filtered member email, private-channel audience kind, and upstream reference hash that createSlackThreadCapture should pass through.

The approach is sound for this low-risk, test-only change. Two independent reviews found no confirmed correctness, security, or performance issues. The new assertion is materially stronger than reading mocks.rows.audienceMembers, which the fully mocked audience implementation does not populate, and the reported targeted and full-suite verification supports the change. No comments are required.

Risk assessment: Low risk (test-only change).

🧪 Browser testing: Skipped — PR only modifies backend/config/docs, no UI impact

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