feat(worker): branch type and number rules for task branches
This commit is contained in:
@@ -28,6 +28,12 @@ public class CommitMessageBuilderTests
|
||||
Assert.Equal("abc", CommitMessageBuilder.ToSlug("--abc--"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToSlug_transliterates_umlauts()
|
||||
{
|
||||
Assert.Equal("aerger-ueber-groesse-strasse", CommitMessageBuilder.ToSlug("Ärger über Größe Straße"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Title_TruncatedTo60()
|
||||
{
|
||||
|
||||
@@ -80,14 +80,33 @@ public class WorktreeManagerTests : IDisposable
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Fix: Löschen des Tasks!", "7-fix-lschen-des-tasks")]
|
||||
[InlineData("äöü", "7")]
|
||||
[InlineData("a very long title that goes well beyond the forty char cap", "7-a-very-long-title-that-goes-well-beyond")]
|
||||
public void NameFor_NumberPlusCappedTitleSlug(string title, string expected)
|
||||
[InlineData("Fix: Löschen des Tasks!", null, false, "7-fix-loeschen-des-tasks")]
|
||||
[InlineData("äöü", null, false, "7-aeoeue")]
|
||||
[InlineData("a very long title that goes well beyond the forty char cap", null, false, "7-a-very-long-title-that-goes-well-beyond")]
|
||||
[InlineData("test task", 412, false, "412-test-task")]
|
||||
[InlineData("test task", 412, true, "412-test-task")]
|
||||
[InlineData("test task", null, true, "test-task")]
|
||||
[InlineData("!!!", null, true, "7")]
|
||||
public void NameFor_NumberRules(string title, int? ticketId, bool isCompany, string expected)
|
||||
{
|
||||
Assert.Equal(expected, WorktreeManager.NameFor(new TaskEntity { Id = "x", ListId = "y", Title = title, Number = 7, CreatedAt = DateTime.UtcNow }));
|
||||
var task = new TaskEntity { Id = "x", ListId = "y", Title = title, Number = 7, CreatedAt = DateTime.UtcNow };
|
||||
Assert.Equal(expected, WorktreeManager.NameFor(task, ticketId, isCompany));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("feat", "feature")]
|
||||
[InlineData("fix", "fix")]
|
||||
[InlineData("refactor", "refactor")]
|
||||
[InlineData("docs", "docs")]
|
||||
[InlineData("test", "test")]
|
||||
[InlineData("chore", "chore")]
|
||||
[InlineData("ci", "chore")]
|
||||
[InlineData("perf", "chore")]
|
||||
[InlineData(" FEAT ", "feature")]
|
||||
[InlineData("", "chore")]
|
||||
public void BranchTypeFor_maps_commit_types(string commitType, string expected)
|
||||
=> Assert.Equal(expected, WorktreeManager.BranchTypeFor(commitType));
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_BroadcastsCreatingWorktreePhase()
|
||||
{
|
||||
@@ -128,13 +147,13 @@ public class WorktreeManagerTests : IDisposable
|
||||
var (mgr, _) = await CreateManagerAsync(task, list);
|
||||
|
||||
// A leftover from an earlier DB whose task happened to get the same number and title.
|
||||
var foreign = $"claudedo/{WorktreeManager.NameFor(task)}";
|
||||
var foreign = $"claudedo/{WorktreeManager.NameFor(task, null, false)}";
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", foreign, repo.BaseCommit);
|
||||
|
||||
var ctx = await mgr.CreateAsync(task, list, CancellationToken.None);
|
||||
_worktreeCleanups.Add((repo.RepoDir, ctx.WorktreePath));
|
||||
|
||||
var suffixed = $"{WorktreeManager.NameFor(task)}-{task.Id.Replace("-", "")[..8]}";
|
||||
var suffixed = $"{WorktreeManager.NameFor(task, null, false)}-{task.Id.Replace("-", "")[..8]}";
|
||||
Assert.Equal($"claudedo/{suffixed}", ctx.BranchName);
|
||||
Assert.Equal(suffixed, Path.GetFileName(ctx.WorktreePath));
|
||||
Assert.False(string.IsNullOrWhiteSpace(GitRepoFixture.RunGit(repo.RepoDir, "branch", "--list", foreign)));
|
||||
@@ -157,7 +176,7 @@ public class WorktreeManagerTests : IDisposable
|
||||
|
||||
// Occupy the plain name (-> id-suffixed fallback) and the fallback too, so
|
||||
// `git worktree add -b` hits the "already exists" self-heal path.
|
||||
var branchName = $"claudedo/{WorktreeManager.NameFor(task)}";
|
||||
var branchName = $"claudedo/{WorktreeManager.NameFor(task, null, false)}";
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", branchName, repo.BaseCommit);
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", $"{branchName}-{task.Id.Replace("-", "")[..8]}", repo.BaseCommit);
|
||||
|
||||
@@ -311,13 +330,13 @@ public class WorktreeManagerTests : IDisposable
|
||||
await Assert.ThrowsAnyAsync<Exception>(
|
||||
() => mgr.CreateAsync(task, list, CancellationToken.None));
|
||||
|
||||
var branchName = $"claudedo/{WorktreeManager.NameFor(task)}";
|
||||
var branchName = $"claudedo/{WorktreeManager.NameFor(task, null, false)}";
|
||||
var branchList = GitRepoFixture.RunGit(repo.RepoDir, "branch", "--list", branchName);
|
||||
Assert.True(string.IsNullOrWhiteSpace(branchList),
|
||||
$"orphaned branch {branchName} should be cleaned up, got: {branchList}");
|
||||
|
||||
var worktreeList = GitRepoFixture.RunGit(repo.RepoDir, "worktree", "list");
|
||||
Assert.DoesNotContain(WorktreeManager.NameFor(task), worktreeList);
|
||||
Assert.DoesNotContain(WorktreeManager.NameFor(task, null, false), worktreeList);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user