oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire_test
2
3import (
4 "strings"
5 "testing"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10func TestTaskBranch(t *testing.T) {
11 for _, tc := range []struct{ id, title, want string }{
12 {"tk0001", "Fix the iOS swipe-back bug!", "equipo/tk0001-fix-the-ios-swipe-back-bug"},
13 {"tk0002", " ¿Qué? ", "equipo/tk0002-qu"},
14 {"tk0003", "", "equipo/tk0003"},
15 {"tk0004", "---", "equipo/tk0004"},
16 {"tk0005", strings.Repeat("long word ", 20), "equipo/tk0005-long-word-long-word-long-word-long-word"},
17 // Cut at a word boundary, never mid-word.
18 {"tk0006", "iOS edge swipe to go back doesn't work on account screens", "equipo/tk0006-ios-edge-swipe-to-go-back-doesn-t-work"},
19 {"tk0007", strings.Repeat("x", 50), "equipo/tk0007-" + strings.Repeat("x", 40)},
20 } {
21 got := wire.TaskBranch(tc.id, tc.title)
22 if got != tc.want || !wire.ValidTaskBranch(got) {
23 t.Fatalf("TaskBranch(%q, %q) = %q (valid %v), want %q", tc.id, tc.title, got, wire.ValidTaskBranch(got), tc.want)
24 }
25 }
26 for _, bad := range []string{"main", "equipo/", "equipo/../main", "equipo/a b", "refs/heads/equipo/x", "equipo/x-", "equipo/X", "equipo/x/y", "equipo/" + strings.Repeat("a", 100)} {
27 if wire.ValidTaskBranch(bad) {
28 t.Fatalf("accepted %q", bad)
29 }
30 }
31}
32
33func TestStepFramesAreDurable(t *testing.T) {
34 for _, kind := range []string{wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameBranch} {
35 if !(wire.Frame{Type: kind}).Durable() {
36 t.Fatalf("%s is not durable", kind)
37 }
38 }
39}
40
41func TestTaskToolsAreConverseTools(t *testing.T) {
42 for _, name := range []string{wire.ToolRecordTask, wire.ToolAddFinding, wire.ToolStartTask, wire.ToolReadTask, wire.ToolCancelTask} {
43 found := false
44 for _, n := range wire.ConverseTools {
45 found = found || n == name
46 }
47 if !found {
48 t.Fatalf("%s missing from ConverseTools", name)
49 }
50 }
51}
52
53// Asking the implementer: the question and its cancel go to the runner,
54// the answer comes back, and a task's end lets the runner forget its
55// sessions. All durable; the answer's streamed text rides the delta and
56// activity frames, which are not.
57func TestAskFramesAreDurable(t *testing.T) {
58 for _, kind := range []string{wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask} {
59 if !(wire.Frame{Type: kind}).Durable() {
60 t.Fatalf("%s is not durable", kind)
61 }
62 }
63}
64
65func TestQuestionTerminal(t *testing.T) {
66 for state, want := range map[string]bool{wire.QuestionQueued: false, wire.QuestionRunning: false, wire.QuestionAnswered: true, wire.QuestionFailed: true, wire.QuestionCancelled: true} {
67 if wire.QuestionTerminal(state) != want {
68 t.Fatalf("%s terminal=%v", state, !want)
69 }
70 }
71}
72
73// AddressesReview decides who answers when the person did not choose:
74// Review when they address it or ask about the review, else Engineering.
75func TestAddressesReview(t *testing.T) {
76 for text, want := range map[string]bool{
77 "Review, anything you were unsure about?": true,
78 "Why did the review approve this?": true,
79 "What did the reviewer check?": true,
80 "What did you change and why?": false,
81 "Can you preview the page?": false,
82 "": false,
83 } {
84 if wire.AddressesReview(text) != want {
85 t.Fatalf("AddressesReview(%q) = %v", text, !want)
86 }
87 }
88}
89
90// Step activity lines are not durable: a lost line is only a lost line,
91// and the step's report carries what matters.
92func TestStepActivityIsNotDurable(t *testing.T) {
93 if (wire.Frame{Type: wire.FrameStepActivity}).Durable() {
94 t.Fatal("step_activity is durable")
95 }
96}
97