| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "amadan.net/oficina/equipo/internal/equipo/chat" |
| 7 | "amadan.net/oficina/equipo/internal/wire" |
| 8 | ) |
| 9 | |
| 10 | // Token figures read as people say them, and a sum with a missing |
| 11 | // figure says it is a lower bound, never a precise number. |
| 12 | func TestSpendWords(t *testing.T) { |
| 13 | for n, want := range map[int64]string{0: "0", 840: "840", 1000: "1k", 1500: "1.5k", 9960: "10k", 84_300: "84k", 999_499: "999k", 999_500: "1M", 1_240_000: "1.2M"} { |
| 14 | if got := tokenCount(n); got != want { |
| 15 | t.Fatalf("%d: %q, want %q", n, got, want) |
| 16 | } |
| 17 | } |
| 18 | task := wire.Task{Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering}, {ID: "s2", Specialist: wire.SpecialistChecks}, {ID: "s3", Specialist: wire.SpecialistEngineering, Round: 1}}} |
| 19 | sp := chat.TaskSpend{Rows: 3, Total: chat.Spend{Tokens: 50_000, Partial: true}, Steps: map[string]chat.Spend{"s1": {Tokens: 40_000, Cached: 30_000}, "s3": {Tokens: 9_000, Partial: true}}, Questions: chat.Spend{Tokens: 1_000}} |
| 20 | total, note, lines := spendOf(task, sp) |
| 21 | if total != "Used at least 50k tokens" || note != "" { |
| 22 | t.Fatalf("total %q", total) |
| 23 | } |
| 24 | want := []spendLine{{"s1", "Engineering: 40k tokens (30k cached)"}, {"s3", "Engineering, fix round 1: at least 9k tokens"}, {"questions", "Questions: 1k tokens"}} |
| 25 | if len(lines) != len(want) { |
| 26 | t.Fatalf("lines %+v", lines) |
| 27 | } |
| 28 | for i := range want { |
| 29 | if lines[i] != want[i] { |
| 30 | t.Fatalf("line %d %+v, want %+v", i, lines[i], want[i]) |
| 31 | } |
| 32 | } |
| 33 | if total, note, lines := spendOf(task, chat.TaskSpend{}); total != "" || note != "" || lines != nil { |
| 34 | t.Fatalf("no rows: %q %q %+v", total, note, lines) |
| 35 | } |
| 36 | // Rows left out because they overcount: said, never summed. |
| 37 | if total, note, lines := spendOf(task, chat.TaskSpend{LeftOut: true}); total != "" || note != "Earlier usage not shown" || lines != nil { |
| 38 | t.Fatalf("left out: %q %q %+v", total, note, lines) |
| 39 | } |
| 40 | } |
| 41 | |