Skip to content

Increase MCPServer coverage - #227

Merged
fernandotonon merged 1 commit into
masterfrom
codex/coverage-push-6
Mar 27, 2026
Merged

Increase MCPServer coverage#227
fernandotonon merged 1 commit into
masterfrom
codex/coverage-push-6

Conversation

@fernandotonon

@fernandotonon fernandotonon commented Mar 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • expand MCPServer protocol coverage for ping, notifications, resource edge cases, and transport parsing
  • add HTTP coverage for query-string tool routes, busy-server handling, and partial request bodies
  • harden no-response assertions with non-blocking pipe reads to avoid test hangs

Testing

  • local configure currently blocked by external dependency/bootstrap time in this worktree
  • focused MCPServer validation still needs a full UnitTests build in CI

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for HTTP endpoint behavior including query string handling, busy server responses, and partial body streaming.
    • Enhanced MCP protocol testing for ping/notification handling, resource reading, and message buffering.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR adds comprehensive test coverage to MCPServer_test.cpp, introducing a non-blocking socket read helper and expanding test cases for HTTP endpoints (query string handling, busy responses, partial body streaming) and MCP protocol operations (ping/notifications, resource handling, transport buffering, serialization).

Changes

Cohort / File(s) Summary
Non-blocking read helper
src/MCPServer_test.cpp
Added readTransportMessageNonBlocking(int readFd) utility function that temporarily sets O_NONBLOCK via fcntl, performs a single non-blocking read() up to 4096 bytes, and restores original flags; returns empty array on fcntl failures.
HTTP endpoint test coverage
src/MCPServer_test.cpp
Added GetToolCallWithQueryStringStripsSuffix (verifies GET /api/tools/<tool>?... returns HTTP 200 with JSON), BusyToolRequestReturns503 (asserts HTTP 503 when server busy), and PartialPostBodyWaitsForCompletionBeforeResponding (validates streaming POST body buffering until full Content-Length received).
MCP protocol & transport test coverage
src/MCPServer_test.cpp
Added tests for: ping message responses, initialized and cancelled notifications (no output), unknown resource URIs, onReadyRead() buffering behavior with complete Content-Length payloads, invalid Content-Length handling, and protocol serialization for sendNotification and sendError methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Tests multiply like carrots in spring,
Each assert a hop, each ping a ring!
Non-blocking reads and buffers so keen,
Protocol protocols, properly seen! 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers the main technical areas (protocol coverage, HTTP coverage, test hardening) but does not follow the provided template structure with required sections like Features, Bugfixes, or proper formatting. Reformat the description to follow the template with clear 'Summary', 'Technical Details', 'Features', and 'Bugfixes' sections as specified in the repository guidelines.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Increase MCPServer coverage' directly and clearly summarizes the main change—expanding test coverage for the MCPServer component.

✏️ 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 codex/coverage-push-6

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 and usage tips.

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/MCPServer_test.cpp`:
- Around line 52-72: The helper readTransportMessageNonBlocking uses POSIX fcntl
and must be made platform-safe: wrap the current implementation in a `#ifndef`
_WIN32 guard and add a Windows branch that sets non-blocking mode via
ioctlsocket/FIONBIO (or returns an empty QByteArray and lets tests skip on
Windows); ensure you restore the original blocking state (fcntl on POSIX,
ioctlsocket on Windows) and reference readTransportMessageNonBlocking in any
test skip logic so Windows CI either uses the ioctlsocket-based path or the
tests that call readTransportMessageNonBlocking are skipped.
- Around line 14-15: The code includes the POSIX header <fcntl.h> and uses
fcntl() in readTransportMessageNonBlocking which will fail to compile on
Windows; wrap the `#include` <fcntl.h> and the POSIX-specific implementation of
readTransportMessageNonBlocking with a platform guard (e.g. `#ifndef` _WIN32 /
`#else` / `#endif`), and provide a Windows-specific alternative implementation or
stub that uses the appropriate Windows non-blocking APIs (e.g. ioctlsocket/WSA*
for sockets) or returns a clear unsupported/error path; modify the function
(readTransportMessageNonBlocking) and any uses of fcntl to be conditionally
compiled so the build succeeds on both POSIX and Windows.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: b40ab870-f7a0-4ffd-b416-6d4b0782415f

📥 Commits

Reviewing files that changed from the base of the PR and between 36d40f4 and b3ff45f.

📒 Files selected for processing (1)
  • src/MCPServer_test.cpp

Comment thread src/MCPServer_test.cpp
Comment on lines 14 to +15
#include <unistd.h>
#include <fcntl.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Platform compatibility: fcntl.h is POSIX-only and will not compile on Windows.

The include and the readTransportMessageNonBlocking function below use POSIX fcntl() which is unavailable on Windows. As per coding guidelines, platform-specific APIs must be guarded.

🛠️ Proposed fix with platform guard
 `#include` <unistd.h>
