Skip to content

Commit 9437696

Browse files
Phase C: drop LogLevel::Info default
When ClientOptions::log_level is None, the SDK no longer passes --log-level to the spawned CLI process at all. The CLI's built-in default takes over. Previously the SDK silently overrode the CLI default with Info, which made it impossible to opt back into the CLI default. - Extract a log_level_args() helper alongside auth_args / remote_args. - Update field rustdoc and remove 'Default.' annotation from LogLevel::Info. - Add two unit tests: log_level_args_omitted_when_unset and log_level_args_emit_flag_when_set. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6b0cdf3 commit 9437696

1 file changed

Lines changed: 30 additions & 19 deletions

File tree

rust/src/lib.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ pub struct ClientOptions {
350350
/// [`Self::github_token`] is set, in which case false).
351351
pub use_logged_in_user: Option<bool>,
352352
/// Log level passed to the CLI server via `--log-level`. When `None`,
353-
/// the SDK uses [`LogLevel::Info`].
353+
/// the SDK does not pass `--log-level` to the runtime at all and the
354+
/// CLI uses its built-in default.
354355
pub log_level: Option<LogLevel>,
355356
/// Server-wide idle timeout for sessions, in seconds. When set to a
356357
/// positive value, the SDK passes `--session-idle-timeout <secs>` to
@@ -475,7 +476,7 @@ pub enum LogLevel {
475476
Error,
476477
/// Warnings and errors.
477478
Warning,
478-
/// Default. Info and above.
479+
/// Info and above.
479480
Info,
480481
/// Debug, info, warnings, errors.
481482
Debug,
@@ -1349,18 +1350,19 @@ impl Client {
13491350
}
13501351
}
13511352

1353+
fn log_level_args(options: &ClientOptions) -> Vec<&'static str> {
1354+
match options.log_level {
1355+
Some(level) => vec!["--log-level", level.as_str()],
1356+
None => Vec::new(),
1357+
}
1358+
}
1359+
13521360
fn spawn_stdio(program: &Path, options: &ClientOptions) -> Result<Child, Error> {
13531361
info!(cwd = ?options.cwd, program = %program.display(), "spawning copilot CLI (stdio)");
13541362
let mut command = Self::build_command(program, options);
1355-
let log_level = options.log_level.unwrap_or(LogLevel::Info);
13561363
command
1357-
.args([
1358-
"--server",
1359-
"--stdio",
1360-
"--no-auto-update",
1361-
"--log-level",
1362-
log_level.as_str(),
1363-
])
1364+
.args(["--server", "--stdio", "--no-auto-update"])
1365+
.args(Self::log_level_args(options))
13641366
.args(Self::auth_args(options))
13651367
.args(Self::session_idle_timeout_args(options))
13661368
.args(Self::remote_args(options))
@@ -1382,16 +1384,9 @@ impl Client {
13821384
) -> Result<(Child, u16), Error> {
13831385
info!(cwd = ?options.cwd, program = %program.display(), port = %port, "spawning copilot CLI (tcp)");
13841386
let mut command = Self::build_command(program, options);
1385-
let log_level = options.log_level.unwrap_or(LogLevel::Info);
13861387
command
1387-
.args([
1388-
"--server",
1389-
"--port",
1390-
&port.to_string(),
1391-
"--no-auto-update",
1392-
"--log-level",
1393-
log_level.as_str(),
1394-
])
1388+
.args(["--server", "--port", &port.to_string(), "--no-auto-update"])
1389+
.args(Self::log_level_args(options))
13951390
.args(Self::auth_args(options))
13961391
.args(Self::session_idle_timeout_args(options))
13971392
.args(Self::remote_args(options))
@@ -2403,6 +2398,22 @@ mod tests {
24032398
assert_eq!(Client::remote_args(&opts), vec!["--remote".to_string()]);
24042399
}
24052400

2401+
#[test]
2402+
fn log_level_args_omitted_when_unset() {
2403+
let opts = ClientOptions::default();
2404+
assert!(opts.log_level.is_none());
2405+
assert!(
2406+
Client::log_level_args(&opts).is_empty(),
2407+
"with no caller-supplied log_level the SDK must not pass --log-level"
2408+
);
2409+
}
2410+
2411+
#[test]
2412+
fn log_level_args_emit_flag_when_set() {
2413+
let opts = ClientOptions::default().with_log_level(LogLevel::Debug);
2414+
assert_eq!(Client::log_level_args(&opts), vec!["--log-level", "debug"]);
2415+
}
2416+
24062417
#[test]
24072418
fn log_level_str_round_trips() {
24082419
for level in [

0 commit comments

Comments
 (0)