Skip to content

Conversation

@AlexSkrypnyk
Copy link
Member

@AlexSkrypnyk AlexSkrypnyk commented Jan 22, 2026

Summary by CodeRabbit

  • Tests
    • Added new Behat test scenarios for API server management.
    • New scenario validates that response queues can be cleared independently while preserving existing request records.
    • New scenario enables inspection and debugging of recorded API requests through enhanced testing utilities.
    • Testing infrastructure now provides improved visibility into API server state during test execution.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Two new Behat step definitions were added to ApiServerContext: apiHasNoResponses() clears the response queue via DELETE request, and debugApiRequests() retrieves and displays request information via GET request. Corresponding test scenarios were added to validate these behaviors.

Changes

Cohort / File(s) Summary
New API server admin step definitions
src/DrevOps/BehatPhpServer/ApiServerContext.php
Added apiHasNoResponses() to clear response queue and debugApiRequests() to retrieve and display logged requests, both communicating with API server admin endpoints.
Feature test scenarios
tests/behat/features/apiserver.feature
Added two scenarios: one testing response queue clearing without affecting request count, another testing request information retrieval and display.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: two new Behat step definitions for clearing responses and debugging API requests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.45%. Comparing base (abc12c2) to head (f873393).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/DrevOps/BehatPhpServer/ApiServerContext.php 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #59      +/-   ##
==========================================
+ Coverage   75.34%   75.45%   +0.10%     
==========================================
  Files           3        3              
  Lines         430      440      +10     
==========================================
+ Hits          324      332       +8     
- Misses        106      108       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/DrevOps/BehatPhpServer/ApiServerContext.php`:
- Around line 157-168: The debugApiRequests method currently assumes the
response body is valid JSON; change debugApiRequests to validate the json_decode
result (call json_decode($body, TRUE) into a variable, then check
json_last_error() or that the result is not null) and when decoding fails write
a clear message and the raw response body to STDOUT instead of encoding
null—update references to $response->getBody(), the json_decode call, and the
$message construction so invalid JSON is reported gracefully while valid JSON
continues to be pretty-printed.

Comment on lines +157 to +168
public function debugApiRequests(): void {
$response = $this->client->request('GET', '/admin/requests');

if ($response->getStatusCode() !== 200) {
throw new \RuntimeException('Failed to fetch the API requests.');
}

$body = (string) $response->getBody();

$message = json_encode(json_decode($body, TRUE), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
fwrite(STDOUT, "\nAPI Requests Debug Info:\n" . $message . "\n");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle invalid JSON gracefully in debug output.

If the response body is not valid JSON, json_decode($body, TRUE) returns null, and json_encode(null, ...) will output the string "null", which could be confusing during debugging.

Proposed fix
   public function debugApiRequests(): void {
     $response = $this->client->request('GET', '/admin/requests');

     if ($response->getStatusCode() !== 200) {
       throw new \RuntimeException('Failed to fetch the API requests.');
     }

     $body = (string) $response->getBody();

-    $message = json_encode(json_decode($body, TRUE), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+    $decoded = json_decode($body, TRUE);
+    $message = $decoded !== null
+      ? json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
+      : $body;
     fwrite(STDOUT, "\nAPI Requests Debug Info:\n" . $message . "\n");
   }
🧰 Tools
🪛 PHPMD (2.15.0)

161-161: Missing class import via use statement (line '161', column '17'). (undefined)

(MissingImport)

🤖 Prompt for AI Agents
In `@src/DrevOps/BehatPhpServer/ApiServerContext.php` around lines 157 - 168, The
debugApiRequests method currently assumes the response body is valid JSON;
change debugApiRequests to validate the json_decode result (call
json_decode($body, TRUE) into a variable, then check json_last_error() or that
the result is not null) and when decoding fails write a clear message and the
raw response body to STDOUT instead of encoding null—update references to
$response->getBody(), the json_decode call, and the $message construction so
invalid JSON is reported gracefully while valid JSON continues to be
pretty-printed.

@AlexSkrypnyk AlexSkrypnyk merged commit ad40dd9 into main Jan 22, 2026
20 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/add-2-steps branch January 22, 2026 08:38
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.

2 participants