feat(webui): expand and organize settings with autosave (#5704)
* feat(webui): expand settings with autosave and live configuration * feat(memory): add long-term memory and idle compaction switches * refactor(webui): clarify settings hierarchy and align compact controls * refactor(webui): keep only memory consolidation in memory settings * refactor(webui): defer runtime changes until explicit restart * refactor(webui): remove default workspace setting * fix(webui): align model lists and remove preset counters * fix(i18n): use natural Chinese labels for chat platforms * fix(i18n): shorten chat settings navigation label * fix(webui): match settings navigation icons to text size * refactor(webui): remove redundant settings sidebar heading * refactor(webui): use icon-only back navigation in settings * fix(webui): remove back arrow hover hint * refactor(webui): remove redundant overview details * refactor(webui): hide secondary descriptions in settings rows * style(webui): replace settings dividers with rounded highlights * refactor(webui): remove redundant model list subtitles and badges * fix(i18n): restore chat translation namespace boundaries * fix(i18n): complete settings translations for all locales * fix(webui): reveal settings only for enabled capabilities * fix(webui): consolidate capabilities and isolate settings feedback * fix(webui): clear restart notices when settings are reverted * fix(webui): anchor restart controls in settings sidebar * fix(webui): shorten sidebar restart label * fix(webui): align settings spacing and control sizes * refactor(webui): unify settings dialogs and interaction feedback * fix(webui): keep settings option groups on one line without scrolling * refactor(webui): align settings spacing and sidebar icon proportions * style(webui): match main sidebar typography to settings * style(webui): use monospace for sidebar session handles * refactor(webui): remove heartbeat configuration from automations * feat(webui): expose configuration actions beside capability toggles * style(webui): remove ellipsis from configuration actions * refactor(webui): remove redundant app configuration controls * feat(webui): add compact sidebar navigation and shortcut hints * fix(webui): synchronize npm dependency lockfile * test(webui): align input radius expectation with pill styling * feat(webui): show daily token usage and cache breakdown * feat(webui): add model usage details and cache hit rates * feat(webui): chart daily token usage by model * refactor(webui): simplify usage details and model labels * fix(webui): hide usage dialog date range * refactor(webui): consolidate model usage into chart legends * fix(webui): enforce restart choices and correct settings test route * fix(webui): polish settings localization and controls * fix(webui): avoid repeated usage legend labels * fix(webui): skip empty usage columns in keyboard navigation * test(webui): assert settings behavior positively * feat(webui): refine sidebar navigation and add drag resizing * style(webui): soften sidebar scroll edges * style(webui): harmonize sidebar typography and text colors * feat(webui): move channels to the main sidebar * style(webui): remove dotted underlines from settings hints * fix(webui): unify tooltip hover delay * fix(webui): support Seatbelt sandbox settings * fix(webui): remove unused appearance density preference * fix(webui): align settings input values consistently * style(webui): group compact settings controls before inputs * feat(webui): edit multiline settings in compact dialogs * feat(webui): add continuous settings scrolling with gentle snapping * Revert "feat(webui): add continuous settings scrolling with gentle snapping" This reverts commit f0978c261a53c844185eeab4d0c3190fbd196fe6.
This commit is contained in:
1 parent
20f115bf46
commit
8ea683679d
244 files changed
+6929
-3900
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { TokenUsageCard } from "@/components/settings/TokenUsageCard";
|
||||
import { TokenUsageModelTrend } from "@/components/settings/TokenUsageModelTrend";
|
||||
import type { SettingsPayload } from "@/lib/types";
|
||||
|
||||
type Usage = NonNullable<SettingsPayload["usage"]>;
|
||||
function day(date: string, tokens: number): Usage["days"][number] {
|
||||
return { date, total_tokens: tokens, input_tokens: tokens, output_tokens: 0,
|
||||
cache_read_tokens: 0, cache_write_tokens: 0, cache_read_observed_input_tokens: 0,
|
||||
cache_write_observed_input_tokens: 0, requests: 1 };
|
||||
}
|
||||
function usage(days: Usage["days"]): Usage {
|
||||
return { days, total_tokens: 999999, total_tokens_30d: 999999, total_tokens_365d: 999999,
|
||||
peak_day_tokens: 999999, current_streak_days: 0, longest_streak_days: 0,
|
||||
active_days_30d: 0, requests_30d: 0, updated_at: "2026-09-09T00:00:00Z" };
|
||||
}
|
||||
|
||||
describe("Token usage card", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({ toFake: ["Date"] });
|
||||
vi.setSystemTime(new Date("2026-09-09T12:00:00Z"));
|
||||
});
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
it("uses one 30-day window for the total, chart and source percentages", () => {
|
||||
const today = { ...day("2026-09-09", 300), input_tokens: 240, output_tokens: 60, cache_read_tokens: 120, cache_read_observed_input_tokens: 180, estimated_tokens: 100,
|
||||
sources: { user: day("2026-09-09", 200) } };
|
||||
render(<TokenUsageCard timeZone="UTC" usage={usage([
|
||||
day("2026-08-10", 9000), day("2026-08-11", 100), today, day("2026-09-10", 9000),
|
||||
])} />);
|
||||
expect(screen.getByLabelText("400 tokens")).toBeInTheDocument();
|
||||
const bars = within(screen.getByRole("group", { name: "Daily token usage" })).getAllByRole("img");
|
||||
expect(bars).toHaveLength(30);
|
||||
expect(bars.filter((bar) => bar.tabIndex === 0)).toEqual([bars[0], bars[29]]);
|
||||
expect(bars[0]).toHaveAccessibleName(/2026-08-11: 100 tokens, 1 requests/);
|
||||
expect(bars[29]).toHaveAccessibleName(/Cached input: 120, Cache miss: 60, Cache status unknown: 60, Output: 60/);
|
||||
const segments = bars[29].firstElementChild?.children;
|
||||
expect(segments).toHaveLength(4);
|
||||
expect(segments?.[0]).toHaveStyle({ height: "40%" });
|
||||
expect(segments?.[1]).toHaveStyle({ height: "20%" });
|
||||
expect(segments?.[2]).toHaveStyle({ height: "20%" });
|
||||
expect(segments?.[3]).toHaveStyle({ height: "20%" });
|
||||
expect(bars[0]).toHaveAccessibleName(/Cache miss: 0, Cache status unknown: 100/);
|
||||
expect(screen.getAllByText("50%")).toHaveLength(2);
|
||||
expect(screen.getByText("Unclassified")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows an empty state for zero usage", () => {
|
||||
render(<TokenUsageCard usage={usage([])} />);
|
||||
expect(screen.getByRole("status")).toHaveTextContent("No token usage in the last 30 days.");
|
||||
});
|
||||
|
||||
it("opens details and computes the weighted cache rate from observed input only", () => {
|
||||
render(<TokenUsageCard usage={usage([
|
||||
{ ...day("2026-09-08", 100), cache_read_tokens: 80, cache_read_observed_input_tokens: 100 },
|
||||
{ ...day("2026-09-09", 900), cache_read_tokens: 20, cache_read_observed_input_tokens: 300 },
|
||||
])} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "View details" }));
|
||||
const details = screen.getByRole("dialog", { name: "Token usage" });
|
||||
expect(within(details).getByText("25%")).toBeInTheDocument();
|
||||
expect(within(details).getByTitle("Cache hit rate excludes input with unknown cache status.")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not misrepresent unavailable usage as zero", () => {
|
||||
render(<TokenUsageCard />);
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Usage data is unavailable.");
|
||||
expect(screen.getByText("—")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the five leading model series and reconciles the rest to the daily total", () => {
|
||||
const days = Array.from({ length: 30 }, (_, index) => {
|
||||
const date = new Date("2026-09-09T00:00:00Z");
|
||||
date.setUTCDate(date.getUTCDate() - 29 + index);
|
||||
const key = date.toISOString().slice(0, 10);
|
||||
return { date: key, usage: day(key, index === 29 ? 2200 : 0) };
|
||||
});
|
||||
render(<TokenUsageModelTrend days={days}
|
||||
models={[{ ...day("2026-09-09", 600), provider: "provider", model: "model-5",
|
||||
cache_read_tokens: 120, cache_read_observed_input_tokens: 150,
|
||||
reported_tokens: 600, estimated_tokens: 0, successful_requests: 1, failed_requests: 0,
|
||||
reported_requests: 1, estimated_requests: 0, generation_ms: 0, measured_output_tokens: 0,
|
||||
ttft_ms: 0, timed_requests: 0, duration_ms: 0 }]}
|
||||
modelDays={Array.from({ length: 6 }, (_, index) => ({ date: "2026-09-09", provider: "provider", model: `model-${index}`, total_tokens: (index + 1) * 100 }))} />);
|
||||
const column = screen.getAllByRole("img")[29];
|
||||
expect(screen.getAllByRole("img").filter((bar) => bar.tabIndex === 0)).toEqual([column]);
|
||||
expect(column).toHaveAccessibleName(/2026-09-09: 2,200 tokens/);
|
||||
expect(column).toHaveAccessibleName(/model-5: 600/);
|
||||
expect(column).toHaveAccessibleName(/Other \/ unattributed: 200/);
|
||||
const legend = screen.getByLabelText("model-5: Total tokens: 600 · 27.3%, Cache hit rate: 80%");
|
||||
expect(legend).toHaveAttribute("tabindex", "0");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user