@@ -321,6 +321,117 @@ func TestAdd_NothingToCommit(t *testing.T) {
321321 assert .Contains (t , output , "no changes to commit" )
322322}
323323
324+ func TestAdd_PromptPrefillsPrefix (t * testing.T ) {
325+ gitDir := t .TempDir ()
326+ saveStack (t , gitDir , stack.Stack {
327+ Prefix : "feat" ,
328+ Trunk : stack.BranchRef {Branch : "main" },
329+ Branches : []stack.BranchRef {{Branch : "feat/01" }},
330+ })
331+
332+ var createdBranch string
333+ restore := git .SetOps (& git.MockOps {
334+ GitDirFn : func () (string , error ) { return gitDir , nil },
335+ CurrentBranchFn : func () (string , error ) { return "feat/01" , nil },
336+ CreateBranchFn : func (name , base string ) error {
337+ createdBranch = name
338+ return nil
339+ },
340+ CheckoutBranchFn : func (name string ) error { return nil },
341+ RevParseFn : func (ref string ) (string , error ) { return "abc" , nil },
342+ })
343+ defer restore ()
344+
345+ cfg , outR , errR := config .NewTestConfig ()
346+
347+ var gotDefault string
348+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
349+ gotDefault = defaultValue
350+ return "feat/my-branch" , nil
351+ }
352+
353+ err := runAdd (cfg , & addOptions {}, nil )
354+ output := collectOutput (cfg , outR , errR )
355+
356+ require .NoError (t , err )
357+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
358+ assert .Equal (t , "feat/" , gotDefault , "prompt should pre-fill prefix/" )
359+ assert .Equal (t , "feat/my-branch" , createdBranch , "full input should be used as branch name" )
360+ }
361+
362+ func TestAdd_PromptNoPrefixEmptyDefault (t * testing.T ) {
363+ gitDir := t .TempDir ()
364+ saveStack (t , gitDir , stack.Stack {
365+ Trunk : stack.BranchRef {Branch : "main" },
366+ Branches : []stack.BranchRef {{Branch : "b1" }},
367+ })
368+
369+ var createdBranch string
370+ restore := git .SetOps (& git.MockOps {
371+ GitDirFn : func () (string , error ) { return gitDir , nil },
372+ CurrentBranchFn : func () (string , error ) { return "b1" , nil },
373+ CreateBranchFn : func (name , base string ) error {
374+ createdBranch = name
375+ return nil
376+ },
377+ CheckoutBranchFn : func (name string ) error { return nil },
378+ RevParseFn : func (ref string ) (string , error ) { return "abc" , nil },
379+ })
380+ defer restore ()
381+
382+ cfg , outR , errR := config .NewTestConfig ()
383+
384+ var gotDefault string
385+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
386+ gotDefault = defaultValue
387+ return "my-branch" , nil
388+ }
389+
390+ err := runAdd (cfg , & addOptions {}, nil )
391+ output := collectOutput (cfg , outR , errR )
392+
393+ require .NoError (t , err )
394+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
395+ assert .Equal (t , "" , gotDefault , "prompt should have empty default when no prefix" )
396+ assert .Equal (t , "my-branch" , createdBranch , "input should be used as-is" )
397+ }
398+
399+ func TestAdd_PromptUserModifiesPrefix (t * testing.T ) {
400+ gitDir := t .TempDir ()
401+ saveStack (t , gitDir , stack.Stack {
402+ Prefix : "feat" ,
403+ Trunk : stack.BranchRef {Branch : "main" },
404+ Branches : []stack.BranchRef {{Branch : "feat/01" }},
405+ })
406+
407+ var createdBranch string
408+ restore := git .SetOps (& git.MockOps {
409+ GitDirFn : func () (string , error ) { return gitDir , nil },
410+ CurrentBranchFn : func () (string , error ) { return "feat/01" , nil },
411+ CreateBranchFn : func (name , base string ) error {
412+ createdBranch = name
413+ return nil
414+ },
415+ CheckoutBranchFn : func (name string ) error { return nil },
416+ RevParseFn : func (ref string ) (string , error ) { return "abc" , nil },
417+ })
418+ defer restore ()
419+
420+ cfg , outR , errR := config .NewTestConfig ()
421+
422+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
423+ // Simulate user changing the prefix entirely
424+ return "custom/other-name" , nil
425+ }
426+
427+ err := runAdd (cfg , & addOptions {}, nil )
428+ output := collectOutput (cfg , outR , errR )
429+
430+ require .NoError (t , err )
431+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
432+ assert .Equal (t , "custom/other-name" , createdBranch , "user-modified input should be used verbatim" )
433+ }
434+
324435func TestAdd_FromTrunk (t * testing.T ) {
325436 gitDir := t .TempDir ()
326437 saveStack (t , gitDir , stack.Stack {
0 commit comments