Skip to content

{Batch} Compare request bodies of Batch requests in playback tests - #34466

Merged
xuming-ms merged 1 commit into
Azure:devfrom
mskeyansong:keyan/batch-test-request-bodies
Nov 20, 2026
Merged

xuming-ms merged 1 commit into
Azure:devfrom
mskeyansong:keyan/batch-test-request-bodies

Conversation

@mskeyansong

@mskeyansong Keyan Song (mskeyansong) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

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-time lost 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. 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. 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:

Testing Guide
azdev test batch: 84 passed. Run on dev before #34450, the matcher failed test_batch_jobs_and_tasks and
test_batch_pool_upgradePolicy_cmd on the lost years and months, as expected. azdev style batch and
azdev linter --ci-exclusions --min-severity medium batch pass.

History Notes
None: {Batch}, tests only.


This checklist is used to make sure that common guidelines for a pull request are followed.

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>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 15:38
@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 19, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Keyan Song (@mskeyansong)! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +61 to +63
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)
@x-engineering-agent

Copy link
Copy Markdown
Contributor

Hi Keyan Song (@mskeyansong),
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@xuming-ms

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@xuming-ms
xuming-ms merged commit 916a231 into Azure:dev Nov 20, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Batch az batch customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants