Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
10eb964
Add 'devproxy system-proxy reset' and restore previous system proxy s…
waldekmastykarz Nov 5, 2026
e76ff0b
Address review feedback on system proxy reset
waldekmastykarz Nov 5, 2026
9f75e95
Harden system proxy recovery per review feedback
waldekmastykarz Nov 5, 2026
d14a489
Restore macOS snapshot after partial disable failure; harden standalo…
waldekmastykarz Nov 5, 2026
57007bc
Detect system-proxy reset via System.CommandLine parsing
waldekmastykarz Nov 5, 2026
6e20a0b
Leave parsed help to the full command tree
waldekmastykarz Nov 5, 2026
b6c717c
Merge main into issue-2060 branch
waldekmastykarz Nov 24, 2026
1e33fe6
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 24, 2026
90b5f14
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 25, 2026
41920b0
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 26, 2026
ec80e69
Fix system-proxy command compatibility after upstream merge
waldekmastykarz Nov 26, 2026
abb3efc
Preserve system proxy recovery records and verify ownership
waldekmastykarz Nov 26, 2026
a5aecfa
Check snapshot process identity before deleting stale state
waldekmastykarz Nov 26, 2026
7b498cb
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 26, 2026
cde010d
Merge remote-tracking branch 'upstream/main' into resolve-conflicts-p…
waldekmastykarz Nov 26, 2026
7192622
Gate proxy recovery on parsed start and trust snapshot owner
waldekmastykarz Nov 26, 2026
add51ce
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 26, 2026
bf45876
Address review feedback on system proxy ownership and start detection
waldekmastykarz Nov 26, 2026
cadb350
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 27, 2026
3a8e891
Run startup system-proxy recovery only after the start command is parsed
waldekmastykarz Nov 27, 2026
dbb2dcc
Merge branch 'main' into issue-2060-add-a-command-to-restore-system-p…
waldekmastykarz Nov 27, 2026
358641e
Restrict macOS restore to recorded services, keep snapshot until owne…
waldekmastykarz Nov 27, 2026
191f0d2
Warn when restoring an authenticated macOS proxy
waldekmastykarz Nov 27, 2026
6c4f16b
Log system proxy recovery warnings in all reconciliation callers
waldekmastykarz Nov 27, 2026
09fad99
Merge dotnet/dev-proxy main into issue-2060 branch
waldekmastykarz Nov 27, 2026
be59324
Report system proxy restore cleanup failures and capture new macOS se…
waldekmastykarz Nov 27, 2026
203d185
Recover detached system proxy only for parsed starts; retire same-PID…
waldekmastykarz Nov 27, 2026
af40e41
Merge dotnet/dev-proxy main into issue-2060 branch
waldekmastykarz Nov 27, 2026
3b57b36
Merge remote-tracking branch 'origin/issue-2060-add-a-command-to-rest…
waldekmastykarz Nov 27, 2026
9e918ee
Echo all system proxy recovery messages on detached start
waldekmastykarz Nov 27, 2026
92fbb8c
Fix stop --pid PID sharing and JSON reset output at higher log levels
waldekmastykarz Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DevProxy.Abstractions/Proxy/ISystemProxyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public interface ISystemProxyManager
void Enable(string? ipAddress, int port);

