@@ -157,7 +157,7 @@ func TestUnstack_NoStackID_WarnsAndSkipsAPI(t *testing.T) {
157157 assert .NotContains (t , output , "Stack deleted on GitHub" )
158158}
159159
160- func TestUnstack_API404_ShowsErrorAndStopsLocalDeletion (t * testing.T ) {
160+ func TestUnstack_API404_TreatedAsIdempotentSuccess (t * testing.T ) {
161161 gitDir := t .TempDir ()
162162 restore := git .SetOps (& git.MockOps {
163163 GitDirFn : func () (string , error ) { return gitDir , nil },
@@ -180,15 +180,14 @@ func TestUnstack_API404_ShowsErrorAndStopsLocalDeletion(t *testing.T) {
180180 err := runUnstack (cfg , & unstackOptions {})
181181 output := collectOutput (cfg , outR , errR )
182182
183- assert . ErrorIs ( t , err , ErrAPIFailure )
184- assert . Contains (t , output , "Failed to delete stack on GitHub (HTTP 404)" )
185- // Should NOT remove locally when remote fails
186- assert .NotContains (t , output , "Stack removed from local tracking" )
183+ // 404 means already deleted — should succeed and remove locally
184+ require . NoError (t , err )
185+ assert . Contains ( t , output , "continuing with local unstack" )
186+ assert .Contains (t , output , "Stack removed from local tracking" )
187187
188- // Stack should still exist locally
189188 sf , err := stack .Load (gitDir )
190189 require .NoError (t , err )
191- require . Len (t , sf .Stacks , 1 )
190+ assert . Empty (t , sf .Stacks )
192191}
193192
194193func TestUnstack_API409_ShowsErrorAndStopsLocalDeletion (t * testing.T ) {
@@ -224,3 +223,37 @@ func TestUnstack_API409_ShowsErrorAndStopsLocalDeletion(t *testing.T) {
224223 require .NoError (t , err )
225224 require .Len (t , sf .Stacks , 1 )
226225}
226+
227+ func TestUnstack_RemovesCorrectStackByPointer (t * testing.T ) {
228+ // Two stacks share the same trunk "main". Targeting "b3" should remove
229+ // only the second stack (b3,b4), leaving the first (b1,b2) intact.
230+ // This verifies pointer-based removal instead of branch-name-based.
231+ gitDir := t .TempDir ()
232+ restore := git .SetOps (& git.MockOps {
233+ GitDirFn : func () (string , error ) { return gitDir , nil },
234+ CurrentBranchFn : func () (string , error ) { return "b3" , nil },
235+ })
236+ defer restore ()
237+
238+ s1 := stack.Stack {
239+ Trunk : stack.BranchRef {Branch : "main" },
240+ Branches : []stack.BranchRef {{Branch : "b1" }, {Branch : "b2" }},
241+ }
242+ s2 := stack.Stack {
243+ Trunk : stack.BranchRef {Branch : "main" },
244+ Branches : []stack.BranchRef {{Branch : "b3" }, {Branch : "b4" }},
245+ }
246+ writeTwoStacks (t , gitDir , s1 , s2 )
247+
248+ cfg , outR , errR := config .NewTestConfig ()
249+ err := runUnstack (cfg , & unstackOptions {target : "b3" , local : true })
250+ output := collectOutput (cfg , outR , errR )
251+
252+ require .NoError (t , err )
253+ assert .Contains (t , output , "Stack removed from local tracking" )
254+
255+ sf , err := stack .Load (gitDir )
256+ require .NoError (t , err )
257+ require .Len (t , sf .Stacks , 1 , "should remove exactly one stack" )
258+ assert .Equal (t , []string {"b1" , "b2" }, sf .Stacks [0 ].BranchNames (), "should keep the OTHER stack intact" )
259+ }
0 commit comments