Skip to content

Commit 084f0a0

Browse files
Varun Kamathvarunkamath
authored andcommitted
fix: respect plugins_loading.enabled config in zenohd
zenohd unconditionally set `plugins_loading.enabled = true`, ignoring the user's configuration. Now plugin loading is only force-enabled when CLI args require it (`--plugin`, `--rest-http-port`, or `--plugin-search-dir`), preserving the documented behavior. Fixes #2422 Signed-off-by: Varun Kamath <varunkamath@gmail.com>
1 parent 674da72 commit 084f0a0

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

zenohd/src/main.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ fn config_from_args(args: &Args) -> Config {
134134
}
135135
}
136136
config.adminspace.set_enabled(true).unwrap();
137-
config.plugins_loading.set_enabled(true).unwrap();
137+
// Enable plugin loading if CLI args require plugins, but respect the user's
138+
// config if no plugin-related CLI args are provided.
139+
if !args.plugin.is_empty() || args.rest_http_port.is_some() || !args.plugin_search_dir.is_empty()
140+
{
141+
config.plugins_loading.set_enabled(true).unwrap();
142+
}
138143
if !args.plugin_search_dir.is_empty() {
139144
config
140145
.plugins_loading
@@ -286,6 +291,50 @@ fn init_logging() -> Result<()> {
286291
Ok(())
287292
}
288293

294+
#[test]
295+
fn test_plugins_loading_respects_config() {
296+
// Without plugin-related CLI args, plugins_loading.enabled should remain
297+
// at whatever the config specifies (false by default).
298+
let args = Args::parse_from(["zenohd"]);
299+
let config = config_from_args(&args);
300+
assert!(
301+
!config.plugins_loading.enabled(),
302+
"plugins_loading should be disabled by default without plugin CLI args"
303+
);
304+
305+
// With --plugin, plugins_loading.enabled should be forced on.
306+
let args = Args::parse_from(["zenohd", "--plugin", "rest"]);
307+
let config = config_from_args(&args);
308+
assert!(
309+
config.plugins_loading.enabled(),
310+
"plugins_loading should be enabled when --plugin is passed"
311+
);
312+
313+
// With --rest-http-port, plugins_loading.enabled should be forced on.
314+
let args = Args::parse_from(["zenohd", "--rest-http-port", "8000"]);
315+
let config = config_from_args(&args);
316+
assert!(
317+
config.plugins_loading.enabled(),
318+
"plugins_loading should be enabled when --rest-http-port is passed"
319+
);
320+
321+
// With --plugin-search-dir, plugins_loading.enabled should be forced on.
322+
let args = Args::parse_from(["zenohd", "--plugin-search-dir", "/tmp"]);
323+
let config = config_from_args(&args);
324+
assert!(
325+
config.plugins_loading.enabled(),
326+
"plugins_loading should be enabled when --plugin-search-dir is passed"
327+
);
328+
329+
// When config explicitly enables plugins_loading but no CLI args, it should stay enabled.
330+
let args = Args::parse_from(["zenohd", "--cfg", "plugins_loading/enabled:true"]);
331+
let config = config_from_args(&args);
332+
assert!(
333+
config.plugins_loading.enabled(),
334+
"plugins_loading should stay enabled when set via --cfg"
335+
);
336+
}
337+
289338
#[test]
290339
#[cfg(feature = "default")]
291340
fn test_default_features() {

0 commit comments

Comments
 (0)