+#ifndef Q_OS_WIN
 `#include` <fcntl.h>
+#endif
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#include <unistd.h>
#include <fcntl.h>
`#include` <unistd.h>
`#ifndef` Q_OS_WIN
`#include` <fcntl.h>
`#endif`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/MCPServer_test.cpp` around lines 14 - 15, The code includes the POSIX
header <fcntl.h> and uses fcntl() in readTransportMessageNonBlocking which will
fail to compile on Windows; wrap the `#include` <fcntl.h> and the POSIX-specific
implementation of readTransportMessageNonBlocking with a platform guard (e.g.
`#ifndef` _WIN32 / `#else` / `#endif`), and provide a Windows-specific alternative
implementation or stub that uses the appropriate Windows non-blocking APIs (e.g.
ioctlsocket/WSA* for sockets) or returns a clear unsupported/error path; modify
the function (readTransportMessageNonBlocking) and any uses of fcntl to be
conditionally compiled so the build succeeds on both POSIX and Windows.

Comment thread src/MCPServer_test.cpp
Comment on lines +52 to +72
static QByteArray readTransportMessageNonBlocking(int readFd)
{
const int flags = fcntl(readFd, F_GETFL, 0);
if (flags == -1) {
return {};
}

if (fcntl(readFd, F_SETFL, flags | O_NONBLOCK) == -1) {
return {};
}

QByteArray response;
char buffer[4096];
ssize_t bytesRead = read(readFd, buffer, sizeof(buffer));
if (bytesRead > 0) {
response.append(buffer, bytesRead);
}

fcntl(readFd, F_SETFL, flags);
return response;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Platform compatibility: fcntl() is POSIX-only.

This function uses POSIX fcntl() which is unavailable on Windows. Guard the implementation or provide a Windows alternative.

🛠️ Proposed fix with platform guard
 static QByteArray readTransportMessageNonBlocking(int readFd)
 {
+#ifdef Q_OS_WIN
+    // fcntl not available on Windows; return empty to indicate no data
+    Q_UNUSED(readFd);
+    return {};
+#else
     const int flags = fcntl(readFd, F_GETFL, 0);
     if (flags == -1) {
         return {};
     }

     if (fcntl(readFd, F_SETFL, flags | O_NONBLOCK) == -1) {
         return {};
     }

     QByteArray response;
     char buffer[4096];
     ssize_t bytesRead = read(readFd, buffer, sizeof(buffer));
     if (bytesRead > 0) {
         response.append(buffer, bytesRead);
     }

     fcntl(readFd, F_SETFL, flags);
     return response;
+#endif
 }

Note: Tests relying on this helper will need to be skipped on Windows or the Windows implementation enhanced using ioctlsocket() with FIONBIO.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static QByteArray readTransportMessageNonBlocking(int readFd)
{
const int flags = fcntl(readFd, F_GETFL, 0);
if (flags == -1) {
return {};
}
if (fcntl(readFd, F_SETFL, flags | O_NONBLOCK) == -1) {
return {};
}
QByteArray response;
char buffer[4096];
ssize_t bytesRead = read(readFd, buffer, sizeof(buffer));
if (bytesRead > 0) {
response.append(buffer, bytesRead);
}
fcntl(readFd, F_SETFL, flags);
return response;
}
static QByteArray readTransportMessageNonBlocking(int readFd)
{
`#ifdef` Q_OS_WIN
// fcntl not available on Windows; return empty to indicate no data
Q_UNUSED(readFd);
return {};
`#else`
const int flags = fcntl(readFd, F_GETFL, 0);
if (flags == -1) {
return {};
}
if (fcntl(readFd, F_SETFL, flags | O_NONBLOCK) == -1) {
return {};
}
QByteArray response;
char buffer[4096];
ssize_t bytesRead = read(readFd, buffer, sizeof(buffer));
if (bytesRead > 0) {
response.append(buffer, bytesRead);
}
fcntl(readFd, F_SETFL, flags);
return response;
`#endif`
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/MCPServer_test.cpp` around lines 52 - 72, The helper
readTransportMessageNonBlocking uses POSIX fcntl and must be made platform-safe:
wrap the current implementation in a `#ifndef` _WIN32 guard and add a Windows
branch that sets non-blocking mode via ioctlsocket/FIONBIO (or returns an empty
QByteArray and lets tests skip on Windows); ensure you restore the original
blocking state (fcntl on POSIX, ioctlsocket on Windows) and reference
readTransportMessageNonBlocking in any test skip logic so Windows CI either uses
the ioctlsocket-based path or the tests that call
readTransportMessageNonBlocking are skipped.

@sonarqubecloud

Copy link
Copy Markdown

@fernandotonon
fernandotonon merged commit b2de341 into master Mar 27, 2026
18 checks passed
@fernandotonon
fernandotonon deleted the codex/coverage-push-6 branch March 27, 2026 16:55
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