package wire_test import ( "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) func TestTaskBranch(t *testing.T) { for _, tc := range []struct{ id, title, want string }{ {"tk0001", "Fix the iOS swipe-back bug!", "equipo/tk0001-fix-the-ios-swipe-back-bug"}, {"tk0002", " ¿Qué? ", "equipo/tk0002-qu"}, {"tk0003", "", "equipo/tk0003"}, {"tk0004", "---", "equipo/tk0004"}, {"tk0005", strings.Repeat("long word ", 20), "equipo/tk0005-long-word-long-word-long-word-long-word"}, // Cut at a word boundary, never mid-word. {"tk0006", "iOS edge swipe to go back doesn't work on account screens", "equipo/tk0006-ios-edge-swipe-to-go-back-doesn-t-work"}, {"tk0007", strings.Repeat("x", 50), "equipo/tk0007-" + strings.Repeat("x", 40)}, } { got := wire.TaskBranch(tc.id, tc.title) if got != tc.want || !wire.ValidTaskBranch(got) { t.Fatalf("TaskBranch(%q, %q) = %q (valid %v), want %q", tc.id, tc.title, got, wire.ValidTaskBranch(got), tc.want) } } 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)} { if wire.ValidTaskBranch(bad) { t.Fatalf("accepted %q", bad) } } } func TestStepFramesAreDurable(t *testing.T) { for _, kind := range []string{wire.FrameDispatch, wire.FrameCancelStep, wire.FrameStep, wire.FrameRecheck, wire.FrameWatchMerge, wire.FrameMerged, wire.FrameBranch} { if !(wire.Frame{Type: kind}).Durable() { t.Fatalf("%s is not durable", kind) } } } func TestTaskToolsAreConverseTools(t *testing.T) { for _, name := range []string{wire.ToolRecordTask, wire.ToolAddFinding, wire.ToolStartTask, wire.ToolReadTask, wire.ToolCancelTask} { found := false for _, n := range wire.ConverseTools { found = found || n == name } if !found { t.Fatalf("%s missing from ConverseTools", name) } } } // Asking the implementer: the question and its cancel go to the runner, // the answer comes back, and a task's end lets the runner forget its // sessions. All durable; the answer's streamed text rides the delta and // activity frames, which are not. func TestAskFramesAreDurable(t *testing.T) { for _, kind := range []string{wire.FrameAsk, wire.FrameCancelAsk, wire.FrameAnswer, wire.FrameForgetTask} { if !(wire.Frame{Type: kind}).Durable() { t.Fatalf("%s is not durable", kind) } } } func TestQuestionTerminal(t *testing.T) { for state, want := range map[string]bool{wire.QuestionQueued: false, wire.QuestionRunning: false, wire.QuestionAnswered: true, wire.QuestionFailed: true, wire.QuestionCancelled: true} { if wire.QuestionTerminal(state) != want { t.Fatalf("%s terminal=%v", state, !want) } } } // AddressesReview decides who answers when the person did not choose: // Review when they address it or ask about the review, else Engineering. func TestAddressesReview(t *testing.T) { for text, want := range map[string]bool{ "Review, anything you were unsure about?": true, "Why did the review approve this?": true, "What did the reviewer check?": true, "What did you change and why?": false, "Can you preview the page?": false, "": false, } { if wire.AddressesReview(text) != want { t.Fatalf("AddressesReview(%q) = %v", text, !want) } } } // Step activity lines are not durable: a lost line is only a lost line, // and the step's report carries what matters. func TestStepActivityIsNotDurable(t *testing.T) { if (wire.Frame{Type: wire.FrameStepActivity}).Durable() { t.Fatal("step_activity is durable") } }