/// <summary>
/// Removes Dev Proxy as the system proxy, restoring direct connections. Safe to call
/// even if the proxy was never enabled (idempotent best-effort cleanup).
/// Removes Dev Proxy as the system proxy, restoring the settings that were in place
/// before <see cref="Enable(string?, int)"/> when they were recorded, or direct
/// connections otherwise. Safe to call even if the proxy was never enabled
/// (idempotent best-effort cleanup).
/// </summary>
void Disable();
}
24 changes: 24 additions & 0 deletions DevProxy.Tests/StateManagerPidReuseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ namespace DevProxy.Tests;
[Collection("management-environment")]
public class StateManagerPidReuseTests
{
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task StateLookups_PreserveOrphanedSystemProxyUntilRecovery(bool asSystemProxy)
{
var pid = Random.Shared.Next(int.MaxValue / 2, int.MaxValue);
var path = StateManager.GetInstanceStateFilePath(pid);
Assert.False(File.Exists(path));
try
{
await StateManager.SaveStateAsync(new() { Pid = pid, AsSystemProxy = asSystemProxy });

_ = await StateManager.FindSystemProxyInstanceAsync();
Assert.True(File.Exists(path));

Assert.Null(await StateManager.LoadStateByPidAsync(pid));
Assert.Equal(asSystemProxy, File.Exists(path));
}
finally
{
File.Delete(path);
}
}

[Fact]
public void ProcessStartTime_RoundTripsThroughJson()
{
Expand Down
56 changes: 55 additions & 1 deletion DevProxy.Tests/StopCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using DevProxy.Abstractions.Proxy;
using DevProxy.Commands;
using DevProxy.Logging;
using DevProxy.Proxy;
using DevProxy.State;
using Microsoft.Extensions.Logging.Abstractions;
using System.CommandLine;
using System.Globalization;
using System.Text.Json;
Expand All @@ -24,7 +27,7 @@ public async Task Stop_JsonOutput_NoInstanceWithPid_EmitsStructuredResult()
{
var logger = new RecordingLogger<StopCommand>();

var exitCode = await CreateRootCommand(new StopCommand(logger))
var exitCode = await CreateRootCommand(new StopCommand(logger, NullLogger<SystemProxyManager>.Instance))
.Parse(["stop", "--pid", UnusedPid.ToString(CultureInfo.InvariantCulture), "--output", "json"])
.InvokeAsync();

Expand All @@ -43,3 +46,54 @@ internal static RootCommand CreateRootCommand(Command command) =>
command
];
}

[Collection("management-environment")]
public class StopCommandPidReuseTests
{
[Fact]
public async Task StopByPid_DeadLegacyRecordSharesPidWithLiveInstance_StopsLiveInstance()
{
var legacyPath = StateManager.GetStateFilePath();
if (File.Exists(legacyPath) || File.Exists(SystemProxySnapshotStore.DefaultPath))
{
// Don't touch a real legacy record or system proxy snapshot.
return;
}
var pid = Environment.ProcessId;
var statePath = StateManager.GetInstanceStateFilePath(pid);
Assert.False(File.Exists(statePath));
try
{
// A dead system-proxy instance's legacy record, and a live instance (this test
// process, with an API that doesn't answer) that later got the same PID.
await StateManager.SaveStateAsync(new() { Pid = pid, ProcessStartTime = DateTimeOffset.UnixEpoch, AsSystemProxy = true });
File.Move(statePath, legacyPath);
await StateManager.SaveStateAsync(new()
{
Pid = pid,
ProcessStartTime = StateManager.GetCurrentProcessStartTime(),
AsSystemProxy = true,
ApiUrl = "http://127.0.0.1:1",
});
var logger = new RecordingLogger<StopCommand>();

var exitCode = await StopCommandTests.CreateRootCommand(new StopCommand(logger, NullLogger<SystemProxyManager>.Instance))
.Parse(["stop", "--pid", pid.ToString(CultureInfo.InvariantCulture), "--output", "json"])
.InvokeAsync();

var statuses = logger.Entries
.Where(e => e.EventId == LogEvents.StructuredOutput)
.Select(e => JsonElement.Parse(e.Message).GetProperty("status").GetString())
.ToList();
Assert.Equal(1, exitCode);
Assert.Equal(["staleRecordRemoved", "failed"], statuses);
Assert.False(File.Exists(legacyPath));
Assert.True(File.Exists(statePath));
}
finally
{
File.Delete(statePath);
File.Delete(legacyPath);
}
}
}
41 changes: 41 additions & 0 deletions DevProxy.Tests/SystemProxyCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.Abstractions.Proxy;
using DevProxy.Commands;
using DevProxy.Logging;
using Microsoft.Extensions.Logging;
using Xunit;

namespace DevProxy.Tests;

// Captures the process-wide console, so it mustn't run in parallel with other management tests.
[Collection("management-environment")]
public class SystemProxyCommandTests
{
[Fact]
public void ConsoleLoggerFactory_JsonOutputAboveInformation_KeepsResultAndDropsDiagnostics()
{
var stdout = new StringWriter();
var originalOut = Console.Out;
Console.SetOut(stdout);
try
{
using (var loggerFactory = SystemProxyCommand.CreateConsoleLoggerFactory(OutputFormat.Json, LogLevel.Warning))
{
var logger = loggerFactory.CreateLogger<SystemProxyCommand>();
logger.LogInformation("diagnostic-below-level");
logger.LogStructuredOutput("""{"message":"reset-result"}""");
}
}
finally
{
Console.SetOut(originalOut);
}

var output = stdout.ToString();
Assert.Contains("reset-result", output, StringComparison.Ordinal);
Assert.DoesNotContain("diagnostic-below-level", output, StringComparison.Ordinal);
}
}
Loading
Loading