@@ -2,6 +2,7 @@ package paths
22
33import (
44 "os"
5+ "path/filepath"
56 "strings"
67 "testing"
78
@@ -86,6 +87,65 @@ func TestHome_CLIOverridesEnv(t *testing.T) {
8687 }
8788}
8889
90+ func TestHome_ExpandsHomeTokenFromConfig (t * testing.T ) {
91+ withOverride (t , "" )
92+ withEnv (t , HomeEnvVar , "" )
93+ withConfigInstallDir (t , "$HOME/.stepsecurity" )
94+
95+ home , err := os .UserHomeDir ()
96+ if err != nil || home == "" {
97+ t .Skip ("home dir unresolved in this environment" )
98+ }
99+ want := filepath .Join (home , ".stepsecurity" )
100+ if got := Home (); got != want {
101+ t .Errorf ("Home() = %q, want %q (config $HOME should expand)" , got , want )
102+ }
103+ // And the migration warning's equality check must now succeed.
104+ if Home () != LegacyHome () {
105+ t .Errorf ("Home()=%q vs LegacyHome()=%q — expected equal after $HOME expansion" , Home (), LegacyHome ())
106+ }
107+ }
108+
109+ func TestHome_ExpandsTildeFromEnvVar (t * testing.T ) {
110+ withOverride (t , "" )
111+ withConfigInstallDir (t , "" )
112+ withEnv (t , HomeEnvVar , "~/agent" )
113+
114+ home , err := os .UserHomeDir ()
115+ if err != nil || home == "" {
116+ t .Skip ("home dir unresolved in this environment" )
117+ }
118+ want := filepath .Join (home , "agent" )
119+ if got := Home (); got != want {
120+ t .Errorf ("Home() = %q, want %q (env ~ should expand)" , got , want )
121+ }
122+ }
123+
124+ func TestHome_ExpandsHomeFromCLIFlag (t * testing.T ) {
125+ withConfigInstallDir (t , "" )
126+ withEnv (t , HomeEnvVar , "" )
127+ withOverride (t , "$HOME/custom" )
128+
129+ home , err := os .UserHomeDir ()
130+ if err != nil || home == "" {
131+ t .Skip ("home dir unresolved in this environment" )
132+ }
133+ want := filepath .Join (home , "custom" )
134+ if got := Home (); got != want {
135+ t .Errorf ("Home() = %q, want %q (CLI $HOME should expand)" , got , want )
136+ }
137+ }
138+
139+ func TestHome_AbsolutePathUnchanged (t * testing.T ) {
140+ withOverride (t , "" )
141+ withEnv (t , HomeEnvVar , "" )
142+ withConfigInstallDir (t , "/opt/stepsecurity" )
143+
144+ if got := Home (); got != "/opt/stepsecurity" {
145+ t .Errorf ("Home() = %q, want /opt/stepsecurity (absolute path must not be modified)" , got )
146+ }
147+ }
148+
89149func TestSetOverride_Sticks (t * testing.T ) {
90150 withOverride (t , "" )
91151 SetOverride ("/sticky" )
0 commit comments