Skip to content
Closed
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
11 changes: 9 additions & 2 deletions pm-stack/aggregator/src/quota-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// never collapse them into one pool.
import { poolState } from "./derive.ts";
import type { QuotaPool, QuotaWindow } from "./model.ts";
import { parseIsoDate } from "./validate.ts";

const MONTHS: Record<string, number> = {
Jan: 0,
Expand Down Expand Up @@ -213,8 +214,14 @@ const extractClinePass: Extractor = (s) => {
/5-hour \*\*(\d+(?:\.\d+)?)%\*\* used; weekly \*\*(\d+(?:\.\d+)?)%\*\* used \(resets in (\d+)d (\d+)h\); monthly \*\*(\d+(?:\.\d+)?)%\*\* used \(resets in (\d+)d (\d+)h\)/i,
);
if (!measured || !m) return null;
const base = Date.parse(dateTimeCDT(measured[1], measured[2]));
const rel = (d: string, h: string) => new Date(base + (Number(d) * 24 + Number(h)) * 3_600_000).toISOString();
const base = parseIsoDate(dateTimeCDT(measured[1], measured[2]));
const rel = (d: string, h: string): string | null => {
const offsetHours = Number(d) * 24 + Number(h);
if (base === null || !Number.isFinite(offsetHours) || offsetHours > 8784) {
return null;
}
return new Date(base.getTime() + offsetHours * 3_600_000).toISOString();
};
return {
windows: [
pctWindow("5-hour", Number(m[1]), null),
Expand Down
54 changes: 54 additions & 0 deletions pm-stack/aggregator/test/quota.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,60 @@ describe("quota extractors", () => {
expect(p.windows[2].resetsAt).toBe("2026-11-06T00:48:00.000Z");
});

test("clinepass invalid measured anchors keep percentages and null both resets", () => {
const stamps = [
"2026-13-25 ~04:48",
"2026-02-30 ~04:48",
"2026-10-25 ~99:99",
"2026-10-25 ~24:00",
"2026-10-25 ~23:60",
];
for (const stamp of stamps) {
const view = VIEW.replace(
"Measured 2026-10-25 ~04:48 CDT",
`Measured ${stamp} CDT`,
);
const p = extractQuotaPools(view, NOW).find(
(x) => x.id === "cline-pass:cline-pass",
)!;
expect(p.windows.map((w) => w.percent)).toEqual([0, 26, 69]);
expect(p.windows.map((w) => w.resetsAt)).toEqual([null, null, null]);
}
});

test("clinepass oversized relative offsets null only their own reset", () => {
const weeklyTooFar = VIEW.replace("resets in 5d 23h", "resets in 200000d 0h");
const weekly = extractQuotaPools(weeklyTooFar, NOW).find(
(x) => x.id === "cline-pass:cline-pass",
)!;
expect(weekly.windows.map((w) => w.percent)).toEqual([0, 26, 69]);
expect(weekly.windows.map((w) => w.resetsAt)).toEqual([
null,
null,
"2026-11-06T00:48:00.000Z",
]);

const monthlyTooFar = VIEW.replace("resets in 11d 15h", "resets in 99999999999d 0h");
const monthly = extractQuotaPools(monthlyTooFar, NOW).find(
(x) => x.id === "cline-pass:cline-pass",
)!;
expect(monthly.windows.map((w) => w.percent)).toEqual([0, 26, 69]);
expect(monthly.windows.map((w) => w.resetsAt)).toEqual([
null,
"2026-10-31T08:48:00.000Z",
null,
]);
});

test("clinepass accepts the 366-day relative offset ceiling", () => {
const atLimit = VIEW.replace("resets in 5d 23h", "resets in 366d 0h");
const p = extractQuotaPools(atLimit, NOW).find(
(x) => x.id === "cline-pass:cline-pass",
)!;
expect(p.windows[1].resetsAt).toBe("2027-10-26T09:48:00.000Z");
expect(p.windows[2].resetsAt).toBe("2026-11-06T00:48:00.000Z");
});

test("command code credits + short windows", () => {
const p = byId.get("commandcode:go")!;
expect(p.windows[0]).toMatchObject({ unit: "usd", used: 6.57, limit: 10 });
Expand Down
Loading