mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 00:44:49 +00:00
fix(usage): report enterprise spending limits
This commit is contained in:
@@ -117,6 +117,38 @@ test("coerces credit balance and marks a 96 percent window dangerous", async ()
|
||||
]);
|
||||
});
|
||||
|
||||
test("reports enterprise individual spend limit percentage and reset", async () => {
|
||||
const report = await fetchUsage(authInput(fixtureHome), async () =>
|
||||
Response.json({
|
||||
plan_type: "enterprise",
|
||||
spend_control: {
|
||||
individual_limit: { used_percent: 5, remaining_percent: 95, reset_at: 1795996800 },
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(report).toMatchObject({
|
||||
planLabel: "enterprise",
|
||||
windows: [
|
||||
expect.objectContaining({
|
||||
id: "individual_limit",
|
||||
label: "Individual spend limit",
|
||||
summary: true,
|
||||
usedPct: 5,
|
||||
remainingPct: 95,
|
||||
resetsAt: new Date(1795996800 * 1000).toISOString(),
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("omits individual spend limit without a percentage", async () => {
|
||||
const report = await fetchUsage(authInput(fixtureHome), async () =>
|
||||
Response.json({ spend_control: { individual_limit: { reset_at: 1795996800 } } }),
|
||||
);
|
||||
expect(report.windows).toEqual([]);
|
||||
});
|
||||
|
||||
test("summarizes the session and weekly windows by default, not code review", async () => {
|
||||
const report = await fetchUsage(
|
||||
authInput(fixtureHome),
|
||||
|
||||
@@ -34,6 +34,15 @@ const rateLimitSchema = z.object({
|
||||
primary_window: windowSchema.nullish(),
|
||||
secondary_window: windowSchema.nullish(),
|
||||
});
|
||||
const spendControlSchema = z.object({
|
||||
individual_limit: z
|
||||
.object({
|
||||
used_percent: number.nullish(),
|
||||
remaining_percent: number.nullish(),
|
||||
reset_at: number.nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
});
|
||||
const responseSchema = z.object({
|
||||
plan_type: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
@@ -48,6 +57,7 @@ const responseSchema = z.object({
|
||||
)
|
||||
.nullish(),
|
||||
code_review_rate_limit: rateLimitSchema.nullish(),
|
||||
spend_control: spendControlSchema.nullish(),
|
||||
credits: z.object({ balance: number.optional() }).nullish(),
|
||||
});
|
||||
|
||||
@@ -227,6 +237,27 @@ export async function fetchUsage(
|
||||
},
|
||||
});
|
||||
}),
|
||||
...(usage.spend_control?.individual_limit
|
||||
? (() => {
|
||||
const limit = usage.spend_control.individual_limit;
|
||||
const usedPct =
|
||||
limit.used_percent ??
|
||||
(limit.remaining_percent != null ? 100 - limit.remaining_percent : undefined);
|
||||
if (usedPct === undefined && limit.remaining_percent == null) return [];
|
||||
return [
|
||||
{
|
||||
id: "individual_limit",
|
||||
label: "Individual spend limit",
|
||||
summary: true,
|
||||
usedPct,
|
||||
remainingPct: limit.remaining_percent,
|
||||
resetsAt:
|
||||
limit.reset_at != null ? new Date(limit.reset_at * 1000).toISOString() : null,
|
||||
tone: toneFromUsedPct(usedPct),
|
||||
},
|
||||
];
|
||||
})()
|
||||
: []),
|
||||
...usageWindows({
|
||||
rateLimit: usage.code_review_rate_limit,
|
||||
scope: { id: "code_review", label: "Code review" },
|
||||
|
||||
Reference in New Issue
Block a user