@@ -3,7 +3,9 @@ package cmd
33import (
44 "os"
55 "path/filepath"
6+ "strings"
67 "testing"
8+ "time"
79
810 "github.com/DocumentDrivenDX/ddx/internal/ddxroot"
911 "github.com/spf13/cobra"
@@ -51,6 +53,28 @@ persona_bindings: {}
5153 ))
5254}
5355
56+ func personaContractTempDir (t * testing.T ) string {
57+ t .Helper ()
58+
59+ prefix := strings .NewReplacer ("/" , "-" , " " , "-" ).Replace (t .Name ())
60+ dir , err := os .MkdirTemp ("" , prefix + "-*" )
61+ require .NoError (t , err )
62+
63+ t .Cleanup (func () {
64+ var removeErr error
65+ for attempt := 0 ; attempt < 5 ; attempt ++ {
66+ removeErr = os .RemoveAll (dir )
67+ if removeErr == nil {
68+ return
69+ }
70+ time .Sleep (time .Duration (attempt + 1 ) * 25 * time .Millisecond )
71+ }
72+ require .NoError (t , removeErr )
73+ })
74+
75+ return dir
76+ }
77+
5478// Contract validation tests verify that persona CLI commands conform to their API contracts
5579// as defined in the CLI persona contract
5680
@@ -359,7 +383,7 @@ func TestPersonaShowCommand_Contract(t *testing.T) {
359383 description : "Exit code 0: Persona found and displayed" ,
360384 args : []string {"persona" , "show" , "test-reviewer" },
361385 setup : func (t * testing.T ) string {
362- testWorkDir := t . TempDir ( )
386+ testWorkDir := personaContractTempDir ( t )
363387
364388 homeDir := t .TempDir ()
365389 t .Setenv ("HOME" , homeDir )
@@ -410,7 +434,7 @@ You are an experienced code reviewer who enforces high standards.
410434 description : "Exit code 6: Persona not found" ,
411435 args : []string {"persona" , "show" , "nonexistent-persona" },
412436 setup : func (t * testing.T ) string {
413- testWorkDir := t . TempDir ( )
437+ testWorkDir := personaContractTempDir ( t )
414438
415439 homeDir := t .TempDir ()
416440 t .Setenv ("HOME" , homeDir )
0 commit comments