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 src/providers/codex-capacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { codexPlanKey, codexPlanValue } from "../codex/plan";

export const CODEX_CONFIGURED_CAPACITY_WEIGHTS = {
plus: 1,
team: 1,
business: 1,
prolite: 5,
pro: 20,
Expand Down
34 changes: 31 additions & 3 deletions tests/provider-capacity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ describe("configured-weight Codex pool capacity", () => {
expect(aggregateCodexPoolCapacity(rows(9), NOW).quota?.weeklyPercent).toBeCloseTo(39.33333333, 8);
});

test("legacy Team and Business plans share configured weight", () => {
const result = aggregateCodexPoolCapacity([
account("team", 20, { isMain: true, active: true }),
account("business", 60),
], NOW);
expect(result.quota?.weeklyPercent).toBe(40);
expect(result.aggregation).toMatchObject({
includedAccounts: 2,
excludedAccounts: 0,
unknownPlanAccounts: 0,
incomplete: false,
});
});

test("an all-Team pool has complete configured-weight coverage", () => {
const result = aggregateCodexPoolCapacity([
account("team", 20, { isMain: true, active: true }),
account("team", 60),
], NOW);
expect(result.quota?.weeklyPercent).toBe(40);
expect(result.aggregation).toMatchObject({
includedAccounts: 2,
excludedAccounts: 0,
unknownPlanAccounts: 0,
incomplete: false,
});
});

test("same-time resets group partial consumed capacity and expose only recovery percent", () => {
const result = aggregateCodexPoolCapacity([
account("pro", 25, { weeklyResetAt: NOW + 10_000 }),
Expand All @@ -66,7 +94,7 @@ describe("configured-weight Codex pool capacity", () => {
test("unknown, missing, paused, and reauth rows are excluded with incomplete coverage", () => {
const result = aggregateCodexPoolCapacity([
account("pro", 10, { active: true, isMain: true }),
account("team", 50),
account("future-plan", 50),
account("plus", undefined),
account("prolite", 20, { paused: true }),
account("business", 30, { needsReauth: true }),
Expand Down Expand Up @@ -109,7 +137,7 @@ describe("configured-weight Codex pool capacity", () => {
], NOW);
expect(expired.aggregation?.weekly).not.toHaveProperty("nextRecoveryAt");
const fallback = aggregateCodexPoolCapacity([
account("team", 70, { active: true, isMain: true }),
account("future-plan", 70, { active: true, isMain: true }),
account("go", 80),
], NOW);
expect(fallback.aggregation).toMatchObject({
Expand Down Expand Up @@ -209,7 +237,7 @@ describe("configured-weight Codex pool capacity", () => {
const stale = account("pro", 90);
stale.quota = { ...stale.quota!, updatedAt: NOW - CODEX_CAPACITY_MAX_QUOTA_AGE_MS - 1 };
const result = aggregateCodexPoolCapacity([
account("team", 10, { active: true, isMain: true }),
account("future-plan", 10, { active: true, isMain: true }),
account("plus", undefined),
account("prolite", 20, { paused: true }),
account("business", 30, { needsReauth: true }),
Expand Down
Loading