Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { effortBarHeights, resolveEffortGlyph } from "./EffortGlyph";
4
5const descriptor = (ids: ReadonlyArray<string>, promptInjectedValues?: ReadonlyArray<string>) => ({
6 id: "effort",
7 label: "Reasoning",
8 type: "select" as const,
9 options: ids.map((id) => ({ id, label: id[0]!.toUpperCase() + id.slice(1) })),
10 ...(promptInjectedValues ? { promptInjectedValues } : {}),
11});
12
13describe("resolveEffortGlyph", () => {
14 const claude = descriptor(
15 ["low", "medium", "high", "xhigh", "max", "ultracode", "ultrathink"],
16 ["ultrathink"],
17 );
18
19 const codex = descriptor(["low", "medium", "high", "xhigh", "max", "ultra"]);
20
21 it("fills bars up to the current level and leaves max and workflow levels off the scale", () => {
22 for (const model of [claude, codex]) {
23 expect(resolveEffortGlyph(model, "xhigh")).toEqual({
24 count: 4,
25 filled: 4,
26 special: null,
27 label: "Xhigh",
28 });
29 }
30 });
31
32 it("names Max, Default, and Ultra instead of drawing them", () => {
33 expect(resolveEffortGlyph(claude, "max")?.special).toBe("Max");
34 const reported = descriptor(["default", "low", "medium", "high", "xhigh", "max"]);
35 expect(resolveEffortGlyph(reported, "default")?.special).toBe("Default");
36 expect(resolveEffortGlyph(reported, "low")).toMatchObject({ count: 4, filled: 1 });
37 expect(resolveEffortGlyph(codex, "ultra")?.special).toBe("Ultra");
38 });
39
40 it("names Ultracode and Ultrathink instead of drawing a level", () => {
41 expect(resolveEffortGlyph(claude, "ultracode")?.special).toBe("Ultracode");
42 expect(resolveEffortGlyph(claude, "ultrathink")?.special).toBe("Ultrathink");
43 });
44
45 it("draws the lowest level as one bar, and an off level as none", () => {
46 expect(resolveEffortGlyph(claude, "low")).toMatchObject({ count: 4, filled: 1 });
47 expect(resolveEffortGlyph(claude, "medium")).toMatchObject({ count: 4, filled: 2 });
48 expect(resolveEffortGlyph(descriptor(["off", "low", "high"]), "off")).toEqual({
49 count: 2,
50 filled: 0,
51 special: null,
52 label: "Off",
53 });
54 });
55
56 it("falls back to the word when the value is unknown or the scale is too short or long", () => {
57 expect(resolveEffortGlyph(claude, "unknown")).toBeNull();
58 expect(resolveEffortGlyph(descriptor(["high"]), "high")).toBeNull();
59 const levels = Array.from({ length: 8 }, (_, index) => `level${index}`);
60 expect(resolveEffortGlyph(descriptor(levels), "level0")).toBeNull();
61 });
62});
63
64describe("effortBarHeights", () => {
65 it.each([3, 4, 5, 6, 7])(
66 "rises by one whole-pixel step and ends at full height: %i bars",
67 (count) => {
68 const heights = effortBarHeights(count, 12);
69 expect(heights).toHaveLength(count);
70 expect(heights.at(-1)).toBe(12);
71 const steps = new Set(heights.slice(1).map((height, index) => height - heights[index]!));
72 expect(steps.size).toBe(1);
73 const [step] = steps;
74 expect(Number.isInteger(step) && step! > 0).toBe(true);
75 },
76 );
77});