Skip to content

Commit d5e8a8e

Browse files
committed
Upgrade prompt is skipped when -y is passed
1 parent 5d9eb7c commit d5e8a8e

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

crates/cli/src/subcommands/publish.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,18 @@ fn confirm_and_clear(
246246
Ok(builder)
247247
}
248248

249-
fn confirm_major_version_upgrade() -> Result<(), anyhow::Error> {
249+
fn confirm_major_version_upgrade(force: bool) -> Result<(), anyhow::Error> {
250250
println!(
251251
"It looks like you're trying to do a major version upgrade from 1.0 to 2.0. We recommend first looking at the upgrade notes before committing to this upgrade: https://spacetimedb.com/docs/upgrade"
252252
);
253253
println!();
254254
println!("WARNING: Once you publish you cannot revert back to version 1.0.");
255255
println!();
256256

257+
if force {
258+
return Ok(());
259+
}
260+
257261
let mut input = String::new();
258262
print!("Please type 'upgrade' to accept this change: ");
259263
let mut stdout = std::io::stdout();
@@ -671,7 +675,7 @@ async fn apply_pre_publish_if_needed(
671675
PrePublishResult::ManualMigrate(manual) => manual.major_version_upgrade,
672676
};
673677
if major_version_upgrade {
674-
confirm_major_version_upgrade()?;
678+
confirm_major_version_upgrade(force)?;
675679
}
676680

677681
match pre {

crates/smoketests/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,19 +1003,25 @@ log = "0.4"
10031003

10041004
/// Publishes the module with name, clear, and break_clients options.
10051005
pub fn publish_module_with_options(&mut self, name: &str, clear: bool, break_clients: bool) -> Result<String> {
1006-
self.publish_module_internal(Some(name), clear, break_clients, None)
1006+
self.publish_module_internal(Some(name), clear, break_clients, true, None)
10071007
}
10081008

10091009
/// Publishes the module and allows supplying stdin input to the CLI.
10101010
///
10111011
/// Useful for interactive publish prompts which require typed acknowledgements.
1012+
/// Note: does NOT pass `--yes` so that interactive prompts are not suppressed.
10121013
pub fn publish_module_with_stdin(&mut self, name: &str, stdin_input: &str) -> Result<String> {
1013-
self.publish_module_internal(Some(name), false, false, Some(stdin_input))
1014+
self.publish_module_internal(Some(name), false, false, false, Some(stdin_input))
1015+
}
1016+
1017+
/// Publishes the module without passing `--yes`, so interactive prompts are not suppressed.
1018+
pub fn publish_module_named_no_yes(&mut self, name: &str) -> Result<String> {
1019+
self.publish_module_internal(Some(name), false, false, false, None)
10141020
}
10151021

10161022
/// Internal helper for publishing with options.
10171023
fn publish_module_opts(&mut self, name: Option<&str>, clear: bool) -> Result<String> {
1018-
self.publish_module_internal(name, clear, false, None)
1024+
self.publish_module_internal(name, clear, false, true, None)
10191025
}
10201026

10211027
/// Internal helper for publishing with all options.
@@ -1024,6 +1030,7 @@ log = "0.4"
10241030
name: Option<&str>,
10251031
clear: bool,
10261032
break_clients: bool,
1033+
force: bool,
10271034
stdin_input: Option<&str>,
10281035
) -> Result<String> {
10291036
let start = Instant::now();
@@ -1072,9 +1079,12 @@ log = "0.4"
10721079
&self.server_url,
10731080
"--bin-path",
10741081
&wasm_path_str,
1075-
"--yes",
10761082
];
10771083

1084+
if force {
1085+
args.push("--yes");
1086+
}
1087+
10781088
if clear {
10791089
args.push("--clear-database");
10801090
}

crates/smoketests/tests/smoketests/publish_upgrade_prompt.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,31 @@ fn upgrade_prompt_on_publish() {
3333
// Switch back to source-built module, which uses current bindings.
3434
test.write_module_code(MODULE_CODE).unwrap();
3535

36-
let deny_err = test.publish_module_named(&db_name, false).unwrap_err().to_string();
36+
let deny_err = test.publish_module_named_no_yes(&db_name).unwrap_err().to_string();
3737
assert!(deny_err.contains("major version upgrade from 1.0 to 2.0"));
3838
assert!(deny_err.contains("Please type 'upgrade' to accept this change:"));
3939

4040
let accepted_identity = test.publish_module_with_stdin(&db_name, "upgrade\n").unwrap();
4141
assert_eq!(accepted_identity, initial_identity);
4242
}
43+
44+
#[test]
45+
fn upgrade_prompt_suppressed_by_yes_flag() {
46+
let mut test = Smoketest::builder().autopublish(false).build();
47+
48+
let old_wasm = old_fixture_wasm();
49+
assert!(old_wasm.exists(), "expected old fixture wasm at {}", old_wasm.display());
50+
51+
let db_name = format!("upgrade-smoke-yes-{}", random_string());
52+
53+
test.use_precompiled_wasm_path(&old_wasm).unwrap();
54+
let initial_identity = test.publish_module_named(&db_name, false).unwrap();
55+
assert_eq!(test.database_identity.as_deref(), Some(initial_identity.as_str()));
56+
57+
// Switch back to source-built module, which uses current bindings.
58+
test.write_module_code(MODULE_CODE).unwrap();
59+
60+
// With --yes, the upgrade prompt should be suppressed and publish should succeed.
61+
let accepted_identity = test.publish_module_named(&db_name, false).unwrap();
62+
assert_eq!(accepted_identity, initial_identity);
63+
}

0 commit comments

Comments
 (0)