Skip to content

Tolerate NuGet credential-provider stdout preamble in package search parsing - #19343

Merged
David Pine (IEvangelist) merged 3 commits into
mainfrom
dapine/fix-nuget-package-search-json
Aug 17, 2026
Merged

David Pine (IEvangelist) merged 3 commits into
mainfrom
dapine/fix-nuget-package-search-json

Conversation

@IEvangelist

Copy link
Copy Markdown
Member

Description

dotnet package search <id> --format json is parsed as if its entire stdout were a single JSON document. When an authenticated Azure DevOps / Azure Artifacts feed is configured, the NuGet Azure Artifacts Credential Provider writes [CredentialProvider]… progress lines to stdout before the JSON payload while the command still exits 0. Parsing the whole stdout then throws:

System.Text.Json.JsonReaderException: 'C' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 5.

Example polluted stdout (JSON begins after the preamble; stderr empty; exit code 0):

    [CredentialProvider]VstsCredentialProvider - Acquired bearer token using 'MSAL Silent'
    [CredentialProvider]Requested 8/13/2026 2:36:13 AM but received 8/12/2026 11:37:51 PM
    {"version":2,"problems":[],"searchResult":[{"sourceName":"azure-default","packages":[ … ]}]}

Impact: the background version check is silently broken (a JsonReaderException is logged every aspire run and no upgrade prompts appear), and CLI package operations (aspire add) can report "no packages found" — affecting essentially every developer with an authenticated Azure DevOps feed.

