Skip to content

fix(connector-slack): no construct-time Slack auth (green main)#152

Merged
harry-harish merged 1 commit into
mainfrom
fix/connector-slack-bolt-defer-init
Jul 9, 2026
Merged

fix(connector-slack): no construct-time Slack auth (green main)#152
harry-harish merged 1 commit into
mainfrom
fix/connector-slack-bolt-defer-init

Conversation

@harry-harish

@harry-harish harry-harish commented Jul 9, 2026

Copy link
Copy Markdown
Member

Root cause

SlackAdapter's constructor called new App({ token, appToken, socketMode: true }).
Bolt's App constructor fires a construct-time auth.test() call to api.slack.com to
fetch bot identity. In tests, fake tokens (xoxb-test / xapp-test) make this reject
with invalid_auth. Nothing awaited the rejection, so vitest reported 3 unhandled promise
rejections and failed the process — even though all 7 assertions passed.

Fix

Production fix (preferred over vi.mock): deferInitialization: true

  • Added deferInitialization: true to the Bolt App constructor options. This is an
    official Bolt 4.x API that skips the construct-time auth.test() call entirely.
  • SlackAdapter.start() now calls await this.app.init() before await this.app.start()
    to run the deferred initialization at the correct moment (Bolt's init()start()
    sequence when deferInitialization is used).

No mock or test-only shim is needed — the fix is in production code, which also benefits
real integrations where you want to construct the adapter before credentials are verified
(e.g. DI containers, lazy initialization).

New guard test

Added a 'SlackAdapter construction' describe block that:

  1. Constructs SlackAdapter with fake tokens and asserts no synchronous throw.
  2. Flushes microtasks via await Promise.resolve() to surface any immediate rejection.
  3. Asserts the adapter instance is defined.

This test locks in the network-free construction invariant so regressions are caught immediately.

Verification

pnpm --filter @peekdev/connector-slack exec vitest run src/slack-adapter.test.ts
# ✓ 8 tests, 0 unhandled rejections
pnpm build && pnpm typecheck && pnpm lint && pnpm test
# all green (1161+ tests across all packages)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Slack connector startup so creating the adapter no longer triggers an immediate network call or async rejection.
    • Startup now completes initialization before the connector begins running, making app launch more reliable.
  • Tests
    • Added coverage for adapter construction to verify it can be created safely without throwing.

… makes no network call

Bolt's App constructor fires a construct-time auth.test() call to
api.slack.com. With fake tokens (xoxb-test / xapp-test) in tests this
resolves to an `invalid_auth` rejection — unhandled, because nothing
awaits it — causing vitest to report 3 unhandled promise rejections and
fail the process even though all 7 test assertions passed.

Fix: pass `deferInitialization: true` to the Bolt App constructor so the
auth.test() call is skipped at construction time. SlackAdapter.start()
now calls `await this.app.init()` before `await this.app.start()` to run
the deferred initialization at the right moment (Bolt 4.x API).

A new guard test ("SlackAdapter construction") constructs an adapter with
fake tokens, flushes microtasks via `await Promise.resolve()`, and asserts
no throw/rejection — locks in the network-free construction invariant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: harry-harish <22562634+harry-harish@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 42c87b81-3a0a-415c-9f62-40d1a11e6442

📥 Commits

Reviewing files that changed from the base of the PR and between 8947f44 and 33c4b9f.

📒 Files selected for processing (2)
  • packages/connector-slack/src/slack-adapter.test.ts
  • packages/connector-slack/src/slack-adapter.ts

📝 Walkthrough

Walkthrough

SlackAdapter's Bolt App construction now sets deferInitialization: true, and start() explicitly calls app.init() before app.start() to complete deferred initialization. A new test verifies constructing SlackAdapter does not throw synchronously or trigger an immediate unhandled rejection.

Changes

Slack Adapter deferred init

Layer / File(s) Summary
Deferred initialization and startup sequencing
packages/connector-slack/src/slack-adapter.ts
Bolt App is constructed with deferInitialization: true, and start() now awaits app.init() before app.start().
Construction safety test
packages/connector-slack/src/slack-adapter.test.ts
New test constructs SlackAdapter with fake tokens and confirms no synchronous throw or immediate unhandled rejection occurs.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SlackAdapter
    participant BoltApp

    Caller->>SlackAdapter: new SlackAdapter(tokens)
    SlackAdapter->>BoltApp: new App({ deferInitialization: true })
    Note over BoltApp: no auth.test() call yet

    Caller->>SlackAdapter: start()
    SlackAdapter->>BoltApp: await app.init()
    SlackAdapter->>BoltApp: await app.start()
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing Slack auth during SlackAdapter construction.
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 fix/connector-slack-bolt-defer-init

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.

@harry-harish

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@harry-harish

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@harry-harish harry-harish merged commit 0bc4cff into main Jul 9, 2026
7 checks passed
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