[Tracker]
Update Summary: [One-line status update for stakeholders]
Short Description: Mock provider request matching breaks when new keys are added to input toArray()
Check-in Date: MM/DD/YYYY
[/Tracker]
Problem/Motivation
Needed for #3546954: Normalize file api's to allow providers to use them.
The EchoProvider's getMatchingRequest() method in ai_test compares the current request against stored YAML fixtures using strict JSON equality (Json::encode($request['request']) === Json::encode($array), line 406 of EchoProvider.php). When a new key with a default value is added to an input type's toArray() (e.g. remote_files added to ChatInput), all existing YAML test fixtures break because they do not contain the new key - even though the default value is functionally irrelevant.
This means every time a new property with a default value is added to any input type, all existing test YAML files for that operation type must be manually updated. This is fragile and creates unnecessary churn.
Proposed resolution
- Change the comparison in
EchoProvider::getMatchingRequest()so that it automatically fills in default values for keys that are present in the current input'stoArray()but missing from the stored YAML request, before comparing. - This way existing YAML fixtures continue to work even after new keys with default values are added to input types.
- One approach: iterate the keys of
$array(the current input) and for any key missing in$request['request'], add the default value from the input before comparison. Alternatively, only compare the keys that exist in the YAML fixture (subset matching) rather than requiring exact equality.
AI usage (if applicable)
[x] AI Assisted Issue
This issue was generated with AI assistance, but was reviewed and refined by the creator.
[ ] AI Assisted Code
[ ] AI Generated Code
[ ] Vibe Coded
- This issue was created with the help of AI
Issue fork ai-3582585
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- mock-provider-1.x
changes, plain diff MR !1389
- 3582585-mock-provider-request
changes, plain diff MR !1388
Comments
Comment #2
marcus_johansson commentedComment #6
marcus_johansson commentedComment #7
abhisekmazumdarComment #8
abhisekmazumdarThanks for the MR. This is needed to keep the test working as #3546954: Normalize file api's to allow providers to use them adds new keys to message objects.
I've pushed a small cleanup to the branch please review them. Rest I mark it RTBC.
Comment #9
marcus_johansson commentedGetting merged, thanks!
Comment #16
arianraeesi commented