summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/test
diff options
context:
space:
mode:
authorFrank <[email protected]>2026-03-03 00:25:03 -0500
committerFrank <[email protected]>2026-03-03 00:25:03 -0500
commit6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9 (patch)
treed0267534d1bd2e3331fc70ca177be4eef5d85530 /packages/console/app/test
parent9f150b07764c44ab5265d7cc2a3fa4e5909094b2 (diff)
downloadopencode-6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9.tar.gz
opencode-6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9.zip
wip: zen
Diffstat (limited to 'packages/console/app/test')
-rw-r--r--packages/console/app/test/rateLimiter.test.ts75
1 files changed, 1 insertions, 74 deletions
diff --git a/packages/console/app/test/rateLimiter.test.ts b/packages/console/app/test/rateLimiter.test.ts
index 864f907d6..5cc97dccf 100644
--- a/packages/console/app/test/rateLimiter.test.ts
+++ b/packages/console/app/test/rateLimiter.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
-import { getRetryAfterDay, getRetryAfterHour } from "../src/routes/zen/util/rateLimiter"
+import { getRetryAfterDay } from "../src/routes/zen/util/rateLimiter"
describe("getRetryAfterDay", () => {
test("returns full day at midnight UTC", () => {
@@ -17,76 +17,3 @@ describe("getRetryAfterDay", () => {
expect(getRetryAfterDay(almost)).toBe(1)
})
})
-
-describe("getRetryAfterHour", () => {
- // 14:30:00 UTC — 30 minutes into the current hour
- const now = Date.UTC(2026, 0, 15, 14, 30, 0, 0)
- const intervals = ["2026011514", "2026011513", "2026011512"]
-
- test("waits 3 hours when all usage is in current hour", () => {
- const rows = [{ interval: "2026011514", count: 10 }]
- // only current hour has usage — it won't leave the window for 3 hours from hour start
- // 3 * 3600 - 1800 = 9000s
- expect(getRetryAfterHour(rows, intervals, 10, now)).toBe(9000)
- })
-
- test("waits 1 hour when dropping oldest interval is sufficient", () => {
- const rows = [
- { interval: "2026011514", count: 2 },
- { interval: "2026011512", count: 10 },
- ]
- // total=12, drop oldest (-2h, count=10) -> 2 < 10
- // hours = 3 - 2 = 1 -> 1 * 3600 - 1800 = 1800s
- expect(getRetryAfterHour(rows, intervals, 10, now)).toBe(1800)
- })
-
- test("waits 2 hours when usage spans oldest two intervals", () => {
- const rows = [
- { interval: "2026011513", count: 8 },
- { interval: "2026011512", count: 5 },
- ]
- // total=13, drop -2h (5) -> 8, 8 >= 8, drop -1h (8) -> 0 < 8
- // hours = 3 - 1 = 2 -> 2 * 3600 - 1800 = 5400s
- expect(getRetryAfterHour(rows, intervals, 8, now)).toBe(5400)
- })
-
- test("waits 1 hour when oldest interval alone pushes over limit", () => {
- const rows = [
- { interval: "2026011514", count: 1 },
- { interval: "2026011513", count: 1 },
- { interval: "2026011512", count: 10 },
- ]
- // total=12, drop -2h (10) -> 2 < 10
- // hours = 3 - 2 = 1 -> 1800s
- expect(getRetryAfterHour(rows, intervals, 10, now)).toBe(1800)
- })
-
- test("waits 2 hours when middle interval keeps total over limit", () => {
- const rows = [
- { interval: "2026011514", count: 4 },
- { interval: "2026011513", count: 4 },
- { interval: "2026011512", count: 4 },
- ]
- // total=12, drop -2h (4) -> 8, 8 >= 5, drop -1h (4) -> 4 < 5
- // hours = 3 - 1 = 2 -> 5400s
- expect(getRetryAfterHour(rows, intervals, 5, now)).toBe(5400)
- })
-
- test("rounds up to nearest second", () => {
- const offset = Date.UTC(2026, 0, 15, 14, 30, 0, 500)
- const rows = [
- { interval: "2026011514", count: 2 },
- { interval: "2026011512", count: 10 },
- ]
- // hours=1 -> 3_600_000 - 1_800_500 = 1_799_500ms -> ceil(1799.5) = 1800
- expect(getRetryAfterHour(rows, intervals, 10, offset)).toBe(1800)
- })
-
- test("fallback returns time until next hour when rows are empty", () => {
- // edge case: rows empty but function called (shouldn't happen in practice)
- // loop drops all zeros, running stays 0 which is < any positive limit on first iteration
- const rows: { interval: string; count: number }[] = []
- // drop -2h (0) -> 0 < 1 -> hours = 3 - 2 = 1 -> 1800s
- expect(getRetryAfterHour(rows, intervals, 1, now)).toBe(1800)
- })
-})