100milionseek 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import { quotaWindow, planOf, resetInstant, nextUtcMidnight, BASE_DAILY_TOKENS } from "../src/quota.mjs";
5
+
6
+ const headers = (pairs) => new Headers(pairs);
7
+
8
+ test("quotaWindow reads the four quota headers into one daily window", () => {
9
+ const now = Date.parse("2026-11-25T10:00:00Z");
10
+ const w = quotaWindow(
11
+ headers({
12
+ "x-quota-limit": "100000000",
13
+ "x-quota-used": "25000000",
14
+ "x-quota-remaining": "75000000",
15
+ "x-quota-reset": "2026-11-26T00:00:00Z",
16
+ }),
17
+ now,
18
+ );
19
+ assert.equal(w.name, "Tokens today (UTC)");
20
+ assert.equal(w.span, 86400);
21
+ assert.equal(w.unit, "tokens");
22
+ assert.equal(w.limit, 100_000_000);
23
+ assert.equal(w.amount, 25_000_000);
24
+ assert.equal(w.used, 25);
25
+ assert.equal(w.resetsAt, "2026-11-26T00:00:00.000Z");
26
+ });
27
+
28
+ test("quotaWindow derives the spend from limit and remaining", () => {
29
+ const w = quotaWindow(
30
+ headers({ "x-quota-limit": "2000000", "x-quota-remaining": "500000" }),
31
+ Date.parse("2026-11-25T10:00:00Z"),
32
+ );
33
+ assert.equal(w.limit, 2_000_000);
34
+ assert.equal(w.amount, 1_500_000);
35
+ assert.equal(w.used, 75);
36
+ });
37
+
38
+ test("quotaWindow leaves used out rather than reporting zero when the spend is unknown", () => {
39
+ const w = quotaWindow(headers({ "x-quota-limit": "100000000" }));
40
+ assert.equal(w.limit, 100_000_000);
41
+ assert.equal("used" in w, false);
42
+ assert.equal(w.amount, undefined);
43
+ assert.match(w.display, /100,000,000 tokens a day/);
44
+ });
45
+
46
+ test("quotaWindow reports a spend without a limit as a display line, not a percentage", () => {
47
+ const w = quotaWindow(headers({ "x-quota-used": "1234" }));
48
+ assert.equal("used" in w, false);
49
+ assert.equal(w.amount, 1234);
50
+ assert.match(w.display, /1,234 tokens used today/);
51
+ });
52
+
53
+ test("quotaWindow says nothing when the response said nothing", () => {
54
+ assert.equal(quotaWindow(headers({ "x-qos": "full" })), undefined);
55
+ });
56
+
57
+ test("quotaWindow allows the percentage to pass 100 once the day is spent", () => {
58
+ const w = quotaWindow(headers({ "x-quota-limit": "1000", "x-quota-used": "1500" }));
59
+ assert.equal(w.used, 150);
60
+ });
61
+
62
+ test("quotaWindow ignores unreadable counts instead of turning them into zero", () => {
63
+ const w = quotaWindow(headers({ "x-quota-limit": "lots", "x-quota-used": "10" }));
64
+ assert.equal(w.limit, undefined);
65
+ assert.equal(w.amount, 10);
66
+ assert.equal("used" in w, false);
67
+ });
68
+
69
+ test("resetInstant falls back to the next 00:00 UTC", () => {
70
+ const now = Date.parse("2026-11-25T23:59:59Z");
71
+ assert.equal(resetInstant(undefined, now).toISOString(), "2026-11-26T00:00:00.000Z");
72
+ assert.equal(resetInstant("not a date", now).toISOString(), "2026-11-26T00:00:00.000Z");
73
+ assert.equal(resetInstant("2026-11-27T00:00:00Z", now).toISOString(), "2026-11-27T00:00:00.000Z");
74
+ });
75
+
76
+ test("nextUtcMidnight always moves forward", () => {
77
+ assert.equal(nextUtcMidnight(Date.parse("2026-11-25T00:00:00Z")).toISOString(), "2026-11-26T00:00:00.000Z");
78
+ assert.equal(nextUtcMidnight(Date.parse("2026-11-25T00:00:01Z")).toISOString(), "2026-11-26T00:00:00.000Z");
79
+ });
80
+
81
+ test("planOf names the allowance the limit actually shows", () => {
82
+ assert.equal(planOf({ limit: BASE_DAILY_TOKENS }), "Free");
83
+ assert.equal(planOf({ limit: 150_000_000 }), "Raised allowance (150,000,000/day)");
84
+ assert.equal(planOf({}), "Free");
85
+ assert.equal(planOf(undefined), "Free");
86
+ });
@@ -0,0 +1,69 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import { normalizeSystemOne } from "../src/systemone.mjs";
5
+
6
+ test("an answer body that is already in magpie's shape is left as it is", () => {
7
+ const body = {
8
+ model: "jev-1.13-free",
9
+ answers: { "is this a coding task?": { choice: "yes", score: 0.91, confidence: 0.8 } },
10
+ };
11
+ assert.deepEqual(normalizeSystemOne(body, ["is this a coding task?"]), body);
12
+ });
13
+
14
+ test("probability per question becomes a score", () => {
15
+ const body = { model: "jev-1.13-free", answers: { q1: 0.75, q2: 0.1 } };
16
+ const out = normalizeSystemOne(body, ["q1", "q2"]);
17
+ assert.deepEqual(out.answers, { q1: { score: 0.75 }, q2: { score: 0.1 } });
18
+ assert.equal(out.model, "jev-1.13-free");
19
+ });
20
+
21
+ test("the vendor's own probability names are renamed", () => {
22
+ const body = { answers: { q1: { probability: 0.4 }, q2: { p: "0.6" }, q3: { value: 1 } } };
23
+ assert.deepEqual(normalizeSystemOne(body, []).answers, {
24
+ q1: { score: 0.4 },
25
+ q2: { score: 0.6 },
26
+ q3: { score: 1 },
27
+ });
28
+ });
29
+
30
+ test("a bare list of probabilities is paired with the questions asked", () => {
31
+ const body = { answers: [0.2, 0.9] };
32
+ assert.deepEqual(normalizeSystemOne(body, ["a", "b"]).answers, {
33
+ a: { score: 0.2 },
34
+ b: { score: 0.9 },
35
+ });
36
+ });
37
+
38
+ test("rows that name their own question are read by name", () => {
39
+ const body = {
40
+ results: [
41
+ { question: "a", probability: 0.3 },
42
+ { id: "b", score: 0.7 },
43
+ { name: "c", value: 0.5 },
44
+ ],
45
+ };
46
+ assert.deepEqual(normalizeSystemOne(body, []).answers, {
47
+ a: { score: 0.3 },
48
+ b: { score: 0.7 },
49
+ c: { score: 0.5 },
50
+ });
51
+ });
52
+
53
+ test("probability maps under other keys are read too", () => {
54
+ const body = { probabilities: { a: 0.11 } };
55
+ assert.deepEqual(normalizeSystemOne(body, []).answers, { a: { score: 0.11 } });
56
+ });
57
+
58
+ test("an unrecognised body passes through untouched", () => {
59
+ const error = { error: { message: "model_not_found" } };
60
+ assert.deepEqual(normalizeSystemOne(error, ["a"]), error);
61
+ const odd = { answers: { a: { unexpected: true } } };
62
+ assert.deepEqual(normalizeSystemOne(odd, ["a"]), odd);
63
+ });
64
+
65
+ test("a body that is not an object is returned as it came", () => {
66
+ assert.equal(normalizeSystemOne("nope", []), "nope");
67
+ assert.equal(normalizeSystemOne(null, []), null);
68
+ assert.deepEqual(normalizeSystemOne([1, 2], []), [1, 2]);
69
+ });