-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
64 lines (57 loc) · 1.64 KB
/
Copy pathindex.test.ts
File metadata and controls
64 lines (57 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { describe, expect, test } from "bun:test";
import { toUsageReportLike } from "./index";
import { evaluateBlock } from "./predicate";
const NOW = 1_700_000_000_000;
describe("toUsageReportLike", () => {
test("maps a raw exhausted SDK report through evaluateBlock into an act:true decision", () => {
const resetsAt = NOW + 90 * 60_000;
const rawReport = {
provider: "anthropic",
fetchedAt: NOW,
limits: [
{
id: "anthropic:5h",
label: "5 Hour",
scope: { provider: "anthropic", windowId: "5h", tier: undefined },
window: { id: "5h", label: "5 Hour", resetsAt },
amount: { usedFraction: 0.999, unit: "percent" },
},
],
};
const decision = evaluateBlock({
nowMs: NOW,
activeProvider: "anthropic",
reports: toUsageReportLike([rawReport]),
handledEpisodes: new Set(),
});
expect(decision).toEqual({
act: true,
windowId: "5h",
resetsAt,
episodeKey: `5h:${resetsAt}`,
});
});
test("maps a raw below-threshold SDK report through evaluateBlock into a not-exhausted decision", () => {
const resetsAt = NOW + 90 * 60_000;
const rawReport = {
provider: "anthropic",
fetchedAt: NOW,
limits: [
{
id: "anthropic:5h",
label: "5 Hour",
scope: { provider: "anthropic", windowId: "5h", tier: undefined },
window: { id: "5h", label: "5 Hour", resetsAt },
amount: { usedFraction: 0.4, unit: "percent" },
},
],
};
const decision = evaluateBlock({
nowMs: NOW,
activeProvider: "anthropic",
reports: toUsageReportLike([rawReport]),
handledEpisodes: new Set(),
});
expect(decision).toEqual({ act: false, reason: "not-exhausted" });
});
});