Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pm-stack/aggregator/src/quota-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function monthDayTime(mon: string, day: string, hhmm: string, now: Date): string
if (month === undefined) return null;

const [h, m] = hhmm.split(":").map(Number);
if (!Number.isInteger(h) || h < 0 || h > 23 || !Number.isInteger(m) || m < 0 || m > 59) return null;
const dayNumber = Number(day);
const dateInYear = (year: number) => new Date(Date.UTC(year, month, dayNumber, h, m));
const isRequestedDate = (date: Date) => date.getUTCMonth() === month && date.getUTCDate() === dayNumber;
Expand Down
26 changes: 15 additions & 11 deletions pm-stack/aggregator/test/quota.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,40 @@ describe("quota extractors", () => {
const consumers = [
{
id: "_openai.main",
view: (reset: string) => `\n### ChatGPT — main account plans\n7-day 42% used; resets ${reset}, 18:01 UTC.\n`,
view: (reset: string, time: string) => `\n### ChatGPT — main account plans\n7-day 42% used; resets ${reset}, ${time} UTC.\n`,
window: { name: "7-day", percent: 42 },
extraWindows: 0,
},
{
id: "opencode-go.drewrypope",
view: (reset: string) =>
`\n### OpenCode Go ×2 workspaces\n- **drewrypope — monthly 60% used**; monthly reset ${reset}, 18:01 UTC.\n`,
view: (reset: string, time: string) =>
`\n### OpenCode Go ×2 workspaces\n- **drewrypope — monthly 60% used**; monthly reset ${reset}, ${time} UTC.\n`,
window: { name: "monthly", unit: "usd", limit: 60, used: 36, percent: 60 },
extraWindows: 0,
},
{
id: "_commandcode",
view: (reset: string) =>
`\n### Command Code\n$6.57 of $10 used; 5h 1.2%, weekly 8.8%; period ends ${reset}, 18:01 UTC.\n`,
view: (reset: string, time: string) =>
`\n### Command Code\n$6.57 of $10 used; 5h 1.2%, weekly 8.8%; period ends ${reset}, ${time} UTC.\n`,
window: { name: "monthly credits", unit: "usd", limit: 10, used: 6.57, percent: 65.7 },
extraWindows: 2,
},
];
const resets = [
{ input: "Oct 30", expected: "2026-10-30T18:01:00.000Z" },
{ input: "oct 30", expected: "2026-10-30T18:01:00.000Z" },
{ input: "OCT 30", expected: "2026-10-30T18:01:00.000Z" },
{ input: "Foo 30", expected: null },
{ input: "Oct 39", expected: null },
{ input: "Oct 30", time: "18:01", expected: "2026-10-30T18:01:00.000Z" },
{ input: "oct 30", time: "18:01", expected: "2026-10-30T18:01:00.000Z" },
{ input: "OCT 30", time: "18:01", expected: "2026-10-30T18:01:00.000Z" },
{ input: "Foo 30", time: "18:01", expected: null },
{ input: "Oct 39", time: "18:01", expected: null },
{ input: "Oct 30", time: "18:60", expected: null },
{ input: "Oct 30", time: "18:99", expected: null },
{ input: "Oct 30", time: "24:00", expected: null },
{ input: "Oct 30", time: "23:59", expected: "2026-10-30T23:59:00.000Z" },
];

for (const consumer of consumers) {
for (const reset of resets) {
const pool = extractQuotaPools(consumer.view(reset.input), NOW).find((p) => p.id === consumer.id)!;
const pool = extractQuotaPools(consumer.view(reset.input, reset.time), NOW).find((p) => p.id === consumer.id)!;
expect(pool.windows).toHaveLength(1 + consumer.extraWindows);
expect(pool.windows[0]).toMatchObject(consumer.window);
expect(pool.windows[0].resetsAt).toBe(reset.expected);
Expand Down
Loading