@@ -83,13 +83,21 @@ fn uid() -> Result<String, String> {
8383}
8484
8585fn render_plist ( paths : & AutostartPaths ) -> String {
86+ render_plist_with_path ( paths, & super :: service_path_env ( ) )
87+ }
88+
89+ fn render_plist_with_path ( paths : & AutostartPaths , path_env : & str ) -> String {
8690 format ! (
8791 "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n \
8892 <!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd\" >\n \
8993 <plist version=\" 1.0\" >\n \
9094 <dict>\n \
9195 <key>Label</key><string>{}</string>\n \
9296 <key>ProgramArguments</key><array><string>{}</string></array>\n \
97+ <key>EnvironmentVariables</key>\n \
98+ <dict>\n \
99+ <key>PATH</key><string>{}</string>\n \
100+ </dict>\n \
93101 <key>RunAtLoad</key><true/>\n \
94102 <key>KeepAlive</key><false/>\n \
95103 <key>StandardOutPath</key><string>{}</string>\n \
@@ -98,6 +106,7 @@ fn render_plist(paths: &AutostartPaths) -> String {
98106 </plist>\n ",
99107 LABEL ,
100108 xml_escape( & paths. lucarned. display( ) . to_string( ) ) ,
109+ xml_escape( path_env) ,
101110 xml_escape( & paths. log_dir. join( "launchd.out.log" ) . display( ) . to_string( ) ) ,
102111 xml_escape( & paths. log_dir. join( "launchd.err.log" ) . display( ) . to_string( ) ) ,
103112 )
@@ -127,4 +136,30 @@ mod tests {
127136 assert ! ( plist. contains( "/tmp/A&B/lucarned" ) ) ;
128137 assert ! ( plist. contains( "com.tuchg.lucarned" ) ) ;
129138 }
139+
140+ #[ test]
141+ fn plist_sets_cli_lookup_path ( ) {
142+ let paths = AutostartPaths {
143+ lucarned : PathBuf :: from ( "/tmp/lucarned" ) ,
144+ config_dir : PathBuf :: from ( "/tmp/config" ) ,
145+ log_dir : PathBuf :: from ( "/tmp/logs" ) ,
146+ } ;
147+ let plist = render_plist ( & paths) ;
148+ assert ! ( plist. contains( "<key>EnvironmentVariables</key>" ) ) ;
149+ assert ! ( plist. contains( "<key>PATH</key>" ) ) ;
150+ assert ! ( plist. contains( "/usr/bin" ) ) ;
151+ }
152+
153+ #[ test]
154+ fn plist_persists_current_process_path_only ( ) {
155+ let paths = AutostartPaths {
156+ lucarned : PathBuf :: from ( "/tmp/lucarned" ) ,
157+ config_dir : PathBuf :: from ( "/tmp/config" ) ,
158+ log_dir : PathBuf :: from ( "/tmp/logs" ) ,
159+ } ;
160+ let plist = render_plist_with_path ( & paths, "/custom/bin:/usr/bin" ) ;
161+ assert ! ( plist. contains( "<key>PATH</key><string>/custom/bin:/usr/bin</string>" ) ) ;
162+ assert ! ( !plist. contains( "HOMEBREW_PATH" ) ) ;
163+ assert ! ( !plist. contains( "LUCARNE_TEST_ENV" ) ) ;
164+ }
130165}
0 commit comments