app: let the settings hide single limit windows
agent-review agent review: pass

The developer does not use Claude's Fable week and wants it out of the
panel. Each provider's settings now hold hidden windows by window series,
so a hidden Codex week stays hidden across slot moves (D7, D8). The panel
drops them in one place before it renders and queries history, and a
hidden window gives no popups. The snapshot and history keep every window
(D9). Older settings files load with nothing hidden.

Refs #17
This commit is contained in:
Florian Schmidt
2026-11-04 19:35:18 +01:00
parent 52b67a6d1b
commit 7631d8096c
8 changed files with 253 additions and 9 deletions
@@ -0,0 +1,77 @@
using Xunit;
namespace FinalToken.Core.Tests;
public sealed class HiddenWindowTests
{
private static readonly DateTimeOffset Now = new(2026, 10, 18, 12, 0, 0, TimeSpan.Zero);
private static LimitWindow Week => new(Provider.Codex, "codex:secondary", "Week", 80,
Now.AddDays(3.5), TimeSpan.FromDays(7), Now, "fixture");
[Fact]
public async Task HiddenWindowsRoundTripWithSeriesLengthAndAbsentLabel()
{
using var directory = new TestDirectory();
var settings = new Settings
{
Claude = new() { HiddenWindows = [new("week (fable)", TimeSpan.FromDays(7), "Current week (Fable)"), new("session", null, "Session")] },
Codex = new() { HiddenWindows = [HiddenLimitWindow.For(Week)] }
};
await SettingsFile.SaveAsync(directory.Path, settings, TestContext.Current.CancellationToken);
var diagnostics = new DiagnosticLog();
var loaded = SettingsFile.Load(directory.Path, diagnostics);
Assert.Equal(settings, loaded); Assert.Equal(settings.GetHashCode(), loaded.GetHashCode());
Assert.Equal(settings.Claude.HiddenWindows, loaded.Claude.HiddenWindows);
Assert.Equal(settings.Codex.HiddenWindows, loaded.Codex.HiddenWindows);
Assert.Empty(diagnostics.Recent);
}
[Fact]
public void OldFileHidesNothing()
{
using var directory = new TestDirectory();
directory.Write("settings.json", """{"claude":{"enabled":true},"codex":{"popupAhead":false}}""");
var diagnostics = new DiagnosticLog();
var settings = SettingsFile.Load(directory.Path, diagnostics);
Assert.Empty(settings.Claude.HiddenWindows); Assert.Empty(settings.Codex.HiddenWindows);
Assert.False(settings.Codex.PopupAhead); Assert.False(settings.Codex.IsHidden(Week));
Assert.Empty(diagnostics.Recent);
}
[Fact]
public void CodexWeekStaysHiddenAcrossSlotResetAndLabelChangesButNotLengthOrName()
{
var config = new ProviderSettings { HiddenWindows = [HiddenLimitWindow.For(Week)] };
Assert.True(config.IsHidden(Week));
Assert.True(config.IsHidden(Week with { Id = "codex:primary", ResetsAt = Now.AddDays(7), Label = "Renamed week" }));
Assert.False(config.IsHidden(Week with { Id = "codex:primary", Length = TimeSpan.FromHours(5) }));
Assert.False(config.IsHidden(Week with { Id = "other:secondary" }));
}
[Theory]
[InlineData(80)]
[InlineData(10)]
public void HiddenWindowHasNoAheadOrBehindPopupAcrossSlotMove(double used)
{
var window = Week with { UsedPercent = used, Id = "codex:primary" };
var pace = Pace.Calculate(window, Now);
Assert.NotNull(new PopupDecider().Observe(window, pace, new Settings()));
var settings = new Settings { Codex = new() { HiddenWindows = [HiddenLimitWindow.For(Week)] } };
Assert.Null(new PopupDecider().Observe(window, pace, settings));
Assert.NotNull(new PopupDecider().Observe(window with { Provider = Provider.Claude }, pace, settings));
}
[Theory]
[InlineData("null")]
[InlineData("[null]")]
[InlineData("[{\"name\":\"\",\"label\":\"Week\"}]")]
[InlineData("[{\"name\":\"week\",\"label\":\"Week\",\"length\":\"00:00:00\"}]")]
public void MalformedHiddenWindowsFallBackWithDiagnostic(string hidden)
{
using var directory = new TestDirectory();
directory.Write("settings.json", "{\"claude\":{\"hiddenWindows\":" + hidden + "}}");
var diagnostics = new DiagnosticLog();
Assert.Empty(SettingsFile.Load(directory.Path, diagnostics).Claude.HiddenWindows);
Assert.Equal("settings-defaults", Assert.Single(diagnostics.Recent).Code);
}
}