fix(worker): name quarantined prompt files and their replacements in the recovery Warn

PromptFileRecovery's orphan-quarantine log only reported a bare count, so a customized
merge-helper-execute.md silently stopped applying with no pointer to where it went. Log each
quarantined file's destination path, and for merge-helper-execute.md specifically call out that
it was split into merge-helper-wait.md and merge-helper-merge.md with no content migration.
This commit is contained in:
mika kuns
2026-08-11 16:55:32 +02:00
parent e343baf21a
commit 1003fdbf46
2 changed files with 62 additions and 3 deletions
@@ -1,12 +1,31 @@
using System.Text.Json;
using ClaudeDo.Data;
using ClaudeDo.Worker.Lifecycle;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace ClaudeDo.Worker.Tests.Lifecycle;
public sealed class PromptFileRecoveryTests
{
private sealed class CapturingLogger<T> : ILogger<T>
{
public List<string> Messages { get; } = new();
public IDisposable BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance;
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception?, string> formatter)
=> Messages.Add(formatter(state, exception));
private sealed class NullScope : IDisposable
{
public static readonly NullScope Instance = new();
public void Dispose() { }
}
}
[Fact]
public async Task StartAsync_ReconcilesStaleDefaultAndQuarantinesOrphan_WithoutTouchingRealEdit()
{
@@ -46,4 +65,33 @@ public sealed class PromptFileRecoveryTests
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
}
}
[Fact]
public async Task StartAsync_QuarantinesOrphanedMergeHelperExecute_WarnNamesFileAndReplacements()
{
var root = Path.Combine(Path.GetTempPath(), $"claudedo_prompts_{Guid.NewGuid():N}");
try
{
Directory.CreateDirectory(root);
var orphanPath = Path.Combine(root, "merge-helper-execute.md");
File.WriteAllText(orphanPath, "my old customized triage+wait+merge prompt");
var logger = new CapturingLogger<PromptFileRecovery>();
var sut = new PromptFileRecovery(logger, root);
await sut.StartAsync(CancellationToken.None);
var dest = Path.Combine(root, "_orphans", "merge-helper-execute.md");
Assert.False(File.Exists(orphanPath));
Assert.True(File.Exists(dest));
Assert.Contains(logger.Messages, m => m.Contains("merge-helper-execute.md") && m.Contains(dest));
Assert.Contains(logger.Messages, m =>
m.Contains("merge-helper-wait.md") && m.Contains("merge-helper-merge.md"));
}
finally
{
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
}
}
}