Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Netclaw.Cli.Tests/Tui/InitExistingInstallPageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task ProgressScreen_RendersQueuedUpdates_AndOnlyCtrlQExits()
(_, _) => Task.FromResult(new DaemonResult(true, "Daemon stopped.")),
path =>
{
if (path == _paths.BasePath)
if (path == _paths.ConfigDirectory)
{
deleteStarted.TrySetResult();
releaseDelete.Task.GetAwaiter().GetResult();
Expand Down
11 changes: 8 additions & 3 deletions src/Netclaw.Cli.Tests/Tui/InitExistingInstallViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public async Task FullReset_AfterBothConfirmations_DeletesEverything()
{
File.WriteAllText(_paths.NetclawConfigPath, "{}");
File.WriteAllText(_paths.SqliteDbPath, "db");
// bin/ holds the installed binaries; a full reset must purge data but keep it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

var binaryPath = Path.Combine(_paths.BinDirectory, "netclaw");
File.WriteAllText(binaryPath, "binary");

var vm = Create();
string? route = null;
Expand All @@ -113,7 +116,9 @@ public async Task FullReset_AfterBothConfirmations_DeletesEverything()
Select(vm, 1); // Yes → perform
await WaitForProgressAsync(vm, 3);

Assert.False(Directory.Exists(_paths.BasePath));
Assert.False(Directory.Exists(_paths.ConfigDirectory), "Config should be purged.");
Assert.False(File.Exists(_paths.SqliteDbPath), "Memory db should be purged.");
Assert.True(File.Exists(binaryPath), "Installed binaries in bin/ must survive a full reset.");
await CompleteResetAsync(vm);
Assert.Equal(InitExistingInstallViewModel.WizardRoute, route);
}
Expand Down Expand Up @@ -292,7 +297,7 @@ public async Task Dispose_WhileDeleteIsRunning_CancelsCompletionNavigation()
var releaseDelete = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var vm = Create(DaemonStopped, path =>
{
if (path == _paths.BasePath)
if (path == _paths.ConfigDirectory)
{
deleteStarted.TrySetResult();
releaseDelete.Task.GetAwaiter().GetResult();
Expand Down Expand Up @@ -350,7 +355,7 @@ public async Task ResetFailure_AfterBlockedQuit_ClearsQuitDisabledStatus()
var releaseDelete = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var vm = Create(DaemonStopped, path =>
{
if (path == _paths.BasePath)
if (path == _paths.ConfigDirectory)
{
deleteStarted.TrySetResult();
releaseDelete.Task.GetAwaiter().GetResult();
Expand Down
14 changes: 13 additions & 1 deletion src/Netclaw.Cli/Tui/InitExistingInstallViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,19 @@ private async Task RunResetAsync(CancellationToken ct)

if (_scope == ResetScopeKind.Full)
{
_deleteDirectory(_paths.BasePath);
// Purge everything under BasePath except bin/ — the installed binaries
// live there and deleting them would brick the CLI mid-reset.
foreach (var entry in Directory.GetDirectories(_paths.BasePath))
{
var name = Path.GetFileName(entry);
if (string.Equals(name, "bin", StringComparison.OrdinalIgnoreCase))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to fix this without using a magic string here?

continue;

_deleteDirectory(entry);
}

foreach (var file in Directory.GetFiles(_paths.BasePath))
File.Delete(file);
}
else
{
Expand Down
Loading