Repository navigation
Use plain logging for subcommands and require subcommands first - #2196
Conversation
Subcommands such as 'devproxy api show' now print plain text without level labels; the decorated output is kept for the root command that monitors traffic. Options placed before a subcommand are now rejected, so the root command can be detected reliably from the first argument, even for subcommands contributed by plugins. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Configuration loading can preempt command-order errors and standalone validation when recursive options intervene, while logging thresholds can suppress usage diagnostics.
3 open issues
What changed in this PR
This PR separates subcommand output from Dev Proxy’s traffic-monitoring logs: subcommands use plain messages, while the root command retains decorated logging. It also introduces a subcommand-first argument rule.
Changes:
- Enables plain logging for subcommands and standalone plugin and validation commands.
- Adds ordering errors for options before subcommands and simplifies invocation detection.
- Updates tests for plain output and the new argument-ordering behavior.
| File | Description |
|---|---|
| DevProxy/Logging/ProxyConsoleFormatterOptions.cs | Adds the plain-output option. |
| DevProxy/Logging/ProxyConsoleFormatter.cs | Supports plain messages with short diagnostic prefixes. |
| DevProxy/Extensions/ILoggingBuilderExtensions.cs | Enables plain logging for subcommands. |
| DevProxy/Commands/PluginCommand.cs | Enables plain standalone plugin output. |
| DevProxy/Commands/DevProxyCommand.cs | Adds ordering checks and simplifies command detection. |
| DevProxy/Commands/ConfigCommand.cs | Enables plain standalone validation output. |
| DevProxy.Tests/ProxyConsoleFormatterTests.cs | Tests plain messages and diagnostic prefixes. |
| DevProxy.Tests/LoggingConfigurationTests.cs | Tests root versus subcommand formatting selection. |
| DevProxy.Tests/DevProxyConfigOptionsTests.cs | Removes coverage for leading environment options before stdio. |
| DevProxy.Tests/DevProxyCommandTests.cs | Tests subcommand-first detection and ordering errors. |
| DevProxy.Tests/ConfigValidateTests.cs | Updates validation cases for command-first arguments. |
Review effort: Balanced
- Allow recursive options between 'config' and 'validate' for standalone validation - Show the options-order error regardless of the configured log level Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
config open, api show and outdated read the configuration, so they need config selection now that options must follow the subcommand. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The validator resolves the config path again after environment changes, so it can check a different location and reject a configuration that was successfully loaded.
1 open issue
1 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve conflicts with main (root options moved to CreateRootOptions). --env can change what a token like ~dataFolder expands to after the config file was resolved and loaded, so the --config-file validators on the root command and subcommands check DevProxyConfigOptions.ConfigFile again. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The tests merged from main put options before the subcommand, which is now rejected. Move options after the subcommand, and assert that a plugin option before cert export is rejected without exporting. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
garrytrinder
left a comment
There was a problem hiding this comment.
Functional test results
- PR: dotnet/dev-proxy#2196
- Tested commit:
f2e675e49e7f9df8830891234b0c2e29115b4400 - Environment: macOS, arm64, .NET SDK
11.0.100, source build, private configuration and user directories.
The final execution passed all 47 recorded checks. These checks include command results, output formats, generated content, API responses, and process cleanup.
| Scenario or test command | Expected | Actual | Result |
|---|---|---|---|
| Source and plugin builds | Builds complete without errors or warnings. | Both builds completed with zero errors and zero warnings. | PASS |
| Current-commit CI | Required checks succeed. | Build, smoke, CodeQL, analysis, and tests on macOS, Windows, and Ubuntu succeeded. | PASS |
api show -c custom.json |
Use the selected API address. Do not add information labels. | Exit 0; plain Base URL: http://127.0.0.2:23456. |
PASS |
api show -c custom.json --output json, also with --log-level None |
Preserve structured results independently of diagnostic filtering. | Exit 0; valid JSON Lines with the selected address under data. |
PASS |
--log-level debug api show, also with None and Critical |
Reject leading options with a visible diagnostic. | Exit 2; Options must follow the subcommand. Use: devproxy api show [options]. |
PASS |
--output json api show |
Report the ordering error as JSON on stderr. | Exit 2; valid JSON error record on stderr. |
PASS |
-c custom.json config open and --detach api show |
Reject leading options. Do not start a persistent proxy. | Exit 2; ordering diagnostic; no remaining process or listener. |
PASS |
config open -c custom.json |
Accept configuration selection after the command. | Exit 0; no parser error or runtime diagnostic. The external editor display was not inspected. |
PASS |
config open -c missing.json |
Reject a missing file. | Exit 2. |
PASS |
config validate -c custom.json |
Use plain text with short warning prefixes. | Exit 0; plain information; warning: prefix for the absent schema. |
PASS |
config --output json validate -c custom.json and validate -c custom.json --output json |
Accept recursive options between command levels. | Exit 0; JSON result contains "valid":true. |
PASS |
config --output json validate -c invalid.json |
Report malformed configuration without starting the proxy. | Exit 2; JSON result contains "valid":false. |
PASS |
plugin list --plugin-path <assembly>, text and JSON |
List plugins without decorated text. Preserve JSON results. | Exit 0; MockResponsePlugin listed; JSON Lines parsed correctly. |
PASS |
plugin list --plugin-path missing.dll |
Explain the runtime failure. | Exit 1; stderr starts with error:. |
PASS |
mocks from-http-responses response.http --mocks-file out.json -c plugin.json |
Load the selected plugin and write the response. | Exit 0; plain progress; generated response has status 202 and the expected JSON body. |
PASS |
mocks -c plugin.json from-http-responses response.http --mocks-file middle.json |
Accept recursive configuration selection between command levels. | Exit 0; generated file and success message. |
PASS |
Same plugin command with leading -c plugin.json |
Preserve the new ordering rule. | Exit 2; ordering diagnostic. |
PASS |
Plugin conversion with missing.http, text and JSON |
Report the missing input. | Exit 1; text diagnostic is error: No matching HTTP response files found. JSON error remains visible. |
PASS |
mocks from-http-responses cert export --mocks-file absent.json -c plugin.json |
Treat command names as input values. | Exit 1; missing-input diagnostic; no certificate export. |
PASS |
jwt create --name cert --scopes export --output json, also scopes cert export |
Treat command names as option values. | Exit 0; structured token results; no certificate export. |
PASS |
outdated -c custom.json |
Accept the selected configuration. | Exit 0; plain result with version notifications disabled in the fixture. |
PASS |
Root, stdio, and config open help |
Preserve help and show supported options. | Exit 0; expected command descriptions and configuration option. |
PASS |
| Detached root with safe flags and JSON output | Start on assigned ports and keep management operations functional. | Authenticated API returned 200; explicit proxy request returned the exact local response body. |
PASS |
PID-scoped status, logs, and stop |
Select only the owned instance. | Each command returned 0; logs contained startup records; process exited. |
PASS |
| Foreground root with safe flags | Preserve decorated root logging and traffic forwarding. | info labels remained; authenticated API and explicit proxy request succeeded; PID-scoped stop returned 0. |
PASS |
cert export --file ca.pem --log-level debug, also JSON output |
Keep stdout reserved for the export result. | Exit 0; text path only, or one JSON document; exported file contains a public certificate only. |
PASS |
--log-level debug cert export --file should-not-exist.pem |
Reject leading options without exporting a file. | Exit 2; ordering error; file absent. |
PASS |
Startup exceptions and cleanup
| Scenario | Changed default | Why the default prevents reproduction | Execution environment | Safety controls | Cleanup verification |
|---|---|---|---|---|---|
| Foreground root output | Omitted --detach. |
Detached output does not show the foreground logging format. | macOS; owned .devproxy/pr2196-functional directory. |
Private HOME and CFFIXED_USER_HOME; --as-system-proxy false --install-cert false --port 0 --api-port 0; bounded waits and separate streams. |
Owned process exited; assigned listeners closed. |
| Detached root | None. | N/A | Same private environment. | Safe startup flags; API authentication; local upstream; PID and process start time recorded. | PID-scoped stop succeeded; process absent; API, proxy, and upstream listeners closed. |
| Subcommands | Root startup flags do not apply. | These commands do not start a proxy. | Same private environment; selected configurations disable system proxy registration and certificate trust installation. | Twenty-second command deadline; owned certificate path; private state, logs, and first-run paths. | No state files remained. Test configuration, certificates, logs, and SDK were removed. |
| Certificate export | No native trust operation. | Export checks public-file output, not certificate installation. | Private certificate file and private leaf-cache directory. | No cert ensure, cert remove, or trust command; no system-proxy operation. |
Owned certificate and exported public files removed. |
config open |
Root startup flags do not apply. | This command passes the selected file to the OS file opener. | Owned configuration file only. | No file-association changes. | Test file removed; no test document window was identified. |
The first restore failed because NuGet TLS connections failed. Locked restore through Microsoft's public package mirror succeeded without lock-file changes.
Initial executions exposed fixture and runner errors, not product defects. The runner expected JSON Lines from cert export, which returns one formatted JSON document.
The foreground stop check initially waited on an unreaped child process. Concurrent child reaping corrected this check; the final stop returned 0.
No product changes, commits, pushes, or merges were made. Temporary test files and the owned SDK were removed.
Requested changes
None. The previous configuration-selection failure no longer occurs with config open -c custom.json.
The previous thread is resolved. Configuration selection also works for api show, outdated, and plugin commands.
Outcome
Approve for functional testing on the tested commit. This approval does not replace code review. No essential functional tests remain blocked.
The ASD-STE100 check is incomplete because the full Issue 9 dictionary was unavailable. Sentence lengths and wording were checked manually.
…y reset Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
garrytrinder
left a comment
There was a problem hiding this comment.
Functional test results
- PR: dotnet/dev-proxy#2196
- Tested commit:
0119f2f96040b3478a672c4600a0d91bd994ef18 - Previous tested commit:
f2e675e49e7f9df8830891234b0c2e29115b4400 - Environment: macOS arm64, owned .NET SDK
11.0.100, separate clean checkout, private user directories.
The merge adds the system-proxy recovery changes from main. The last commit adds option-order checks and plain output to standalone reset.
The final execution passed 53 command and runtime checks. Two additional checks passed for the standalone reset logger.
| Scenario or test command | Expected | Actual | Result |
|---|---|---|---|
| Current source and plugin builds | No errors or warnings. | Both builds completed with zero errors and zero warnings. | PASS |
| CI for the tested commit | All checks succeed. | Build, smoke, CodeQL, analysis, and tests on all three operating systems succeeded. | PASS |
api show -c custom.json, text and JSON |
Use selected address; preserve plain text and structured results. | Exit 0; selected 127.0.0.2:23456; valid JSON Lines, including with --log-level None. |
PASS |
Leading options before api show, config open, and plugin commands |
Return usage error 2. |
Ordering diagnostic remained visible, including with None and Critical log levels. |
PASS |
--detach api show |
Reject the ordering without leaving a proxy running. | Exit 2; ordering diagnostic; no remaining process or listener. |
PASS |
config open -c custom.json |
Accept the selected file. | Exit 0; no parser or runtime diagnostic. External editor display was not inspected. |
PASS |
config open -c missing.json |
Reject a missing file. | Exit 2. |
PASS |
config validate, validate, and recursive options between command levels |
Validate selected configuration in text and JSON. | Valid configuration returned 0; malformed configuration returned 2 with "valid":false. |
PASS |
| Text warning and error output | Use short prefixes instead of decorated labels. | warning: and error: appeared on stderr. |
PASS |
plugin list, text and JSON |
Preserve plugin discovery and output formats. | Exit 0; expected plugin listed; JSON Lines parsed correctly. Missing assembly returned 1 with an error. |
PASS |
Plugin conversion with trailing or intermediate -c |
Load the selected plugin and write correct content. | Exit 0; plain progress; generated response had status 202 and the expected JSON body. |
PASS |
| Plugin conversion with missing input, text and JSON | Explain the runtime failure. | Exit 1; No matching HTTP response files found. remained visible. |
PASS |
| Command names used as plugin arguments or JWT option values | Do not select another command. | Plugin diagnostic and structured JWT results remained correct; no unintended certificate export. | PASS |
outdated -c custom.json and command help |
Preserve configuration selection and help. | Exit 0; expected plain output and option descriptions. |
PASS |
| Detached root with safe flags | Preserve assigned ports, authenticated API, traffic forwarding, and management commands. | API returned 200; explicit proxy request returned the exact local body; status, logs, and stop returned 0. |
PASS |
| Foreground root with safe flags | Preserve decorated root output and traffic forwarding. | info labels remained; API and proxy request succeeded; PID-scoped stop returned 0. |
PASS |
| Certificate export, text and JSON | Preserve public-file and stdout contracts. | Exit 0; public certificate only; stdout contained the path or one JSON document. Leading options produced 2 without exporting. |
PASS |
Leading --output json, --log-level None, --log-level Critical, or -c invalid.json before system-proxy reset --force --pr2196-safety-reject |
Report the ordering error before reset or configuration loading. | Each command returned 2 with the ordering diagnostic. JSON errors used stderr. |
PASS |
system-proxy reset --pr2196-safety-reject, text and JSON |
Explain invalid input without native changes. | Exit 2; plain error or JSON error remained visible, including with --log-level None. |
PASS |
Source build's SystemProxyCommand.CreateConsoleLoggerFactory, called without reset |
Emit plain information and short diagnostic prefixes; preserve JSON logging. | Text was exactly PR2196 information, warning: PR2196 warning, and error: PR2196 error. JSON records parsed correctly. |
PASS |
Exact unguarded system-proxy reset and leading-option reproduction with --force |
Verify reset output and ordering without access to shared native settings. | No disposable environment was available. Docker could not connect to its daemon. These commands were not executed. | BLOCKED |
Startup exceptions and cleanup
| Scenario | Changed default | Why the default prevents reproduction | Execution environment | Safety controls | Cleanup verification |
|---|---|---|---|---|---|
| Foreground root | Omitted --detach. |
Detached output hides the foreground format. | Clean temporary checkout on macOS; private HOME and CFFIXED_USER_HOME. |
--as-system-proxy false --install-cert false --port 0 --api-port 0; bounded waits; separate streams; recorded PID and start time. |
Owned processes exited; assigned listeners closed. |
| Detached root | None. | N/A | Same private environment. | Safe flags; authenticated API; local upstream; PID-scoped management commands. | Stop succeeded; process absent; API, proxy, and upstream listeners closed. |
| Subcommands | Root startup flags do not apply. | Subcommands do not start a proxy. | Same private environment; selected configurations disable system proxy registration and certificate trust installation. | Twenty-second command deadline; owned state, logs, certificate, and fixture paths. | No instance state remained. Owned temporary files and SDK were removed. |
| Reset rejection | Added unknown option --pr2196-safety-reject. |
An ordering regression must not reach native reset on this shared Mac. | Same private environment. | Both the ordering check and parser error prevent reset. No native reset was invoked. | Commands exited with 2; no owned process remained. |
| Standalone reset logger | Called only the logger factory through reflection. | Successful reset can change shared native settings. | Actual source assembly in an owned temporary probe. | Probe never invokes reset or native settings. | Probe exited; temporary probe removed. |
| Native reset | Not executed. | Governing test instructions require a disposable environment for native settings. | Shared Mac; Docker daemon unavailable. | No real system-proxy or trust changes. Private user paths do not isolate native settings. | No native test state was created. |
Locked package restore used Microsoft's public package mirror. No dependency or lock files changed.
An initial runner error caused recursion before evidence collection. The corrected execution completed all 53 checks; no owned application processes remained.
Cleanup removed the owned SDK, private user paths, certificates, logs, fixtures, probe, and temporary checkout. Pre-existing files in the original checkout were preserved.
Requested changes
None. No product defect was reproduced. The new ordering and plain-logging checks passed within the stated safety limits.
Outcome
Comment only. The exact native-reset scenarios remain blocked, so this retest does not provide a new approval.
The earlier approval applies to the earlier commit only. This report does not replace code review.
The ASD-STE100 check is incomplete because the full Issue 9 dictionary was unavailable. Sentence lengths and wording were checked manually.
garrytrinder
left a comment
There was a problem hiding this comment.
Approved at the maintainer’s explicit direction after reassessing the scope of essential validation. The current head matches the latest functional test revision, and all eight reported current-head CI checks are successful.
All 53 command/runtime checks and two standalone-logger checks passed, including configuration selection, intentional ordering, plain/text/JSON/plugin logging and runtime regressions. Exact unguarded native reset/--force was not executed on the shared Mac; guarded ordering and the production logger factory were tested. This approval is scoped to the changed logging and command-ordering behavior, accepting that disclosed native integration gap.
No new local tests were run for this approval; evidence comes from the previously published current-head functional report. This does not claim that untested or pre-existing behavior is fixed.



Uses plain (undecorated) console output for all subcommands and keeps the decorated, level-labeled output only for the root command that monitors traffic.
Before, every line of e.g.
devproxy api showwas prefixed withinfo. Now:warning:/error:prefix.devproxy logsand detached log parsing are unaffected.Subcommands must come first
To reliably tell the root command from subcommands before plugins (which can contribute their own subcommands) are loaded, subcommands must now be the first argument. Options placed before a subcommand are rejected with exit code 2:
Recursive options (
--log-level,--output, ...) keep working after the subcommand. This simplifies the stdio/validate/plugin invocation detection, which no longer needs to skip leading option values.Changes
ProxyConsoleFormatterOptions.PlainOutput, enabled for subcommand logging,configand standalone plugin commandsDevProxyCommand.GetLeadingOptionsErrorenforces the subcommand-first rule (text and JSON output)IsStdioSubcommand,IsValidateInvocation,IsPluginCommandNotes
--envbeforestdio(undocumented) is no longer supporteddevproxy --detach api shownow fails with the new error instead of runningapi show