Flag bootstrap-only CLI options when set in testconfig.json#9055
Conversation
A few CLI options (--config-file, --diagnostic, --diagnostic-output-directory, --diagnostic-file-prefix, --diagnostic-verbosity, --diagnostic-synchronous-write) are read directly off CommandLineParseResult during platform bootstrap, before IConfiguration / testconfig.json is built. Setting them under 'commandLineOptions' in testconfig.json was previously silently ignored, which was confusing. CommandLineOptionsValidator now keeps a small set of bootstrap-only option names and fails startup with a clear error when any of them is declared in testconfig.json -- regardless of casing or whether the entry is a value or a disabled marker. Bootstrap-only options on the CLI itself remain fully supported. Adds the new JsonCommandLineOptionIsBootstrapOnlyErrorMessage resource (with regenerated XLFs) and a focused set of unit tests covering every bootstrap-only option, case-insensitivity, disabled entries, CLI parity, non-regression of normal JSON options, and multi-option aggregation. Fixes #8829 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves Microsoft.Testing.Platform’s testconfig.json validation by detecting “bootstrap-only” CLI options (options read before configuration is loaded) when they’re incorrectly specified under commandLineOptions, and failing fast with a clear, localized error message instead of silently ignoring them.
Changes:
- Added a bootstrap-only option validation pass to
CommandLineOptionsValidator(case-insensitive, aggregates all offending JSON entries). - Added unit tests covering bootstrap-only JSON failures (including casing, disabled entries, aggregation) and ensuring CLI usage remains allowed.
- Introduced a new localized resource string (and updated corresponding
.xlffiles).
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/JsonCommandLineOptionsTests.cs | Adds coverage for bootstrap-only options being rejected in testconfig.json and allowed on CLI. |
| src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs | Implements bootstrap-only JSON validation and integrates it into the validation pipeline. |
| src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx | Adds the new error message resource for bootstrap-only JSON option usage. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf | Adds localized entry for the new error message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf | Adds localized entry for the new error message. |
Copilot's findings
- Files reviewed: 16/16 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
Reviewer caught that JsonCommandLineOptionIsBootstrapOnlyErrorMessage rendered the option name without the conventional -- prefix, inconsistent with other platform validation messages (Unknown option '--{0}' etc.). Prepend -- in the format string and update the resource comment to clarify that {0} is the bare name (without --). Regenerated all xlf files.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🧪 Test quality grade — PR #90556 new test methods graded across 1 file (
This advisory comment was generated automatically. Grades are heuristic
|
Description
A few platform CLI options are intentionally read off
CommandLineParseResultbeforeIConfiguration(and thereforetestconfig.json) is built, so they cannot be honored from JSON:--config-file– chicken-and-egg, it tells the system where to find the JSON--diagnostic,--diagnostic-output-directory,--diagnostic-file-prefix,--diagnostic-verbosity,--diagnostic-synchronous-write– needed before the config system is up so we can log config-build itselfBefore this change, declaring any of these under
commandLineOptionsintestconfig.jsonwas silently ignored, which is confusing.Fix
CommandLineOptionsValidatornow keeps a smallBootstrapOnlyOptionsset built fromPlatformCommandLineProviderconstants and runs a JSON-only validation pass right after the unknown-option check. When any bootstrap-only option appears undercommandLineOptionsintestconfig.json, startup fails fast with:Behavior:
Config-Fileflagged just likeconfig-file), consistent with howtestconfig.jsonkeys are handled everywhere else."diagnostic": false) — either way the user clearly intended the option to take effect via JSON, which it never does.Tests
Added under
JsonCommandLineOptionsTests:Validator_JsonBootstrapOnlyOption_Fails—[DataRow]over all six bootstrap-only options.Validator_JsonBootstrapOnlyOption_CaseInsensitive_FailsValidator_JsonBootstrapOnlyOption_DisabledEntry_StillFailsValidator_CliBootstrapOnlyOption_AllowedValidator_JsonNonBootstrapOption_Allowed(non-regression for normal JSON options)Validator_JsonMultipleBootstrapOnlyOptions_AllReportedAll 321
CommandLine~unit tests pass locally.Localization
Added
JsonCommandLineOptionIsBootstrapOnlyErrorMessagetoPlatformResources.resxand regenerated all*.xlffiles viadotnet msbuild Microsoft.Testing.Platform.csproj /t:UpdateXlf.Fixes #8829