Merge PR #8337: fix(usage): use authoritative OpenCode Go quotas (@will-bogusz)
This commit is contained in:
@@ -400,13 +400,31 @@ describe("usage status-line segment", () => {
|
||||
expect(content).not.toContain("90%");
|
||||
});
|
||||
|
||||
it("does not render monthly usage for non-Cursor providers", async () => {
|
||||
it("renders all three OpenCode Go windows including monthly", async () => {
|
||||
const now = Date.now();
|
||||
const component = makeComponent(
|
||||
[
|
||||
{
|
||||
provider: "opencode-go",
|
||||
limits: [
|
||||
{ id: "opencode-go:usd:monthly", scope: { windowId: "monthly" }, amount: { usedFraction: 0.42 } },
|
||||
{
|
||||
id: "rolling-5h",
|
||||
scope: { windowId: "5h" },
|
||||
window: { id: "5h", durationMs: 5 * 3_600_000, resetsAt: now + 90 * 60_000 },
|
||||
amount: { used: 12, usedFraction: 0.12, unit: "percent" },
|
||||
},
|
||||
{
|
||||
id: "weekly",
|
||||
scope: { windowId: "7d" },
|
||||
window: { id: "7d", durationMs: 7 * 86_400_000, resetsAt: now + 100 * 3_600_000 },
|
||||
amount: { used: 8, usedFraction: 0.08, unit: "percent" },
|
||||
},
|
||||
{
|
||||
id: "monthly",
|
||||
scope: { windowId: "monthly" },
|
||||
window: { id: "monthly", resetsAt: now + 160 * 3_600_000 },
|
||||
amount: { used: 42, usedFraction: 0.42, unit: "percent" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -417,6 +435,29 @@ describe("usage status-line segment", () => {
|
||||
await flushUsageRefresh();
|
||||
const content = stripVTControlCharacters(component.getTopBorder(200).content);
|
||||
|
||||
expect(content).toContain("5h");
|
||||
expect(content).toContain("12%");
|
||||
expect(content).toContain("7d");
|
||||
expect(content).toContain("8%");
|
||||
expect(content).toContain("mo");
|
||||
expect(content).toContain("42%");
|
||||
});
|
||||
|
||||
it("does not render monthly usage for providers outside the single-bucket gate", async () => {
|
||||
const component = makeComponent(
|
||||
[
|
||||
{
|
||||
provider: "github-copilot",
|
||||
limits: [{ id: "copilot:premium", scope: { windowId: "monthly" }, amount: { usedFraction: 0.42 } }],
|
||||
},
|
||||
],
|
||||
{ provider: "github-copilot" },
|
||||
);
|
||||
|
||||
component.refreshUsageInBackground();
|
||||
await flushUsageRefresh();
|
||||
const content = stripVTControlCharacters(component.getTopBorder(200).content);
|
||||
|
||||
expect(content).not.toContain("mo");
|
||||
expect(content).not.toContain("42%");
|
||||
});
|
||||
|
||||
@@ -422,29 +422,29 @@ describe("formatUsageBreakdown", () => {
|
||||
});
|
||||
|
||||
it("renders provider-level notes once per provider, not duplicated per account or limit", () => {
|
||||
const disclaimer = "OMP-observed spend only; OpenCode usage outside OMP is not included.";
|
||||
const providerNote = "Usage data can be delayed by up to five minutes.";
|
||||
const multiAccount = [
|
||||
makeReport(
|
||||
"opencode-go",
|
||||
"anthropic",
|
||||
"acct-a@example.test",
|
||||
[makeLimit({ id: "5 Hour", usedFraction: 0.3, durationMs: FIVE_HOURS, windowId: "5h" })],
|
||||
[disclaimer],
|
||||
[providerNote],
|
||||
),
|
||||
makeReport(
|
||||
"opencode-go",
|
||||
"anthropic",
|
||||
"acct-b@example.test",
|
||||
[makeLimit({ id: "5 Hour", usedFraction: 0.6, durationMs: FIVE_HOURS, windowId: "5h" })],
|
||||
[disclaimer],
|
||||
[providerNote],
|
||||
),
|
||||
];
|
||||
const text = stripVTControlCharacters(formatUsageBreakdown(multiAccount, [], Date.now()));
|
||||
// The disclaimer appears exactly once, not once per account or limit.
|
||||
const occurrences = text.split(disclaimer).length - 1;
|
||||
// The provider note appears exactly once, not once per account or limit.
|
||||
const occurrences = text.split(providerNote).length - 1;
|
||||
expect(occurrences).toBe(1);
|
||||
// It appears above the per-account rows, not inline with a limit line.
|
||||
const disclaimerIdx = text.indexOf(disclaimer);
|
||||
const noteIdx = text.indexOf(providerNote);
|
||||
const firstLimitIdx = text.indexOf("5 Hour");
|
||||
expect(disclaimerIdx).toBeLessThan(firstLimitIdx);
|
||||
expect(noteIdx).toBeLessThan(firstLimitIdx);
|
||||
});
|
||||
|
||||
it("renders Antigravity weekly windows in the usage breakdown", () => {
|
||||
|
||||
@@ -49,23 +49,23 @@ function report(provider: string, email: string, limits: UsageReport["limits"],
|
||||
|
||||
describe("renderUsageReports (#3268 TUI aggregate)", () => {
|
||||
it("renders provider-wide UsageReport.notes exactly once for multiple accounts", () => {
|
||||
const disclaimer = "OMP-observed spend only; OpenCode usage outside OMP is not included.";
|
||||
const providerNote = "Usage data can be delayed by up to five minutes.";
|
||||
const reports: UsageReport[] = [
|
||||
report(
|
||||
"opencode-go",
|
||||
"github-copilot",
|
||||
"acct-a@example.test",
|
||||
[limit("5 Hour limit", "rolling-5h", 5 * HOUR, 0.3)],
|
||||
[disclaimer],
|
||||
[providerNote],
|
||||
),
|
||||
report(
|
||||
"opencode-go",
|
||||
"github-copilot",
|
||||
"acct-b@example.test",
|
||||
[limit("5 Hour limit", "rolling-5h", 5 * HOUR, 0.6)],
|
||||
[disclaimer],
|
||||
[providerNote],
|
||||
),
|
||||
];
|
||||
const text = stripVTControlCharacters(renderUsageReports(reports, theme, Date.now(), 120));
|
||||
const occurrences = text.split(disclaimer).length - 1;
|
||||
const occurrences = text.split(providerNote).length - 1;
|
||||
expect(occurrences).toBe(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user