perf(worker): read untracked-worktree sweep from .git instead of spawning git per list

This commit is contained in:
mika kuns
2026-10-02 15:37:35 +02:00
parent a75acbb2c0
commit 59d990c267
2 changed files with 74 additions and 9 deletions
@@ -72,7 +72,6 @@ public sealed class UntrackedWorktreeRecoveryTests : IDisposable
var hubContext = new CapturingHubContext();
var sut = new UntrackedWorktreeRecovery(
_db.CreateFactory(),
new ClaudeDo.Data.Git.GitService(),
new HubBroadcaster(hubContext),
new ClaudeDo.Worker.Config.WorkerConfig(),
NullLogger<UntrackedWorktreeRecovery>.Instance);
@@ -83,4 +82,32 @@ public sealed class UntrackedWorktreeRecoveryTests : IDisposable
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
[Fact]
public void ReadLinkedWorktrees_MatchesGitWorktreeList()
{
if (!GitRepoFixture.IsGitAvailable()) return;
using var repo = new GitRepoFixture();
var parent = Path.GetDirectoryName(repo.RepoDir)!;
var onBranch = Path.Combine(parent, "wt-branch");
var detached = Path.Combine(parent, "wt-detached");
GitRepoFixture.RunGit(repo.RepoDir, "worktree", "add", "-b", "feature/1-x", onBranch);
GitRepoFixture.RunGit(repo.RepoDir, "worktree", "add", "--detach", detached);
var fromMain = UntrackedWorktreeRecovery.ReadLinkedWorktrees(repo.RepoDir);
var fromLinked = UntrackedWorktreeRecovery.ReadLinkedWorktrees(onBranch);
foreach (var list in new[] { fromMain, fromLinked })
{
Assert.Equal(2, list.Count);
Assert.Contains(list, w => string.Equals(w.Path, Path.GetFullPath(onBranch), StringComparison.OrdinalIgnoreCase) && w.Branch == "feature/1-x");
Assert.Contains(list, w => string.Equals(w.Path, Path.GetFullPath(detached), StringComparison.OrdinalIgnoreCase) && w.Branch is null);
}
}
[Fact]
public void ReadLinkedWorktrees_NotARepo_ReturnsEmpty()
{
Assert.Empty(UntrackedWorktreeRecovery.ReadLinkedWorktrees(Path.GetTempPath()));
}
}