feat(data): add AppSettings entity, migration, and repository

This commit is contained in:
Mika Kuns
2026-04-21 15:55:29 +02:00
parent 4283c67d81
commit 62a1121571
7 changed files with 296 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Tests.Infrastructure;
namespace ClaudeDo.Worker.Tests.Repositories;
public class AppSettingsRepositoryTests : IDisposable
{
private readonly DbFixture _db = new();
public void Dispose() => _db.Dispose();
[Fact]
public async Task GetAsync_Returns_Seeded_Defaults()
{
using var ctx = _db.CreateContext();
var repo = new AppSettingsRepository(ctx);
var row = await repo.GetAsync();
Assert.Equal(AppSettingsEntity.SingletonId, row.Id);
Assert.Equal("sonnet", row.DefaultModel);
Assert.Equal(30, row.DefaultMaxTurns);
Assert.Equal("bypassPermissions", row.DefaultPermissionMode);
Assert.Equal("sibling", row.WorktreeStrategy);
Assert.Null(row.CentralWorktreeRoot);
Assert.False(row.WorktreeAutoCleanupEnabled);
}
[Fact]
public async Task UpdateAsync_Persists_And_RoundTrips()
{
using (var ctx = _db.CreateContext())
{
var repo = new AppSettingsRepository(ctx);
await repo.UpdateAsync(new AppSettingsEntity
{
DefaultClaudeInstructions = "be terse",
DefaultModel = "opus",
DefaultMaxTurns = 42,
DefaultPermissionMode = "acceptEdits",
WorktreeStrategy = "central",
CentralWorktreeRoot = "C:/worktrees",
WorktreeAutoCleanupEnabled = true,
WorktreeAutoCleanupDays = 14,
});
}
using var readCtx = _db.CreateContext();
var readRepo = new AppSettingsRepository(readCtx);
var row = await readRepo.GetAsync();
Assert.Equal("be terse", row.DefaultClaudeInstructions);
Assert.Equal("opus", row.DefaultModel);
Assert.Equal(42, row.DefaultMaxTurns);
Assert.Equal("acceptEdits", row.DefaultPermissionMode);
Assert.Equal("central", row.WorktreeStrategy);
Assert.Equal("C:/worktrees", row.CentralWorktreeRoot);
Assert.True(row.WorktreeAutoCleanupEnabled);
Assert.Equal(14, row.WorktreeAutoCleanupDays);
}
[Fact]
public async Task UpdateAsync_Blank_CentralRoot_Stored_As_Null()
{
using var ctx = _db.CreateContext();
var repo = new AppSettingsRepository(ctx);
await repo.UpdateAsync(new AppSettingsEntity { CentralWorktreeRoot = " " });
var row = await repo.GetAsync();
Assert.Null(row.CentralWorktreeRoot);
}
}