[bug]: List Matching In JSON isn't Working Properly
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 18.5k
- Forks
- 2.4k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 101
Description
👀 Is there an existing issue for this?
- I have searched and didn't find similar issue
👍 Current behavior
- In the file
pkg/matcher/utils, the functionmatchJSONWithNoiseHandling(around line 801) processes slices by attempting to match every element of the expected array with every element of the actual array. - When a match is found, the corresponding element in the actual array is not excluded from further matching. This can lead to incorrect behavior.
- For example, when testing with a recorded JSON object for a GET request (with
ignore orderset to true):{ "Code": 200, "Balance": 100, "CreatedAt": "2025-03-17T06:00:57.303781054+02:00", "UpdatedAt": "2025-03-17T06:00:57.303781224+02:00", "RandNumber": { "Number": 1, "Note": "Random integer" }, "List": [1, 1, 1] } - and modifying the app code to send:
{ "Code": 200, "Balance": 100, "CreatedAt": "2025-03-17T06:00:57.303781054+02:00", "UpdatedAt": "2025-03-17T06:00:57.303781224+02:00", "RandNumber": { "Number": 1, "Note": "Random integer" }, "List": [1, 2, 3] } - the test unexpectedly passes when
ignore order is true. However, settingignore order to falsecauses the test to fail with an error stating that the objects are identical but not in the same order.
👟 Steps to Replicate
-
Navigate to the pkg/matcher/utils directory in the codebase.
-
Open the function matchJSONWithNoiseHandling and inspect the slice-handling code near line 888.
-
Create a test case using a recorded JSON object, for example:
{ "Code": 200, "Balance": 100, "CreatedAt": "2025-03-17T06:00:57.303781054+02:00", "UpdatedAt": "2025-03-17T06:00:57.303781224+02:00", "RandNumber": { "Number": 1, "Note": "Random integer" }, "List": [1, 1, 1] } -
Modify the application to respond with a slightly different array, for instance:
{ "Code": 200, "Balance": 100, "CreatedAt": "2025-03-17T06:00:57.303781054+02:00", "UpdatedAt": "2025-03-17T06:00:57.303781224+02:00", "RandNumber": { "Number": 1, "Note": "Random integer" }, "List": [1, 2, 3] } -
Run the test with
ignore orderenabled. Notice that the test passes despite the differences in theListfield. -
Change the setting to
ignore orderdisabled and run the test again. Observe that the test now fails with a message indicating that the objects are the same but are not in the same order. -
Verify that the root cause is that the function does not exclude matched elements from further comparisons during slice matching.
🧱 Your Environment
No response
💻 Operating system
Linux
🎲 Version
version: 2-dev
💻 Repository
keploy
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/matcher/utils at matchJSONWithNoiseHandling, especially the slice-handling code near the referenced lines. Reproduce the recorded JSON case with ignore order enabled, then compare behavior for [1, 1, 1] versus [1, 2, 3]. Done means unmatched array elements are handled correctly and the differing List values no longer pass when order is ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100