Fix: add a small, well-documented shared helper PackageUpdateHelpers.ExtractJsonPayload that skips the non-JSON preamble by starting at the first {, and apply it everywhere dotnet package search (and the bundle aspire-managed search) stdout is parsed:

  1. Version check — PackageFetcher.TryFetchPackagesAsync → ParsePackageSearchResults.
  2. CLI package search — DotNetCliRunner.SearchPackagesAsync, both the live parse and the disk-cache read → ParsePackageSearchResults.
  3. Bundle path (defense-in-depth) — BundleNuGetPackageCache deserializes the aspire-managed helper stdout directly.

Clean JSON (no preamble) and genuinely empty/malformed output (no {) are returned unchanged, so existing JsonException handling is preserved. This matches the direction validated by the issue author ("Isolating from the first { parses the captured output cleanly").

Fixes #19339

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19343

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19343"

@github-actions

This comment has been minimized.

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.

Pull request overview

Centralizes tolerance for NuGet credential-provider stdout preambles so package searches continue parsing valid JSON.

Changes:

  • Extracts JSON beginning at the first object token.
  • Applies extraction to standard and bundled package searches.
  • Adds regression coverage for both paths.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Shared/PackageUpdateHelpers.cs Adds shared JSON payload extraction.
src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs Handles preambles in bundled searches.
tests/Aspire.Hosting.Tests/VersionChecking/PackageUpdateHelpersTests.cs Tests standard search parsing.
tests/Aspire.Cli.Tests/NuGet/BundleNuGetPackageCacheTests.cs Tests bundled search parsing.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@IEvangelist
David Pine (IEvangelist) enabled auto-merge (squash) August 13, 2026 14:46
@IEvangelist

Copy link
Copy Markdown
Member Author

PR Testing Report

PR Information

Artifact Version Verification

  • Expected Commit: 3e63fc27548463324e383aa0fc4cf9fc3c4d9bfc
  • Installed Version: 13.6.0-pr.19343.g3e63fc27
  • Status: PASS - the installed artifact contains the PR head short SHA 3e63fc27.

Changes Analyzed

Files Changed

  • src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs - trims non-JSON stdout preamble before deserializing bundled package-search results.
  • src/Shared/PackageUpdateHelpers.cs - centralizes JSON payload extraction for AppHost version checking and non-bundled CLI package search.
  • tests/Aspire.Cli.Tests/NuGet/BundleNuGetPackageCacheTests.cs - adds bundled-helper credential-provider preamble coverage.
  • tests/Aspire.Hosting.Tests/VersionChecking/PackageUpdateHelpersTests.cs - adds shared-parser credential-provider preamble coverage.

Change Categories

  • CLI changes detected
  • AppHost version-check parsing changes detected
  • Hosting integration changes
  • Dashboard changes
  • Template changes
  • Client/component changes
  • VS Code extension changes
  • CI infrastructure changes
  • Test changes detected

Test Scenarios Executed

Scenario 1: PR artifact identity

Objective: Verify the tested CLI artifact was built from the latest PR commit.

Coverage Type: Artifact verification

Status: PASS

Steps:

  1. Installed PR Tolerate NuGet credential-provider stdout preamble in package search parsing #19343 with the official dogfood PowerShell installer into an isolated temp directory.
  2. Ran the installed binary directly with --version.
  3. Compared the reported short SHA with the PR head.

Evidence:

  • install-output.txt
  • version.txt
  • source-checkout.txt

Observations:

  • The installer selected workflow run 31709287396.
  • Installed CLI version 13.6.0-pr.19343.g3e63fc27 matches PR head 3e63fc27548463324e383aa0fc4cf9fc3c4d9bfc.

Scenario 2: Focused parser regression tests

Objective: Validate both changed parsing paths against credential-provider preamble output and existing clean/empty payload behavior.

Coverage Type: Happy path and boundary regression

Status: PASS

Steps:

  1. Checked out the exact PR head in an isolated worktree.
  2. Ran restore.cmd.
  3. Ran BundleNuGetPackageCacheTests with quarantined and outerloop tests excluded.
  4. Ran PackageUpdateHelpersTests with quarantined and outerloop tests excluded.

Evidence:

  • restore-output.txt
  • bundle-cache-tests.txt
  • package-update-helper-tests.txt

Observations:

  • BundleNuGetPackageCacheTests: 3 passed, 0 failed.
  • PackageUpdateHelpersTests: 6 passed, 0 failed.
  • The new tests use the observed [CredentialProvider] preamble shape and validate both bundled CLI and shared AppHost parsing.
  • Existing pure-JSON, empty-result, filtering, and version-selection behavior remained green.

Scenario 3: Installed CLI package-search and add flow

Objective: Exercise the changed bundled package-search parser through a real aspire add operation.

Coverage Type: User-facing happy path

Status: PASS

Steps:

  1. Created a fresh C# aspire-empty project from the PR package hive.
  2. Ran aspire add redis using the installed PR CLI, explicit AppHost path, and PR hive source.
  3. Verified [email protected] was added to apphost.cs.
  4. Built the generated file-based AppHost.

Evidence:

  • scenario-cli-add/new-output.txt
  • scenario-cli-add/add-redis-output.txt
  • scenario-cli-add/build-output.txt
  • scenario-cli-add/Pr19343Smoke/apphost.cs

Observations:

  • Debug output confirms repeated package discovery through BundleNuGetPackageCache and aspire-managed.
  • Redis was added successfully at the PR version.
  • The AppHost build succeeded.
  • The environment could not reach nuget.org for vulnerability/search metadata, producing NU1900/search warnings, but the PR hive resolved the required packages and the scenario completed successfully.

Scenario 4: AppHost version-check runtime path

Objective: Verify the shared parser works during a real AppHost version check and does not emit JSON parsing failures.

Coverage Type: Runtime happy path and safe shutdown

Status: PASS

Steps:

  1. Started the generated AppHost detached with the installed PR CLI.
  2. Verified the dashboard resource was running and healthy.
  3. Inspected the detached AppHost log after the version check completed.
  4. Stopped the AppHost through aspire stop and confirmed the process exited.

Evidence:

  • scenario-cli-add/start-output.txt
  • scenario-cli-add/runtime-summary.txt
  • scenario-cli-add/stop-output.txt
  • logs/cli_20260813T150614927_detach-child_b6c6aed327da4d499dfe5df20835ffe4.log

Observations:

  • PackageFetcher executed dotnet package search Aspire.Hosting.AppHost --format json --prerelease --take 1000.
  • The parser found one Aspire.Hosting.AppHost package and reported no newer version.
  • Parse-failure count was 0 for JsonReaderException, JsonException, Failed to read JSON, and Failed to parse search results.
  • The dashboard resource was healthy, and the AppHost stopped successfully.

Scenario 5: Live stdout shape probe

Objective: Determine whether this host reproduces credential-provider stdout pollution outside the synthetic fixtures.

Coverage Type: Environment-specific boundary probe

Status: PASS with limitation

Steps:

  1. Ran dotnet package search Aspire.Hosting.AppHost --format json --prerelease --take 5 in the exact PR source checkout.
  2. Captured stdout and stderr separately.
  3. Inspected stdout for credential-provider lines and the first JSON object offset.

Evidence:

  • live-package-search-stdout.txt
  • live-package-search-stderr.txt
  • live-package-search-summary.txt

Observations:

  • Exit code was 0.
  • Stdout began with { at offset 0 and contained no [CredentialProvider] preamble.
  • Stderr was empty.
  • This host therefore did not reproduce the authenticated Azure Artifacts credential-provider preamble live. The exact polluted-output shape remains covered by both focused PR fixtures.

Summary

Scenario Status Notes
PR artifact identity PASS Installed version matches PR head
Focused parser regression tests PASS 9 passed, 0 failed
Installed CLI package-search/add PASS Redis added at PR version; AppHost built
AppHost version-check runtime PASS Package found; zero parse failures; clean stop
Live stdout shape probe PASS with limitation Host emitted clean JSON; fixture covered polluted stdout

Overall Result

PR VERIFIED

The latest PR artifact and exact source commit passed all planned scenarios. Both affected parser paths accept the credential-provider preamble fixture while preserving clean and empty-result behavior. Real installed-CLI package discovery, aspire add, AppHost build/start, version checking, dashboard health, and shutdown all succeeded.

Recommendations

  • No blocking issues found.
  • A live authenticated Azure Artifacts feed reproduction was not available on this host; the PR's focused fixtures provide direct coverage of the reported 616-character preamble shape.

@adamint Adam Ratzman (adamint) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two parser edge cases still reproduce the original package-search failure: provider output can contain a { before the payload, and provider stdout can trail the payload. I left both inline. The intended preamble path and clean JSON path work, the focused tests pass, and a process-level CLI shim verified the real command path. Holding approval because auto-merge is enabled and I think these should be fixed first.

David Pine and others added 2 commits August 14, 2026 07:29
…parsing

dotnet package search --format json can emit non-JSON [CredentialProvider] progress lines to stdout before the JSON payload (exit code still 0) when an authenticated Azure DevOps / Azure Artifacts feed is configured. Parsing the whole stdout as JSON then throws a JsonReaderException, silently breaking the background version check (stack logged every run) and causing aspire add / integration search to report no packages.

Add a shared PackageUpdateHelpers.ExtractJsonPayload helper that skips the preamble by starting at the first brace, and use it in ParsePackageSearchResults (version check + CLI live/disk-cache search paths) and BundleNuGetPackageCache (aspire-managed bundle search path). Clean JSON and genuinely empty/malformed output are unchanged.

Fixes #19339

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 8e466090-81d0-4e48-8423-daf6eea6fdc3
Scan complete JSON object candidates, validate the expected package-search shape, and return only the consumed value so diagnostic JSON before the result and provider output after it cannot corrupt parsing.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 8e466090-81d0-4e48-8423-daf6eea6fdc3
Copilot AI review requested due to automatic review settings August 14, 2026 12:35
@IEvangelist
David Pine (IEvangelist) force-pushed the dapine/fix-nuget-package-search-json branch from 3e63fc2 to bdcb171 Compare August 14, 2026 12:35
@github-actions

This comment has been minimized.

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Cover empty results, UTF-8 diagnostics, incomplete root-level near matches, and missing payloads. Let each caller validate its concrete JSON contract so incomplete diagnostic objects are skipped before parsing.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 8e466090-81d0-4e48-8423-daf6eea6fdc3
Copilot AI review requested due to automatic review settings August 14, 2026 13:52
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector (audit mode)

The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement.

50 / 100 test projects · 5 jobs, from 4 changed files.

Selected test projects (50 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.GitHub.Models.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests

Selected jobs (5)

cli-starter, deployment-e2e, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 43 of the 50 selected test projects come from a single change — src/Shared/PackageUpdateHelpers.cs.

🔧 src/Shared/PackageUpdateHelpers.cs (changed source)
→ 43 via the project graph

show 43

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Browsers.Tests (2 hops), Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests (2 hops), Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.Docker.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.GitHub.Models.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.JavaScript.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Kubernetes.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.OpenAI.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Testing.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Hosting.Yarp.Tests (2 hops), Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Tests/VersionChecking/PackageUpdateHelpersTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/NuGet/BundleNuGetPackageCacheTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter • affected project Aspire.Cli
• selected test Aspire.Cli.Tests
deployment-e2e affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs, tests/Aspire.Cli.Tests/NuGet/BundleNuGetPackageCacheTests.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit 6fdb7f5.

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@adamint Adam Ratzman (adamint) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The parser changes look good. I verified the two earlier concerns are addressed: it scans complete JSON values instead of trusting the first brace, and it returns only the consumed payload when provider output follows the JSON. The focused CLI/Hosting tests passed, along with a direct 20-case parser harness covering glued preambles, suffixes, malformed input, UTF-8 offsets and both payload schemas.

@IEvangelist
David Pine (IEvangelist) merged commit 656041b into main Aug 17, 2026
724 of 727 checks passed
@IEvangelist
David Pine (IEvangelist) deleted the dapine/fix-nuget-package-search-json branch August 17, 2026 18:50
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.6 milestone Aug 17, 2026
@aspire-repo-bot

This comment has been minimized.

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Step 5 branch taken: docs_required → false positive (no concrete documentation edit exists).

Triggered signals (1): pr_body_has_cli_flag_mention — evidence: PR body text "package search (id) --format json` is parsed as if its entire stdout were a single JSON".

Why this is a false positive: --format json is an existing dotnet package search (upstream .NET CLI) flag mentioned only as context for describing how NuGet Azure Artifacts Credential Provider output pollutes stdout. The PR itself does not add, rename, or change any Aspire CLI command, option, or flag — it adds an internal shared helper (PackageUpdateHelpers.ExtractJsonPayload) that strips a non-JSON preamble before parsing dotnet package search output in the background version-check and package-search code paths, plus matching unit tests. There is no new or changed user-facing behavior, output shape, default, or surface area for Aspire users to read about; it purely fixes a silent JsonReaderException that was breaking JSON parsing when an authenticated feed emits credential-provider progress lines. No documentation change is warranted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version check and aspire add fail when NuGet credential-provider output pollutes dotnet package search --format json stdout (JsonReaderException)

3 participants