Skip to content

Commit d5a7e3b

Browse files
nohwndCopilot
andauthored
Fix VS insertion: JSON serialization and disable AutoComplete (#16042)
* Fix insertion: use Invoke-WebRequest for app.config to avoid XML auto-parse Invoke-RestMethod auto-parses XML responses into XmlDocument objects. When embedded in the push body and serialized with ConvertTo-Json -Depth 10, the DOM tree overflows the depth limit, producing truncated JSON that AzDO rejects with 'The body of the request contains invalid Json'. Switch to Invoke-WebRequest which returns the raw string content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix insertion: ensure string content and explicit UTF-8 encoding The previous fix removed the ConvertTo-Json depth overflow warning, but Invoke-WebRequest.Content returns byte[] in PS7 when the response lacks charset in content-type. ConvertTo-Json serializes byte[] as an integer array instead of a string, producing structurally valid but semantically wrong JSON that AzDO rejects. Fix: explicitly decode byte[] to UTF-8 string, send body as UTF-8 bytes with explicit content-type charset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Disable AutoComplete — WIF token cannot vote for others (TF401186) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a818e2f commit d5a7e3b

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

azure-pipelines-insertion.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variables:
2525
- name: CherryPick
2626
value: ''
2727
- name: AutoComplete
28-
value: 'true'
28+
value: 'false'
2929
- name: ComponentBranchName
3030
value: '${{ parameters.ComponentBranchName }}'
3131
- name: CreateDraftPR
@@ -137,9 +137,10 @@ extends:
137137
"--ci"
138138
)
139139
140-
if ("$(AutoComplete)" -eq "true") {
141-
$insertArgs += "--set-auto-complete"
142-
}
140+
# AutoComplete disabled — WIF token cannot vote on behalf of others (TF401186)
141+
# if ("$(AutoComplete)" -eq "true") {
142+
# $insertArgs += "--set-auto-complete"
143+
# }
143144
144145
if ("$(CreateDraftPR)" -eq "true") {
145146
$insertArgs += "--create-draft-pr"
@@ -254,7 +255,15 @@ extends:
254255
Write-Host "Fetching app.config from mirror repo at commit $sourceCommit"
255256
$encodedPath = [Uri]::EscapeDataString("/src/vstest.console/app.config")
256257
$itemUrl = "$dncengBase/_apis/git/repositories/$mirrorRepoId/items?path=$encodedPath&versionDescriptor.version=$sourceCommit&versionDescriptor.versionType=commit&api-version=7.1"
257-
$appConfigContent = Invoke-RestMethod -Uri $itemUrl -Headers $dncengHeaders -Method Get
258+
# Use Invoke-WebRequest and decode to string explicitly.
259+
# Invoke-RestMethod auto-parses XML into XmlDocument (depth overflow),
260+
# and Invoke-WebRequest.Content returns byte[] when charset is missing.
261+
$appConfigResponse = Invoke-WebRequest -Uri $itemUrl -Headers $dncengHeaders -Method Get -UseBasicParsing
262+
$appConfigContent = if ($appConfigResponse.Content -is [byte[]]) {
263+
[System.Text.Encoding]::UTF8.GetString($appConfigResponse.Content)
264+
} else {
265+
$appConfigResponse.Content
266+
}
258267
259268
# Read revision.txt from the VS target branch and bump the revision number.
260269
# revision.txt has two lines: an integer revision number and a GUID.
@@ -265,7 +274,12 @@ extends:
265274
$targetBranchName = ($targetBranch -replace '^refs/heads/', '')
266275
$encodedRevPath = [Uri]::EscapeDataString($revisionFilePath)
267276
$revisionUrl = "$devdivOrg/$project/_apis/git/repositories/$vsRepoId/items?path=$encodedRevPath&versionDescriptor.version=$targetBranchName&versionDescriptor.versionType=branch&api-version=7.1"
268-
$revisionContent = Invoke-RestMethod -Uri $revisionUrl -Headers $headers -Method Get
277+
$revResponse = Invoke-WebRequest -Uri $revisionUrl -Headers $headers -Method Get -UseBasicParsing
278+
$revisionContent = if ($revResponse.Content -is [byte[]]) {
279+
[System.Text.Encoding]::UTF8.GetString($revResponse.Content)
280+
} else {
281+
$revResponse.Content
282+
}
269283
$revisionLines = $revisionContent -split "`n"
270284
$currentRevision = [int]($revisionLines[0].Trim())
271285
$newRevision = $currentRevision + 1
@@ -311,7 +325,12 @@ extends:
311325
)
312326
} | ConvertTo-Json -Depth 10
313327
314-
$pushResponse = Invoke-RestMethod -Uri $pushUrl -Headers $headers -Method Post -Body $pushBody
328+
# Debug: show content types to diagnose serialization issues
329+
Write-Host "appConfigContent type: $($appConfigContent.GetType().FullName), length: $($appConfigContent.Length)"
330+
Write-Host "newRevisionContent type: $($newRevisionContent.GetType().FullName), length: $($newRevisionContent.Length)"
331+
Write-Host "pushBody length: $($pushBody.Length)"
332+
333+
$pushResponse = Invoke-RestMethod -Uri $pushUrl -Headers $headers -Method Post -Body ([System.Text.Encoding]::UTF8.GetBytes($pushBody)) -ContentType 'application/json; charset=utf-8'
315334
Write-Host "Pushed App.config and revision.txt to insertion branch. Commit: $($pushResponse.commits[0].commitId)"
316335
}
317336
catch {

0 commit comments

Comments
 (0)