| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | tea "charm.land/bubbletea/v2" |
| 7 | |
| 8 | "reasonix/internal/control" |
| 9 | ) |
| 10 | |
| 11 | func TestShiftTabCyclesReadWorkspaceYoloPlan(t *testing.T) { |
| 12 | m := newTestChatTUI() |
| 13 | m.ctrl = newOwnedTestController(t, control.Options{}) |
| 14 | m.ctrl.SetGoal("leave goal before plan") |
| 15 | key := tea.KeyPressMsg{Code: tea.KeyTab, Mod: tea.ModShift} |
| 16 | want := []struct { |
| 17 | mode string |
| 18 | plan bool |
| 19 | label string |
| 20 | }{{control.ToolApprovalWorkspaceWrite, false, "Goal+Workspace"}, {control.ToolApprovalDangerFullAccess, false, "Goal+YOLO"}, {control.ToolApprovalReadOnly, true, "Plan"}, {control.ToolApprovalReadOnly, false, "Read only"}} |
| 21 | for i, step := range want { |
| 22 | out, _ := m.Update(key) |
| 23 | m = out.(chatTUI) |
| 24 | if got := m.ctrl.ToolApprovalMode(); got != step.mode || m.planMode != step.plan || m.ctrl.PlanMode() != step.plan { |
| 25 | t.Fatalf("Shift+Tab step %d = mode %q plan %v/%v, want %q/%v", i+1, got, m.planMode, m.ctrl.PlanMode(), step.mode, step.plan) |
| 26 | } |
| 27 | if got := m.modeTagText(); got != step.label { |
| 28 | t.Fatalf("Shift+Tab step %d label = %q, want %q", i+1, got, step.label) |
| 29 | } |
| 30 | } |
| 31 | if got := m.ctrl.Goal(); got != "" { |
| 32 | t.Fatalf("entering Plan kept Goal %q", got) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestCtrlYRestoresWorkspaceAfterShiftTabYolo(t *testing.T) { |
| 37 | m := newTestChatTUI() |
| 38 | m.ctrl = newOwnedTestController(t, control.Options{}) |
| 39 | for range 2 { |
| 40 | out, _ := m.Update(tea.KeyPressMsg{Code: tea.KeyTab, Mod: tea.ModShift}) |
| 41 | m = out.(chatTUI) |
| 42 | } |
| 43 | out, _ := m.Update(tea.KeyPressMsg{Code: 'y', Mod: tea.ModCtrl}) |
| 44 | m = out.(chatTUI) |
| 45 | if got := m.ctrl.ToolApprovalMode(); got != control.ToolApprovalWorkspaceWrite { |
| 46 | t.Fatalf("Ctrl+Y restore after Shift+Tab = %q, want workspace-write", got) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestCtrlYTogglesYoloWithoutLeavingPlan(t *testing.T) { |
| 51 | m := newTestChatTUI() |
| 52 | m.ctrl = newOwnedTestController(t, control.Options{}) |
| 53 | m.planMode = true |
| 54 | m.ctrl.SetPlanMode(true) |
| 55 | key := tea.KeyPressMsg{Code: 'y', Mod: tea.ModCtrl} |
| 56 | for i, mode := range []string{control.ToolApprovalDangerFullAccess, control.ToolApprovalReadOnly} { |
| 57 | out, _ := m.Update(key) |
| 58 | m = out.(chatTUI) |
| 59 | if got := m.ctrl.ToolApprovalMode(); got != mode || !m.planMode || !m.ctrl.PlanMode() { |
| 60 | t.Fatalf("Ctrl+Y step %d in Plan = mode %q plan %v/%v, want %q/true", i+1, got, m.planMode, m.ctrl.PlanMode(), mode) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 |