fix(usage): derive window names and unify pin selection (#5903)

* fix(usage): derive window names and unify pin selection

Quota slots do not identify a period. Derive numeric windows and IDs from reported duration and quota scope; keep unknown lengths neutral. Resolve source defaults and explicit pins through one model, with a persisted empty selection distinct from defaults.

* fix(plugins): declare the duration helper host requirement

* fix(usage): verify persisted selections at the storage boundary
This commit is contained in:
Mohamed Boudra
2026-10-02 11:18:13 +01:00
committed by GitHub
parent 6c985769be
commit 73d25317a4
27 changed files with 815 additions and 172 deletions
+21
View File
@@ -4,6 +4,7 @@ import {
toneFromUsedPct,
usedPctOf,
windowFromUsedPct,
windowFromReportedDuration,
} from "./usage.js";
test("shared usage tones preserve the app threshold contract", () => {
@@ -84,3 +85,23 @@ describe("balanceToneFromRemaining", () => {
expect(balanceToneFromRemaining(null)).toBe("default");
});
});
test.each([
[18000, "five_hour", "5-hour", "5h"],
[604800, "weekly", "Weekly", "wk"],
[7200, "7200s", "2-hour", "2h"],
[86400, "86400s", "1-day", "1d"],
[90, "90s", "90-second", "90s"],
[null, "primary", "Primary limit", ""],
])(
"duration %s owns the window's identity and both names",
(durationSeconds, id, label, shortLabel) => {
expect(
windowFromReportedDuration({
durationSeconds: durationSeconds as number | null,
unknown: { id: "primary", label: "Primary limit", shortLabel: "" },
utilizationPct: 11,
}),
).toMatchObject({ id, label, shortLabel, usedPct: 11 });
},
);