Auto-promote scalar JSON values for arg-bearing CLI options (fixes #8830)#8836
Merged
Evangelink merged 2 commits intoJun 5, 2026
Merged
Conversation
…crosoft#8830) testconfig.json bare scalars like "results-directory": "TestResults" were read by JsonConfigurationProvider as presence markers (via bool.TryParse) for options whose schema requires an argument. For an arg-bearing option `"timeout": "true"` ended up enabling the option with zero args instead of passing `"true"` as the first argument value. Normalize `_singleValueData` at startup using the registered option registry: when an option has `Arity.Min >= 1`, rewrite the bare scalar key `commandLineOptions:<name>` into the indexed form `commandLineOptions:<name>:0` so the value is consistently surfaced as the first argument by both `EnumerateCommandLineOptions` and `TryGetCommandLineOptionFromProviders`. Optional-arg options (`Min=0, Max>=1`) remain ambiguous by design and are left untouched (workaround: use the array form `["true"]`). Zero-arity and unknown options are also left as-is. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a long-standing ambiguity in testconfig.json parsing where scalar JSON values for arg-bearing CLI options (e.g., "timeout": "true") could be misinterpreted as a presence marker instead of being treated as the first argument. It does so by normalizing JSON scalar entries into the canonical indexed configuration shape (commandLineOptions:<name>:0) once the option registry is available.
Changes:
- Added JSON-scalar normalization logic in
JsonConfigurationProviderand surfaced it viaAggregatedConfiguration.NormalizeJsonCommandLineOptionScalars. - Wired normalization into
TestHostBuilderso it runs before JSON options are enumerated/validated. - Added unit tests covering scalar promotion behavior, case-insensitive lookup, and no-op behavior when no JSON provider is present.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/JsonCommandLineOptionsTests.cs | Adds coverage for scalar-to-indexed normalization across arity and casing scenarios. |
| src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.CommonServices.cs | Builds an option-name lookup and invokes JSON normalization before enumerating JSON CLI options. |
| src/Platform/Microsoft.Testing.Platform/Configurations/JsonConfigurationProvider.cs | Implements the scalar key rewrite (commandLineOptions:<name> → ...:<name>:0) for Arity.Min >= 1. |
| src/Platform/Microsoft.Testing.Platform/Configurations/AggregatedConfiguration.cs | Exposes a single entry point to normalize JSON command-line scalar entries when a JSON provider is present. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
JanKrivanek
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #8830.
Problem
In
testconfig.json, a bare scalar like{ "platformOptions": { "commandLineOptions": { "results-directory": "TestResults" } } }was read by
JsonConfigurationProvideras a presence marker viabool.TryParsefor any option whose schema requires an argument. For an arg-bearing option,"timeout": "true"therefore enabled the option with zero args instead of passing"true"as the first argument value — a quiet foot-gun.Fix
Normalize
_singleValueDataonce at startup using the registered option registry: when an option hasArity.Min >= 1, rewrite the bare scalar keyinto the indexed form
so the value is consistently surfaced as the first argument by both
EnumerateCommandLineOptionsandTryGetCommandLineOptionFromProviders.Optional-arg options (
Min=0, Max>=1) remain ambiguous by design and are left untouched (workaround: use the array form["true"]). Zero-arity and unknown options are also left as-is — the existing validator catches unknown options.Wire-up
TestHostBuilder.CommonServices.csbuilds anOrdinalIgnoreCaseoption lookup from the system + extension command-line providers and calls the newAggregatedConfiguration.NormalizeJsonCommandLineOptionScalarsbeforeEnumerateJsonCommandLineOptions, so the validator and any other consumer sees the rewritten form.Tests
Added 9 new
[TestMethod]s inJsonCommandLineOptionsTests.cscovering:"true"/"false"strings on arg-bearing options promoted (regression for the original ambiguity)All 380 existing Configuration / CommandLine tests pass; full
net9.0build clean with-warnaserror.