Skip to content

test: resolve SonarCloud S7503 in the global fetch stub - #287

Merged
asafgolombek merged 1 commit into
mainfrom
dev/asaf/sonar-fetch-stub-s7503
Oct 4, 2026
Merged

asafgolombek merged 1 commit into
mainfrom
dev/asaf/sonar-fetch-stub-s7503

Conversation

@asafgolombek

@asafgolombek asafgolombek commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SonarCloud's first main analysis after the maintenance sweep merged (#286, 44b4d41) reported one new issue: typescript:S7503 on stubGlobalFetch in sdks/typescript/src/test-support/global-fetch-stub.ts, an async arrow with no await. The file did not change in #286. That merge moved sonarqube-scan-action from v8.2.1 to v8.3.0, and the newer analyzer reports a pattern the old one let through. Every other repo in the sweep is at 0 open issues on main.

Why not just drop async

The async wrapper made a throwing handler reject the returned promise, the way the real fetch reports a network failure. mcp-tool-kit.test.ts stubs a handler that throws and expects a rejection. Promise.resolve(handler(url, init)) would let that throw escape fetch() synchronously, which breaks any caller that attaches .catch to the call. The stub now returns a new Promise whose executor calls the handler: a returned value or promise is adopted, and a throw rejects.

Test

a throwing handler rejects the returned promise instead of throwing at the call attaches .then to the fetch(...) call, so a synchronous throw fails the test before the assertion. Red-proved: it fails with the Promise.resolve variant, and passes with this change and with the previous async wrapper. It pins the behaviour, not the implementation.

Verification

  • bun run lint: 162 files, no findings
  • bun run typecheck: clean
  • bun run test: 2068 pass, 0 fail

Test-only module, excluded from tsconfig.build.json; nothing published changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed fetch stubs so errors thrown by handlers reject the returned promise instead of escaping synchronously when fetch is called. Network-failure scenarios now follow the expected promise-based behavior, allowing errors to be handled through standard rejection handling. This also makes fetch stub behavior more consistent with real-world fetch calls.

SonarCloud's first main analysis after the maintenance sweep merged
(44b4d41, scanner action v8.2.1 -> v8.3.0) opened one issue:
typescript:S7503 on `stubGlobalFetch`, an async arrow with no `await`.
The file did not change; the newer analyzer reports a pattern the older
one let through.

The `async` was doing a job, though. A handler that throws became a
rejected promise, which is what the real `fetch` does with a network
failure, and mcp-tool-kit.test.ts depends on it. Dropping `async` for
`Promise.resolve(handler(...))` would let that throw escape `fetch()`
synchronously. A `new Promise` executor keeps the behaviour: the
executor runs the handler, and a throw inside it rejects the promise.

A new test pins that property. It attaches `.then` to the call, so a
synchronous throw fails the test before the assertion. With the
`Promise.resolve` variant it fails; with this change and with the
previous async wrapper it passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
CLAUDE.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: nimbus-agent/nimbus-sdk/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 38d6e080-b6c2-477e-8a41-5f37bd480117
📥 Commits

Reviewing files that changed from the base of the PR and between 44b4d41 and 811315d.

📒 Files selected for processing (2)
  • sdks/typescript/src/test-support/global-fetch-stub.test.ts
  • sdks/typescript/src/test-support/global-fetch-stub.ts

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

The global fetch stub now wraps handler execution in a promise executor, so synchronous handler errors reject the returned promise. A test covers a handler that throws TypeError("network down").

Changes

Global fetch stub

Layer / File(s) Summary
Wrap handler execution in a promise
sdks/typescript/src/test-support/global-fetch-stub.ts, sdks/typescript/src/test-support/global-fetch-stub.test.ts
The stub invokes its handler inside a promise executor. The test checks that a thrown TypeError("network down") rejects the fetch promise.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 81131

The stub preserves promise rejection for throwing handlers, and no merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the SonarCloud S7503 fix in the global fetch stub.
Description check ✅ Passed The description explains the change, its rationale, the added test, and reported verification. It does not include the template checklist, but the key change and test status are documented.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
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
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Biome (2.5.13)
sdks/typescript/src/test-support/global-fetch-stub.test.ts

Biome could not lint this file: nested root configuration. Check the repository's Biome configuration and plugins.

sdks/typescript/src/test-support/global-fetch-stub.ts

Biome could not lint this file: nested root configuration. Check the repository's Biome configuration and plugins.


Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Oct 4, 2026

Copy link
Copy Markdown

@asafgolombek
asafgolombek merged commit abf218d into main Oct 4, 2026
28 checks passed
@asafgolombek
asafgolombek deleted the dev/asaf/sonar-fetch-stub-s7503 branch October 4, 2026 19:20
asafgolombek added a commit that referenced this pull request Oct 5, 2026
Sonar's S4634 flagged the executor #287 wrote to clear S7503: a
new Promise whose executor only calls resolve reads as a trivial
promise. The executor existed only so a throwing handler rejects
instead of throwing at the call. Promise.try does exactly that, calling
the handler at once and turning a throw into a rejection, with no
executor. Promise.resolve(handler(...)) would not: the throw escapes
the call, and the throwing-handler test fails with it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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