feat(ui): add inheritance resolver returning value and source

This commit is contained in:
mika kuns
2026-06-04 12:28:12 +02:00
parent bba3c55e1c
commit 92cee125cc
2 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
namespace ClaudeDo.Ui.Services;
public enum InheritSource { Override, List, Global }
public static class InheritanceResolver
{
// Task-scope fields: task -> list -> global.
public static (string Value, InheritSource Source) Resolve(
string? taskValue, string? listValue, string? globalValue)
{
if (!string.IsNullOrWhiteSpace(taskValue)) return (taskValue!, InheritSource.Override);
if (!string.IsNullOrWhiteSpace(listValue)) return (listValue!, InheritSource.List);
return (globalValue ?? "", InheritSource.Global);
}
// List-scope fields: list -> global (lists have no tier above them).
public static (string Value, InheritSource Source) ResolveList(
string? listValue, string? globalValue)
{
if (!string.IsNullOrWhiteSpace(listValue)) return (listValue!, InheritSource.Override);
return (globalValue ?? "", InheritSource.Global);
}
}

View File

@@ -0,0 +1,43 @@
using ClaudeDo.Ui.Services;
using Xunit;
namespace ClaudeDo.Ui.Tests;
public class InheritanceResolverTests
{
[Fact]
public void Task_value_is_an_override()
{
var (value, source) = InheritanceResolver.Resolve("opus", "sonnet", "haiku");
Assert.Equal("opus", value);
Assert.Equal(InheritSource.Override, source);
}
[Fact]
public void Falls_through_to_list()
{
var (value, source) = InheritanceResolver.Resolve(null, "sonnet", "haiku");
Assert.Equal("sonnet", value);
Assert.Equal(InheritSource.List, source);
}
[Fact]
public void Falls_through_to_global()
{
var (value, source) = InheritanceResolver.Resolve(" ", null, "haiku");
Assert.Equal("haiku", value);
Assert.Equal(InheritSource.Global, source);
}
[Fact]
public void List_scope_treats_list_value_as_override()
{
var (value, source) = InheritanceResolver.ResolveList("sonnet", "haiku");
Assert.Equal("sonnet", value);
Assert.Equal(InheritSource.Override, source);
var (value2, source2) = InheritanceResolver.ResolveList(null, "haiku");
Assert.Equal("haiku", value2);
Assert.Equal(InheritSource.Global, source2);
}
}