fix(cli): honor provider overrides on session resume (#10810)

This commit is contained in:
Kevin
2026-08-11 21:49:07 +08:00
committed by GitHub
parent 38debd7420
commit 8e54bad4e6
2 changed files with 631 additions and 14 deletions
+82 -7
View File
@@ -321,7 +321,7 @@ impl Default for OutputOptions {
}
}
/// Model/provider override options for the run command
/// Model/provider override options
#[derive(Args, Debug, Clone, Default)]
pub struct ModelOptions {
/// Provider to use for this run (overrides environment variable)
@@ -941,6 +941,9 @@ enum Command {
#[command(flatten)]
extension_opts: ExtensionOptions,
#[command(flatten)]
model_opts: ModelOptions,
},
/// Execute commands from an instruction file
@@ -1607,7 +1610,7 @@ async fn handle_session_subcommand(command: SessionCommand) -> Result<()> {
Ok(())
}
async fn handle_interactive_session(
struct InteractiveSessionArgs {
identifier: Option<Identifier>,
resume: bool,
fork: bool,
@@ -1615,7 +1618,20 @@ async fn handle_interactive_session(
history: bool,
session_opts: SessionOptions,
extension_opts: ExtensionOptions,
) -> Result<()> {
model_opts: ModelOptions,
}
async fn handle_interactive_session(args: InteractiveSessionArgs) -> Result<()> {
let InteractiveSessionArgs {
identifier,
resume,
fork,
edit,
history,
session_opts,
extension_opts,
model_opts,
} = args;
#[cfg(feature = "telemetry")]
if get_telemetry_choice().is_none() {
configure_telemetry_consent_dialog()?;
@@ -1690,8 +1706,8 @@ async fn handle_interactive_session(
no_profile: extension_opts.no_profile,
recipe: None,
additional_system_prompt: None,
provider: None,
model: None,
provider: model_opts.provider,
model: model_opts.model,
debug: session_opts.debug,
max_tool_repetitions: session_opts.max_tool_repetitions,
max_turns: session_opts.max_turns,
@@ -2275,8 +2291,9 @@ pub async fn cli() -> anyhow::Result<()> {
history,
session_opts,
extension_opts,
model_opts,
}) => {
handle_interactive_session(
handle_interactive_session(InteractiveSessionArgs {
identifier,
resume,
fork,
@@ -2284,7 +2301,8 @@ pub async fn cli() -> anyhow::Result<()> {
history,
session_opts,
extension_opts,
)
model_opts,
})
.await
}
Some(Command::Run {
@@ -2398,6 +2416,63 @@ mod tests {
}
}
#[test]
fn session_resume_accepts_provider_and_model_overrides() {
let cli = Cli::try_parse_from([
"goose",
"session",
"--resume",
"--provider",
"openai",
"--model",
"gpt-5.4",
])
.expect("parse failed");
match cli.command {
Some(Command::Session {
resume, model_opts, ..
}) => {
assert!(resume);
assert_eq!(model_opts.provider.as_deref(), Some("openai"));
assert_eq!(model_opts.model.as_deref(), Some("gpt-5.4"));
}
_ => panic!("expected session command"),
}
}
#[test]
fn session_accepts_provider_override_without_resume() {
let cli = Cli::try_parse_from(["goose", "session", "--provider", "openai"])
.expect("provider override should work for a new session");
match cli.command {
Some(Command::Session {
resume, model_opts, ..
}) => {
assert!(!resume);
assert_eq!(model_opts.provider.as_deref(), Some("openai"));
}
_ => panic!("expected session command"),
}
}
#[test]
fn session_accepts_model_override_without_resume() {
let cli = Cli::try_parse_from(["goose", "session", "--model", "gpt-5.4"])
.expect("model override should work for a new session");
match cli.command {
Some(Command::Session {
resume, model_opts, ..
}) => {
assert!(!resume);
assert_eq!(model_opts.model.as_deref(), Some("gpt-5.4"));
}
_ => panic!("expected session command"),
}
}
#[test]
fn nushell_completion_generation_emits_module() {
let mut cmd = Cli::command();