ScuttleBot

scuttlebot / pkg / toon / toon_test.go
Source Blame History 65 lines
a027855… noreply 1 package toon
a027855… noreply 2
a027855… noreply 3 import (
a027855… noreply 4 "strings"
a027855… noreply 5 "testing"
a027855… noreply 6 "time"
a027855… noreply 7 )
a027855… noreply 8
a027855… noreply 9 func TestFormatEmpty(t *testing.T) {
a027855… noreply 10 if got := Format(nil, Options{}); got != "" {
a027855… noreply 11 t.Errorf("expected empty, got %q", got)
a027855… noreply 12 }
a027855… noreply 13 }
a027855… noreply 14
a027855… noreply 15 func TestFormatBasic(t *testing.T) {
a027855… noreply 16 base := time.Date(2026, 4, 5, 12, 0, 0, 0, time.UTC)
a027855… noreply 17 entries := []Entry{
a027855… noreply 18 {Nick: "alice", Type: "op", Text: "let's ship it", At: base},
a027855… noreply 19 {Nick: "claude-abc", Type: "orch", MessageType: "task.create", Text: "editing main.go", At: base.Add(2 * time.Minute)},
a027855… noreply 20 {Nick: "claude-abc", Type: "orch", MessageType: "task.complete", Text: "done", At: base.Add(5 * time.Minute)},
a027855… noreply 21 }
a027855… noreply 22 out := Format(entries, Options{Channel: "#fleet"})
a027855… noreply 23
a027855… noreply 24 // Header.
a027855… noreply 25 if !strings.HasPrefix(out, "#fleet 3msg") {
a027855… noreply 26 t.Errorf("header mismatch: %q", out)
a027855… noreply 27 }
a027855… noreply 28 // Grouped consecutive messages from claude-abc.
a027855… noreply 29 if strings.Count(out, "claude-abc") != 1 {
a027855… noreply 30 t.Errorf("expected nick grouping, got:\n%s", out)
a027855… noreply 31 }
a027855… noreply 32 // Contains message types.
a027855… noreply 33 if !strings.Contains(out, "task.create") || !strings.Contains(out, "task.complete") {
a027855… noreply 34 t.Errorf("missing message types:\n%s", out)
a027855… noreply 35 }
a027855… noreply 36 }
a027855… noreply 37
a027855… noreply 38 func TestFormatPrompt(t *testing.T) {
a027855… noreply 39 entries := []Entry{{Nick: "a", Text: "hello"}}
a027855… noreply 40 out := FormatPrompt("#test", entries)
a027855… noreply 41 if !strings.Contains(out, "Summarize") {
a027855… noreply 42 t.Errorf("prompt missing instruction:\n%s", out)
a027855… noreply 43 }
a027855… noreply 44 if !strings.Contains(out, "#test") {
a027855… noreply 45 t.Errorf("prompt missing channel:\n%s", out)
a027855… noreply 46 }
a027855… noreply 47 }
a027855… noreply 48
a027855… noreply 49 func TestCompactDuration(t *testing.T) {
a027855… noreply 50 tests := []struct {
a027855… noreply 51 d time.Duration
a027855… noreply 52 want string
a027855… noreply 53 }{
a027855… noreply 54 {30 * time.Second, "30s"},
a027855… noreply 55 {5 * time.Minute, "5m"},
a027855… noreply 56 {2 * time.Hour, "2h"},
a027855… noreply 57 {2*time.Hour + 30*time.Minute, "2h30m"},
a027855… noreply 58 {48 * time.Hour, "2d"},
a027855… noreply 59 }
a027855… noreply 60 for _, tt := range tests {
a027855… noreply 61 if got := compactDuration(tt.d); got != tt.want {
a027855… noreply 62 t.Errorf("compactDuration(%v) = %q, want %q", tt.d, got, tt.want)
a027855… noreply 63 }
a027855… noreply 64 }
a027855… noreply 65 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button