Skip to content
45 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { AgentEffortCosts } from "@g1t/contracts";
5
6import { readEffort } from "./agent-form.ts";
7import { acceptedLabel, costAt, costLine, effortSetting, savingLabel, totalSaving } from "./effort.ts";
8
9const costs: AgentEffortCosts = {
10 handle: "reviewer",
11 effort: "high",
12 window_days: 28,
13 levels: [
14 { effort: "low", sessions: 0, typical_micros: null, accepted_share: null },
15 { effort: "medium", sessions: 1, typical_micros: 210_000, accepted_share: 1 },
16 { effort: "high", sessions: 14, typical_micros: 480_000, accepted_share: 13 / 14 },
17 { effort: "max", sessions: 0, typical_micros: null, accepted_share: null },
18 ],
19};
20
21test("a level's cost is what its sessions measured, and none where it never ran", () => {
22 assert.equal(costLine(costs, "high"), "$0.48 a typical task, from 14 sessions in the last 28 days");
23 assert.equal(costLine(costs, "medium"), "$0.21 a typical task, from 1 session in the last 28 days");
24 assert.equal(costLine(costs, "low"), "No sessions at Low in the last 28 days, so no figure yet.");
25 assert.equal(costLine(costs, "auto"), "$0.21 a typical task at Medium, from 1 session in the last 28 days");
26 assert.equal(costLine(null, "high"), "Costs couldn't be read right now.");
27 assert.equal(costAt(costs, "max"), null);
28 assert.equal(acceptedLabel(costAt(costs, "high")), "93%");
29});
30
31test("the setting reads from routing and the form, Auto when absent or unknown", () => {
32 assert.equal(effortSetting({ effort: "max" }), "max");
33 assert.equal(effortSetting({}), "auto");
34 assert.equal(effortSetting(null), "auto");
35 assert.equal(readEffort("low"), "low");
36 assert.equal(readEffort("turbo"), null);
37});
38
39test("savings add up from the open suggestions only", () => {
40 const rec = (status: "open" | "thin", saving: number | null) => ({ status, saving_month_micros: saving }) as never;
41 assert.equal(totalSaving({ checked_at: null, window_days: 28, open: [rec("open", 31_000_000), rec("open", 4_000_000)], thin: [rec("thin", null)], resolved: [] }), 35_000_000);
42 assert.equal(totalSaving(null), 0);
43 assert.equal(savingLabel({ saving_month_micros: 31_000_000 }), "About $31.00 a month");
44 assert.equal(savingLabel({ saving_month_micros: null }), "");
45});