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
108 lines
7.6 KiB
C#
108 lines
7.6 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Styling;
|
|
using Avalonia.Threading;
|
|
using Avalonia.VisualTree;
|
|
using FinalToken.Core;
|
|
using FinalToken.Core.StreamDeck;
|
|
using Xunit;
|
|
|
|
namespace FinalToken.App.Tests;
|
|
|
|
internal static class HiddenWindowViews
|
|
{
|
|
// Called by the shared headless fixture on its dedicated UI thread.
|
|
public static void Verify(Action<Window, string> save)
|
|
{
|
|
var clock = new FixedClock();
|
|
var now = clock.GetUtcNow();
|
|
var all = new LimitWindow(Provider.Claude, "week (all models)", "Current week (all models)", 60,
|
|
now.AddDays(3), TimeSpan.FromDays(7), now, "fixture");
|
|
var fable = all with { Id = "week (fable)", Label = "Current week (Fable)", UsedPercent = 30 };
|
|
var codex = all with { Provider = Provider.Codex, Id = "codex:primary", Label = "Week", UsedPercent = 40 };
|
|
var session = new HiddenLimitWindow("session", TimeSpan.FromHours(5), "Current session");
|
|
var snapshot = new Snapshot { MadeAt = now, RefreshInterval = TimeSpan.FromMinutes(1), Providers =
|
|
[new(Provider.Claude, ProviderStatus.Available, null, [View(all), View(fable)], new(Total: 100), null, new(Total: 500), now.AddDays(-4), all.Id),
|
|
new(Provider.Codex, ProviderStatus.Available, null, [View(codex)], new(Total: 200), null, new(Total: 800), now.AddDays(-4), codex.Id)] };
|
|
var initial = new Settings { Claude = new() { HiddenWindows = [HiddenLimitWindow.For(fable), session] },
|
|
Codex = new() { HiddenWindows = [HiddenLimitWindow.For(codex with { Id = "codex:secondary" })] } };
|
|
Settings? saved = null;
|
|
var settings = new SettingsWindow(initial, new(PluginInstallState.NoHostFound), value => { saved = value; return Task.CompletedTask; }, snapshot: snapshot);
|
|
settings.Show(); Dispatcher.UIThread.RunJobs();
|
|
Assert.NotNull(settings.Icon);
|
|
var choices = settings.GetVisualDescendants().OfType<NeutralCheckBox>().Where(c => c.Content is string text && text.StartsWith("Show ", StringComparison.Ordinal)).ToArray();
|
|
Assert.Equal(["Show Current week (all models)", "Show Current week (Fable)", "Show Current session", "Show Week"], choices.Select(c => c.Content as string));
|
|
Assert.True(choices[0].IsChecked); Assert.All(choices.Skip(1), c => Assert.False(c.IsChecked));
|
|
var viewport = settings.GetVisualDescendants().OfType<ScrollViewer>().First();
|
|
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
|
|
{
|
|
settings.RequestedThemeVariant = theme; Dispatcher.UIThread.RunJobs();
|
|
var title = settings.GetVisualDescendants().OfType<TextBlock>().Single(t => t.Text == "Providers");
|
|
viewport.Offset = new Vector(0, viewport.Offset.Y + title.TranslatePoint(default, viewport)!.Value.Y - 16);
|
|
save(settings, $"hidden-settings-providers-{theme}.png");
|
|
}
|
|
choices[0].IsChecked = false; choices[1].IsChecked = true; choices[2].IsChecked = true;
|
|
settings.GetVisualDescendants().OfType<Button>().Single(b => b.Content as string == "Save").RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
|
Assert.NotNull(saved);
|
|
Assert.Equal(HiddenLimitWindow.For(all), Assert.Single(saved.Claude.HiddenWindows));
|
|
Assert.True(saved.Codex.IsHidden(codex));
|
|
Assert.Equal(2, initial.Claude.HiddenWindows.Count); // Cancel/save must not mutate the caller's value.
|
|
var emptySettings = new SettingsWindow(new(), new(PluginInstallState.NoHostFound), _ => Task.CompletedTask);
|
|
emptySettings.Show(); Dispatcher.UIThread.RunJobs();
|
|
Assert.Equal(2, emptySettings.GetVisualDescendants().OfType<TextBlock>().Count(t => t.Text == "No known limit windows"));
|
|
emptySettings.Close();
|
|
|
|
var store = new HistoryStore(Path.Combine(Path.GetTempPath(), "finaltoken-hidden", Guid.NewGuid().ToString("N")), new(), clock);
|
|
foreach (var window in new[] { all, fable, codex })
|
|
store.AddLimits([window with { SampleTime = now.AddHours(-30), UsedPercent = 10 }, window]);
|
|
var model = new PanelViewModel { Snapshot = snapshot,
|
|
History = PanelViewModel.QueryHistory(store, snapshot, HistoryRange.Days7, null, now) };
|
|
var panel = new PanelWindow(model, () => { }, () => { }, () => { }, () => { }, clock);
|
|
panel.Show(); Dispatcher.UIThread.RunJobs();
|
|
Assert.NotNull(panel.Icon); Assert.Equal(3, panel.GetVisualDescendants().OfType<BurnUpChart>().Count());
|
|
Assert.Equal(2, panel.GetVisualDescendants().OfType<ComboBox>().Count());
|
|
// Select Fable in both selectors before hiding it, exercising stale selection/history retirement.
|
|
foreach (var selector in panel.GetVisualDescendants().OfType<ComboBox>()) selector.SelectedIndex = 1;
|
|
var hidden = new Settings { Claude = initial.Claude };
|
|
model.ApplySnapshot(snapshot, hidden); Dispatcher.UIThread.RunJobs();
|
|
VerifyNoFable(); // Applies at once, even while the replacement history is pending.
|
|
model.History = PanelViewModel.QueryHistory(store, model.Snapshot!, HistoryRange.Days7, null, now);
|
|
Dispatcher.UIThread.RunJobs(); VerifyNoFable();
|
|
Assert.Equal(2, model.History.Limits.Count); Assert.Equal(2, model.History.Resets.Count); Assert.Equal(2, model.History.Details.Count);
|
|
Assert.Equal(snapshot.Providers[0].Week, model.Snapshot!.Providers[0].Week);
|
|
Assert.Equal(snapshot.Providers[0].WeekStart, model.Snapshot.Providers[0].WeekStart);
|
|
Assert.Equal(all.Id, model.Snapshot.Providers[0].WeekWindow);
|
|
Assert.Equal(2, snapshot.Providers[0].Windows.Count);
|
|
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
|
|
{
|
|
panel.RequestedThemeVariant = theme;
|
|
panel.GetVisualDescendants().OfType<ScrollViewer>().First().Offset = default;
|
|
save(panel, $"hidden-panel-top-{theme}.png");
|
|
}
|
|
model.ApplySnapshot(snapshot, hidden with { Claude = new() { HiddenWindows = [HiddenLimitWindow.For(all), HiddenLimitWindow.For(fable)] } });
|
|
Dispatcher.UIThread.RunJobs();
|
|
Assert.DoesNotContain(panel.GetVisualDescendants().OfType<Border>(), b => b.Name?.StartsWith("LimitTile-Claude-", StringComparison.Ordinal) == true);
|
|
Assert.Single(panel.GetVisualDescendants().OfType<BurnUpChart>());
|
|
Assert.Single(panel.GetVisualDescendants().OfType<DailyLimitChart>());
|
|
Assert.Single(panel.GetVisualDescendants().OfType<ResetCard>());
|
|
model.ApplySnapshot(snapshot, new());
|
|
model.History = PanelViewModel.QueryHistory(store, model.Snapshot!, HistoryRange.Days7, null, now);
|
|
Dispatcher.UIThread.RunJobs();
|
|
Assert.Equal(3, panel.GetVisualDescendants().OfType<BurnUpChart>().Count());
|
|
Assert.Equal(2, panel.GetVisualDescendants().OfType<ComboBox>().Count());
|
|
panel.Close();
|
|
|
|
WindowSnapshot View(LimitWindow w) => new(w, Pace.Calculate(w, now));
|
|
void VerifyNoFable()
|
|
{
|
|
Assert.DoesNotContain(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text?.Contains("Fable", StringComparison.Ordinal) == true);
|
|
Assert.DoesNotContain(panel.GetVisualDescendants().OfType<Border>(), b => b.Name == "LimitTile-Claude-week (fable)");
|
|
Assert.Contains(panel.GetVisualDescendants().OfType<Border>(), b => b.Name == "LimitTile-Claude-week (all models)");
|
|
Assert.Empty(panel.GetVisualDescendants().OfType<ComboBox>());
|
|
Assert.Equal(2, panel.GetVisualDescendants().OfType<BurnUpChart>().Count());
|
|
Assert.Equal(2, panel.GetVisualDescendants().OfType<ResetCard>().Count());
|
|
}
|
|
}
|
|
}
|