[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's toArray() 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

Command icon 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:

Comments

marcus_johansson created an issue. See original summary.

marcus_johansson’s picture

Assigned: Unassigned » marcus_johansson

marcus_johansson’s picture

Assigned: marcus_johansson » Unassigned
Status: Active » Needs review
abhisekmazumdar’s picture

Assigned: Unassigned » abhisekmazumdar
abhisekmazumdar’s picture

Assigned: abhisekmazumdar » Unassigned
Status: Needs review » Reviewed & tested by the community

Thanks 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.

marcus_johansson’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +AI Initiative Sprint, +AI Product Development

Getting merged, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • marcus_johansson committed b1b76483 on 1.4.x
    Issue #3582585: Mock Provider request matching breaks when new keys are...

  • marcus_johansson committed 15abce45 on 2.0.x
    Issue #3582585: Mock Provider request matching breaks when new keys are...

  • marcus_johansson committed a25e7910 on cherry-pick-3483462-2.x
    Issue #3582585: Mock Provider request matching breaks when new keys are...
arianraeesi’s picture

Issue tags: -AI Product Development