GeezerVison is showing github.com — fix: invalidate full-auto offers at BTW session boundaries · Twigpine/zero@535a80b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: internal/cli/root_flag_order_test.go +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,8 +35,8 @@ func rootFlagOrderings(groups [][]string) [][]string { | 35 | 35 | // order the operator wrote them in load-bearing: `zero --allow-escalation | 36 | 36 | // --theme auto` stranded `--theme auto` as an unknown command and exited with | 37 | 37 | // an argument error instead of launching. Every ordering of the three root | 38 | | -// flags, with --skip-permissions-unsafe absent or at any position, has to reach | 39 | | -// the TUI with all three applied. | | 38 | +// flags, with either spelling of --full-auto at any position or omitted, has | | 39 | +// to reach the TUI with all three applied. | 40 | 40 | func TestRootFlagsComposeInAnyOrder(t *testing.T) { | 41 | 41 | extra := t.TempDir() | 42 | 42 | resolvedExtra, err := filepath.EvalSymlinks(extra) | @@ -45,16 +45,18 @@ func TestRootFlagsComposeInAnyOrder(t *testing.T) { | 45 | 45 | } | 46 | 46 | groups := [][]string{{"--add-dir", extra}, {"--theme", "auto"}, {"--allow-escalation"}} | 47 | 47 | cases := rootFlagOrderings(groups) | 48 | | - cases = append(cases, rootFlagOrderings(append(groups, []string{"--skip-permissions-unsafe"}))...) | 49 | | - if len(cases) != 6+24 { | 50 | | - t.Fatalf("SETUP INVALID: %d orderings, want 30", len(cases)) | | 48 | + for _, flag := range []string{"--full-auto", "--skip-permissions-unsafe"} { | | 49 | + cases = append(cases, rootFlagOrderings(append(groups, []string{flag}))...) | | 50 | + } | | 51 | + if len(cases) != 6+2*24 { | | 52 | + t.Fatalf("SETUP INVALID: %d orderings, want 54", len(cases)) | 51 | 53 | } | 52 | 54 | for _, args := range cases { | 53 | 55 | t.Run(strings.Join(args, " "), func(t *testing.T) { | 54 | 56 | options := captureTUIOptions(t, args...) | 55 | 57 | wantMode := agent.PermissionModeAsk | 56 | 58 | for _, arg := range args { | 57 | | - if arg == "--skip-permissions-unsafe" { | | 59 | + if arg == "--full-auto" || arg == "--skip-permissions-unsafe" { | 58 | 60 | wantMode = agent.PermissionModeFullAuto | 59 | 61 | } | 60 | 62 | } | |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/btw.go +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,6 +73,9 @@ func (m model) handleBTWCommand(question string) (model, tea.Cmd) { | 73 | 73 | // Foreground loops are session-scoped. Stop them only after the side session | 74 | 74 | // is ready, so a failed fork cannot destroy work in the main session. | 75 | 75 | parent := m | | 76 | + // The offer belongs to the foreground surface. Clear it before copying the | | 77 | + // side model so neither the fork nor the saved parent can carry it forward. | | 78 | + parent.unsafeArmed = false | 76 | 79 | clearedLoops := 0 | 77 | 80 | if updated, cleared := parent.clearLoopsForSessionSwitch(); cleared > 0 { | 78 | 81 | parent = updated | @@ -344,6 +347,9 @@ func (m model) refreshHiddenParentFileView() (model, tea.Cmd) { | 344 | 347 | } | 345 | 348 |
| 346 | 349 | func (m model) routeBTWMessageToParent(msg tea.Msg) (model, tea.Cmd, bool) { | | 350 | + // Cross-session delivery ends the offer on the visible side. The hidden | | 351 | + // parent's update cannot clear the side model's confirmation state. | | 352 | + m.unsafeArmed = false | 347 | 353 | parentNext, cmd := m.btw.parent.updateModel(msg) | 348 | 354 | parent, ok := parentNext.(model) | 349 | 355 | if !ok { | |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/btw_test.go +90Lines changed: 90 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ import ( | 11 | 11 |
| 12 | 12 | tea "charm.land/bubbletea/v2" | 13 | 13 |
| | 14 | + "github.com/Twigpine/zero/internal/agent" | 14 | 15 | "github.com/Twigpine/zero/internal/config" | 15 | 16 | "github.com/Twigpine/zero/internal/notify" | 16 | 17 | "github.com/Twigpine/zero/internal/sessions" | @@ -113,6 +114,95 @@ func TestBTWCreatesIsolatedForkAndReturnsWithoutMerge(t *testing.T) { | 113 | 114 | } | 114 | 115 | } | 115 | 116 |
| | 117 | +func TestBTWForkDiscardsFullAutoOffer(t *testing.T) { | | 118 | + main := newBTWTestModel(t) | | 119 | + main.width = 96 | | 120 | + main.permissionMode = agent.PermissionModeAsk | | 121 | + main = pressKey(t, main, tea.Key(testKeyShift(tea.KeyTab))) | | 122 | + if !main.offerOwnsStatusChip() { | | 123 | + t.Fatal("expected a live full-auto offer on main") | | 124 | + } | | 125 | + | | 126 | + // Test the fork boundary directly. The Enter key would clear the offer | | 127 | + // before calling it, masking an offer copied into the fork or saved parent. | | 128 | + side, _ := main.handleBTWCommand("") | | 129 | + if !side.btw.active || side.btw.parent == nil { | | 130 | + t.Fatal("expected a BTW fork") | | 131 | + } | | 132 | + confirmed, _ := side.Update(testKeyCtrl('g')) | | 133 | + if got := confirmed.(model).permissionMode; got != agent.PermissionModeAsk { | | 134 | + t.Errorf("Ctrl+G after forking = %s, want ask", got) | | 135 | + } | | 136 | + restored, _ := side.Update(testKeyCtrl('c')) | | 137 | + if restored.(model).btw.active { | | 138 | + t.Fatal("expected Ctrl+C to restore main") | | 139 | + } | | 140 | + confirmed, _ = restored.Update(testKeyCtrl('g')) | | 141 | + if got := confirmed.(model).permissionMode; got != agent.PermissionModeAsk { | | 142 | + t.Errorf("Ctrl+G after restoring main = %s, want ask", got) | | 143 | + } | | 144 | +} | | 145 | + | | 146 | +func TestBTWParentDeliveryCancelsFullAutoOffer(t *testing.T) { | | 147 | + const mainRunID = 7 | | 148 | + for _, tc := range []struct { | | 149 | + name string | | 150 | + msg tea.Msg | | 151 | + parentNeedsInput bool | | 152 | + }{ | | 153 | + { | | 154 | + name: "completion", | | 155 | + msg: agentResponseMsg{runID: mainRunID}, | | 156 | + }, | | 157 | + { | | 158 | + name: "permission request", | | 159 | + msg: permissionRequestMsg{ | | 160 | + runID: mainRunID, | | 161 | + request: testPromptPermissionRequest(), | | 162 | + }, | | 163 | + parentNeedsInput: true, | | 164 | + }, | | 165 | + } { | | 166 | + t.Run(tc.name, func(t *testing.T) { | | 167 | + main := newBTWTestModel(t) | | 168 | + main.width = 96 | | 169 | + main.permissionMode = agent.PermissionModeAsk | | 170 | + main.runID, main.activeRunID, main.pending = mainRunID, mainRunID, true | | 171 | + side, _ := main.handleBTWCommand("") | | 172 | + if !side.btw.active || side.btw.parent == nil { | | 173 | + t.Fatal("expected a BTW fork with main still running") | | 174 | + } | | 175 | + updated, _ := side.Update(testKeyShift(tea.KeyTab)) | | 176 | + side = updated.(model) | | 177 | + if !side.offerOwnsStatusChip() { | | 178 | + t.Fatal("expected a live full-auto offer in BTW") | | 179 | + } | | 180 | + | | 181 | + updated, _ = side.Update(tc.msg) | | 182 | + side = updated.(model) | | 183 | + parent := side.btw.parent | | 184 | + if parent == nil || parent.pending != tc.parentNeedsInput || | | 185 | + (parent.pendingPermission != nil) != tc.parentNeedsInput { | | 186 | + t.Fatal("delivery did not update the hidden main session") | | 187 | + } | | 188 | + if side.pendingPermission != nil { | | 189 | + t.Fatal("main permission prompt leaked into BTW") | | 190 | + } | | 191 | + updated, _ = side.Update(testKeyCtrl('g')) | | 192 | + side = updated.(model) | | 193 | + if side.permissionMode != agent.PermissionModeAsk { | | 194 | + t.Fatalf("Ctrl+G after main delivery = %s, want ask", side.permissionMode) | | 195 | + } | | 196 | + | | 197 | + updated, _ = side.Update(testKeyShift(tea.KeyTab)) | | 198 | + updated, _ = updated.Update(testKeyCtrl('g')) | | 199 | + if got := updated.(model).permissionMode; got != agent.PermissionModeFullAuto { | | 200 | + t.Errorf("Ctrl+G after a fresh BTW offer = %s, want full-auto", got) | | 201 | + } | | 202 | + }) | | 203 | + } | | 204 | +} | | 205 | + | 116 | 206 | func TestBTWCanOpenWhileParentRunContinues(t *testing.T) { | 117 | 207 | m := newBTWTestModel(t) | 118 | 208 | m.pending = true | |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/model.go +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1494,7 +1494,8 @@ func (m model) updateModel(msg tea.Msg) (tea.Model, tea.Cmd) { | 1494 | 1494 | if next, cmd, routed := m.routeBTWParentMessage(msg); routed { | 1495 | 1495 | return next, batchCommands(cmd, resizeCmd) | 1496 | 1496 | } | 1497 | | - // CROSS-SESSION TRAFFIC ENDS A FULL-AUTO OFFER, every kind of it. | | 1497 | + // CROSS-SESSION TRAFFIC ENDS A FULL-AUTO OFFER. BTW parent deliveries | | 1498 | + // are handled by the router above. Peer deliveries continue here. | 1498 | 1499 | // | 1499 | 1500 | // The offer is valid only until the next user-visible input transition, | 1500 | 1501 | // whatever delivers it (see sttPartialMsg below). Paste, blur, mouse, the | |
|