You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR resolves a bug where optional, unspecified parameters were being sent as null in the JSON payload for network modification commands (network.continueRequest, network.continueResponse, network.provideResponse).
This was causing errors, particularly with the Firefox BiDi implementation, which expects optional fields to be nil.
The fix uses the Ruby method .compact to remove any key-value pairs with a nil value from the command arguments hash before serialization.
🔧 Implementation Notes
The core of the issue was that parameters like cookies, headers, or body, when left unprovided by the user, defaulted to nil.
When constructing the command hash (e.g., in #continue_request), these nil values were present, and upon JSON serialization, they became JSON null values.
We called .compact on the hash arguments to remove nil values:
✅ Fix incorrect test assertion orderSuggestion Impact:The commit re-ordered the test steps so that the network.* method is called before the have_received expectation in multiple tests, matching the suggested fix.
code diff:
it 'sends only the mandatory request ID when all optional args are nil' do
expected_payload = {request: request_id}
+ network.continue_request(id: request_id)+
expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)
-- network.continue_request(id: request_id)
end
it 'sends only provided optional args' do
@@ -47,8 +47,6 @@
method: 'POST'
}
- expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)-
network.continue_request(
id: request_id,
body: {type: 'string', value: 'new body'},
@@ -56,6 +54,8 @@
headers: nil,
method: 'POST'
)
++ expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)
end
end
@@ -63,9 +63,9 @@
it 'sends only the mandatory request ID when all optional args are nil' do
expected_payload = {request: request_id}
+ network.continue_response(id: request_id)+
expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)
-- network.continue_response(id: request_id)
end
it 'sends only provided optional args' do
@@ -76,8 +76,6 @@
statusCode: 202
}
- expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)-
network.continue_response(
id: request_id,
cookies: nil,
@@ -86,6 +84,8 @@
reason: nil,
status: 202
)
++ expect(mock_bidi).to have_received(:send_cmd).with('network.continueResponse', expected_payload)
end
end
@@ -93,9 +93,9 @@
it 'sends only the mandatory request ID when all optional args are nil' do
expected_payload = {request: request_id}
+ network.provide_response(id: request_id)+
expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)
-- network.provide_response(id: request_id)
end
it 'sends only provided optional args' do
@@ -105,8 +105,6 @@
reasonPhrase: 'OK-Custom'
}
- expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)-
network.provide_response(
id: request_id,
body: {type: 'string', value: 'Hello'},
@@ -115,6 +113,8 @@
reason: 'OK-Custom',
status: nil
)
++ expect(mock_bidi).to have_received(:send_cmd).with('network.provideResponse', expected_payload)
end
In the RSpec tests, move the action (e.g., network.continue_request) before the expect(...).to have_received(...) assertion to correctly verify the behavior.
it 'sends only the mandatory request ID when all optional args are nil' do
expected_payload = {request: request_id}
+ network.continue_request(id: request_id)+
expect(mock_bidi).to have_received(:send_cmd).with('network.continueRequest', expected_payload)
-- network.continue_request(id: request_id)
end
[Suggestion processed]
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a critical flaw in the test implementation where the assertion precedes the action, rendering all new tests ineffective at verifying the intended behavior.
well, I don't think that's what I wanted to do. It doesn't want me to push from command line, so I tried to edit on Github, don't think it did what I wanted it to do...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💥 What does this PR do?
This PR resolves a bug where optional, unspecified parameters were being sent as
nullin the JSON payload for network modification commands (network.continueRequest,network.continueResponse,network.provideResponse).This was causing errors, particularly with the Firefox BiDi implementation, which expects optional fields to be nil.
The fix uses the Ruby method
.compactto remove any key-value pairs with anilvalue from the command arguments hash before serialization.🔧 Implementation Notes
The core of the issue was that parameters like
cookies,headers, orbody, when left unprovided by the user, defaulted tonil.When constructing the command hash (e.g., in
#continue_request), thesenilvalues were present, and upon JSON serialization, they became JSONnullvalues.We called
.compacton the hash arguments to remove nil values:🔄 Types of changes