From 8a8ddbe6c803f16145d29daf49c1e3ca61bf0511 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Wed, 21 Oct 2026 15:54:38 +0200 Subject: [PATCH] Fix --discover false enabling recording Only enable recording when --discover is true. Previously any value, including false, turned recording on. Closes #1957 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c4accf12-c9fb-4311-806c-5ed628b79d22 --- DevProxy.Tests/DevProxyCommandTests.cs | 54 ++++++++++++++++++++++++++ DevProxy/Commands/DevProxyCommand.cs | 15 ++++--- 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 DevProxy.Tests/DevProxyCommandTests.cs diff --git a/DevProxy.Tests/DevProxyCommandTests.cs b/DevProxy.Tests/DevProxyCommandTests.cs new file mode 100644 index 00000000..ffcba30f --- /dev/null +++ b/DevProxy.Tests/DevProxyCommandTests.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using DevProxy.Commands; + +using Xunit; + +namespace DevProxy.Tests; + +public class DevProxyCommandTests +{ + [Fact] + public void ApplyDiscoverOption_True_EnablesRecording() + { + var config = new FakeProxyConfiguration { Record = false }; + + DevProxyCommand.ApplyDiscoverOption(config, true); + + Assert.True(config.Record); + } + + [Fact] + public void ApplyDiscoverOption_False_DoesNotEnableRecording() + { + var config = new FakeProxyConfiguration { Record = false }; + + DevProxyCommand.ApplyDiscoverOption(config, false); + + Assert.False(config.Record); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void ApplyDiscoverOption_NotSpecified_LeavesRecordingUnchanged(bool record) + { + var config = new FakeProxyConfiguration { Record = record }; + + DevProxyCommand.ApplyDiscoverOption(config, null); + + Assert.Equal(record, config.Record); + } + + [Fact] + public void ApplyDiscoverOption_False_KeepsRecordingEnabledFromOtherSources() + { + var config = new FakeProxyConfiguration { Record = true }; + + DevProxyCommand.ApplyDiscoverOption(config, false); + + Assert.True(config.Record); + } +} diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index dfc9b763..cd582468 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -674,6 +674,15 @@ private void CustomizeHelp() } } + internal static void ApplyDiscoverOption(IProxyConfiguration proxyConfiguration, bool? isDiscover) + { + // Discovery mode requires recording, but --discover false must not enable it + if (isDiscover == true) + { + proxyConfiguration.Record = true; + } + } + private void ConfigureFromOptions(ParseResult parseResult) { var port = parseResult.GetValueOrDefault(PortOptionName); @@ -742,11 +751,7 @@ private void ConfigureFromOptions(ParseResult parseResult) { _proxyConfiguration.TimeoutSeconds = timeout.Value; } - var isDiscover = parseResult.GetValueOrDefault(DiscoverOptionName); - if (isDiscover is not null) - { - _proxyConfiguration.Record = true; - } + ApplyDiscoverOption(_proxyConfiguration, parseResult.GetValueOrDefault(DiscoverOptionName)); var env = parseResult.GetValueOrDefault(EnvOptionName); if (env is not null) {