@@ -321,6 +321,119 @@ 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 gotPrompt , gotDefault string
348+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
349+ gotPrompt = prompt
350+ gotDefault = defaultValue
351+ return "feat/my-branch" , nil
352+ }
353+
354+ err := runAdd (cfg , & addOptions {}, nil )
355+ output := collectOutput (cfg , outR , errR )
356+
357+ require .NoError (t , err )
358+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
359+ assert .Contains (t , gotPrompt , ":" , "prompt should end with a colon" )
360+ assert .Equal (t , "feat/" , gotDefault , "prompt should pre-fill prefix/" )
361+ assert .Equal (t , "feat/my-branch" , createdBranch , "full input should be used as branch name" )
362+ }
363+
364+ func TestAdd_PromptNoPrefixEmptyDefault (t * testing.T ) {
365+ gitDir := t .TempDir ()
366+ saveStack (t , gitDir , stack.Stack {
367+ Trunk : stack.BranchRef {Branch : "main" },
368+ Branches : []stack.BranchRef {{Branch : "b1" }},
369+ })
370+
371+ var createdBranch string
372+ restore := git .SetOps (& git.MockOps {
373+ GitDirFn : func () (string , error ) { return gitDir , nil },
374+ CurrentBranchFn : func () (string , error ) { return "b1" , nil },
375+ CreateBranchFn : func (name , base string ) error {
376+ createdBranch = name
377+ return nil
378+ },
379+ CheckoutBranchFn : func (name string ) error { return nil },
380+ RevParseFn : func (ref string ) (string , error ) { return "abc" , nil },
381+ })
382+ defer restore ()
383+
384+ cfg , outR , errR := config .NewTestConfig ()
385+
386+ var gotDefault string
387+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
388+ gotDefault = defaultValue
389+ return "my-branch" , nil
390+ }
391+
392+ err := runAdd (cfg , & addOptions {}, nil )
393+ output := collectOutput (cfg , outR , errR )
394+
395+ require .NoError (t , err )
396+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
397+ assert .Equal (t , "" , gotDefault , "prompt should have empty default when no prefix" )
398+ assert .Equal (t , "my-branch" , createdBranch , "input should be used as-is" )
399+ }
400+
401+ func TestAdd_PromptUserModifiesPrefix (t * testing.T ) {
402+ gitDir := t .TempDir ()
403+ saveStack (t , gitDir , stack.Stack {
404+ Prefix : "feat" ,
405+ Trunk : stack.BranchRef {Branch : "main" },
406+ Branches : []stack.BranchRef {{Branch : "feat/01" }},
407+ })
408+
409+ var createdBranch string
410+ restore := git .SetOps (& git.MockOps {
411+ GitDirFn : func () (string , error ) { return gitDir , nil },
412+ CurrentBranchFn : func () (string , error ) { return "feat/01" , nil },
413+ CreateBranchFn : func (name , base string ) error {
414+ createdBranch = name
415+ return nil
416+ },
417+ CheckoutBranchFn : func (name string ) error { return nil },
418+ RevParseFn : func (ref string ) (string , error ) { return "abc" , nil },
419+ })
420+ defer restore ()
421+
422+ cfg , outR , errR := config .NewTestConfig ()
423+
424+ cfg .InputFn = func (prompt , defaultValue string ) (string , error ) {
425+ // Simulate user changing the prefix entirely
426+ return "custom/other-name" , nil
427+ }
428+
429+ err := runAdd (cfg , & addOptions {}, nil )
430+ output := collectOutput (cfg , outR , errR )
431+
432+ require .NoError (t , err )
433+ require .NotContains (t , output , "\u2717 " , "unexpected error" )
434+ assert .Equal (t , "custom/other-name" , createdBranch , "user-modified input should be used verbatim" )
435+ }
436+
324437func TestAdd_FromTrunk (t * testing.T ) {
325438 gitDir := t .TempDir ()
326439 saveStack (t , gitDir , stack.Stack {
0 commit comments