Repository navigation
{Batch} Compare request bodies of Batch requests in playback tests - #34466
Conversation
Playback matched requests on method, host, path and query only (vcrpy's default in azure-cli-testsdk), so a command could send a different body and its test still passed. Add a vcrpy matcher, batch_body (batch_request_matcher.py), to the four Batch scenario test classes. For requests to *.batch.azure.com, or with /providers/Microsoft.Batch/ in the path, the JSON body must equal the recorded one. A subscription ID in /subscriptions/<id>/ matches any other, and durations match by value (PT0H20M = PT20M00S). Requests to other services and bodies that aren't JSON always match. On a difference, the vcrpy error lists the JSON paths that differ, with both values. The Azure SDKs' test proxy also compares request bodies by default. Fix two recordings by hand, where a command now sends a different body than when the test was recorded: - test_batch_pools_and_nodes: Azure#32397 removed --target-communication, but the recording's first POST /pools still sends "targetNodeCommunicationMode": "classic". Remove only that property. - test_batch_managed_identity_cmd: Azure#34452 stopped `az batch account identity assign` and `remove` from sending "properties": {"publicNetworkAccess": "Enabled"}. Remove it from the four recorded PATCH bodies. The Content-Length of each changed request is updated too. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thank you for your contribution Keyan Song (@mskeyansong)! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
🟡 Changes recommended
Subscription normalization skips resource-ID dictionary keys, causing otherwise identical Batch identity requests to mismatch when subscription IDs differ; key normalization must also preserve distinct entries on collisions.
1 open issue
What changed in this PR
This PR strengthens Azure CLI Batch playback tests by comparing JSON request bodies, helping catch serialization regressions such as lost duration components. Changes remain within Batch tests; the shared test SDK is unchanged.
Changes:
- Add a Batch-specific body matcher with duration equivalence, subscription-ID normalization, and field-level mismatch diagnostics.
- Register the matcher in all four Batch scenario test classes.
- Update two recordings to reflect deprecated pool-property removal and corrected identity-update requests.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_mgmt_commands.py |
Register the matcher in three management scenario classes. |
src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_data_plane_commands.py |
Register the matcher in data-plane scenarios. |
src/azure-cli/azure/cli/command_modules/batch/tests/latest/recordings/test_batch_pools_and_nodes.yaml |
Remove the deprecated communication-mode request property. |
src/azure-cli/azure/cli/command_modules/batch/tests/latest/recordings/test_batch_managed_identity_cmd.yaml |
Remove unintended public-network-access settings from identity requests. |
src/azure-cli/azure/cli/command_modules/batch/tests/latest/batch_request_matcher.py |
Implement Batch JSON body comparison and mismatch diagnostics. |
Review effort: Balanced
| for key in sorted(set(recorded) | set(now)): | ||
| yield from _differences(recorded.get(key, _MISSING), now.get(key, _MISSING), | ||
| f'{path}.{key}' if path else key) |
|
Hi Keyan Song (@mskeyansong), |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |

🤖 PR Validation — ️✔️ All clear
Related command
None (tests only).
Description
Playback matched requests on method, host, path and query only, so a command could send a different request body and
its test still passed. That's how a bug where
--max-wall-clock-timelost its years and months got through (fixed in#34450).
This adds a vcrpy matcher (
batch_request_matcher.py) to the four Batch scenario test classes. For Batch requests(
*.batch.azure.com, or/providers/Microsoft.Batch/in the path), the JSON body must match the recorded one. Asubscription ID in
/subscriptions/<id>/matches any other, and durations match by value (PT0H20M=PT20M00S).Requests to other services, and bodies that aren't JSON, always match. When a body differs, the error lists the JSON
paths that differ, with both values. The change stays in the Batch tests; the test SDK isn't changed. (The Azure SDKs'
test proxy compares request bodies by default, too.)
Two recordings are fixed by hand, where a command now sends a different body than when the test was recorded:
test_batch_pools_and_nodes: [Batch] BREAKING CHANGE: Remove deprecated properties #32397 removed--target-communication, but the recording's firstPOST /poolsstillsends
"targetNodeCommunicationMode": "classic".test_batch_managed_identity_cmd: [Batch]az batch account identity assign,az batch account identity remove: Fix public network access being turned on #34452 stoppedaz batch account identity assignandremovefrom sending"properties": {"publicNetworkAccess": "Enabled"}.Testing Guide
azdev test batch: 84 passed. Run ondevbefore #34450, the matcher failedtest_batch_jobs_and_tasksandtest_batch_pool_upgradePolicy_cmdon the lost years and months, as expected.azdev style batchandazdev linter --ci-exclusions --min-severity medium batchpass.History Notes
None:
{Batch}, tests only.This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.