@@ -119,13 +119,27 @@ func TestPlanCommandOnTwiceDoesNotClobberSavedMode(t *testing.T) { |
119 | 119 | } |
120 | 120 | } |
121 | 121 |
|
122 | | -// TestNextPermissionModeLeavesPlanUntouched confirms the shift+tab Auto<->Ask |
123 | | -// toggle cannot silently exit plan mode: folding Plan to Ask would be a LESS |
124 | | -// strict landing (Ask still permits write/shell tools with a prompt), so the |
125 | | -// read-only guarantee must only be given up via the explicit /plan off exit. |
| 122 | +// TestNextPermissionModeLeavesPlanUntouched confirms the shift+tab cycle cannot |
| 123 | +// silently exit plan mode: folding Plan to Ask would be a LESS strict landing |
| 124 | +// (Ask still permits write/shell tools with a prompt), so the read-only |
| 125 | +// guarantee must only be given up via the explicit /plan off exit. |
| 126 | +// |
| 127 | +// The second return value matters as much as the first. Plan must never carry a |
| 128 | +// full-auto OFFER either, or two presses from Plan would reach the one mode that |
| 129 | +// turns permission prompts off entirely, starting from the one mode that |
| 130 | +// promises no mutation at all. |
126 | 131 | func TestNextPermissionModeLeavesPlanUntouched(t *testing.T) { |
127 | | - if got := nextPermissionMode(agent.PermissionModePlan); got != agent.PermissionModePlan { |
128 | | - t.Fatalf("nextPermissionMode(Plan) = %s, want Plan unchanged", got) |
| 132 | + got, offered := advancePermissionMode(agent.PermissionModePlan, false) |
| 133 | + if got != agent.PermissionModePlan { |
| 134 | + t.Fatalf("advancePermissionMode(Plan) = %s, want Plan unchanged", got) |
| 135 | + } |
| 136 | + if offered { |
| 137 | + t.Fatal("shift+tab from Plan offered full-auto, so a second press would leave read-only mode for the least strict one") |
| 138 | + } |
| 139 | + // And from a live offer, which is the state a stray earlier press can leave |
| 140 | + // behind: still Plan, still no offer. |
| 141 | + if got, offered = advancePermissionMode(agent.PermissionModePlan, true); got != agent.PermissionModePlan || offered { |
| 142 | + t.Fatalf("advancePermissionMode(Plan, offered) = %s/%v, want Plan/false", got, offered) |
129 | 143 | } |
130 | 144 | } |
131 | 145 |
|
|