Bot deploy shows the module's refusal; modules update only when the owner asks

- Deploy: a refusal text of the bot module (switched off, rejected, 0 created) is an
  error, not a started job; the outdated-module message points to the Modules page.
- Modules: a module whose build differs from the commit the core recommends shows
  an Update button. Nothing updates by itself, not even on a core change. Needs the
  world stopped, merges the module's settings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-11-24 13:54:48 +05:00
1 parent 5db6691b8b
commit e8bf35f95d
16 files changed
+233 -8

No files matched your search

+1 -1
View File
@@ -178,7 +178,7 @@ impl ErrorCode {
),
ErrorCode::CompanionCommandUnsupported => (
"This server version can not do that yet",
"The bot module of this server build has no such command. Update the server, or restart it to stop what is running.",
"The bot module on this server is older than this Manager and does not know this command. Update the bot module on the Modules page (or update the server), then restart the world.",
&[ShowDetails],
),
ErrorCode::Unknown => ("Something went wrong", "See the technical details.", &[ShowDetails]),
+9
View File
@@ -168,6 +168,9 @@ pub struct ModuleView {
pub component_type: ComponentType,
pub can_remove: bool,
pub source_commit: Option<String>,
/// A newer build of this module is recommended by the server's core; updating is the owner's choice.
#[serde(default)]
pub available_commit: Option<String>,
pub part_of: Option<String>,
}
@@ -493,6 +496,7 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
component_type,
can_remove,
source_commit,
available_commit: None,
part_of: e.part_of,
}
})
@@ -523,6 +527,10 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
views[idx].version = Some(plugin_entry.version.clone());
views[idx].component_type = ComponentType::DynamicDll;
views[idx].can_remove = true;
if views[idx].source_commit.is_none() {
views[idx].source_commit = crate::build_engine::read_build_recipe(root, plugin_id).and_then(|r| r.source_commit);
}
views[idx].available_commit = crate::rebuild::available_update(root, plugin_id);
continue;
}
@@ -592,6 +600,7 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
component_type: ComponentType::DynamicDll,
can_remove: true,
source_commit,
available_commit: None,
part_of: None,
});
}
+49
View File
@@ -286,9 +286,13 @@ impl Ra {
));
}
let out = self.command(&format!("botcmd spawnleveled {count}"))?;
if is_unsupported_command(&out) {
return Err(Error::CompanionCommandUnsupported);
}
if out.to_lowercase().contains("no usable template characters") {
return Err(Error::CompanionTemplatesMissing);
}
refused_spawn(&out)?;
Ok(out.lines().last().unwrap_or("").to_string())
}
@@ -318,6 +322,7 @@ impl Ra {
cmd.push_str(&format!(" {c}"));
}
let out = self.bot_command(&cmd)?;
refused_spawn(&out)?;
Ok(out.lines().last().unwrap_or("").to_string())
}
@@ -402,6 +407,28 @@ fn is_unsupported_command(out: &str) -> bool {
|| l.contains("unknown command")
}
/// The bot module answers a request it cannot carry out with an ordinary line of text, not with an error, so the
/// caller must read it: otherwise the page shows "creating bots" for ever. Returns the module's own words.
fn refused_spawn(out: &str) -> Result<()> {
let l = out.to_lowercase();
let refused = l.contains("switched off")
|| l.contains("rejected")
|| l.contains("nothing to do")
|| l.contains("aborting")
|| l.contains("created and spawned 0 of")
|| l.contains("giving up");
if refused {
let line = out
.lines()
.rev()
.find(|x| !x.trim().is_empty())
.unwrap_or(out)
.trim();
return Err(Error::Invalid(format!("The bot module did not create the bots: {line}")));
}
Ok(())
}
fn first_number(text: &str) -> u32 {
text.split(|c: char| !c.is_ascii_digit())
.find(|t| !t.is_empty())
@@ -625,6 +652,28 @@ AC>";
assert_eq!(h.join().unwrap()[2], "botcmd spawnleveled 50");
}
#[test]
fn a_refusal_of_the_bot_module_is_an_error_not_a_started_job() {
let _lock = serial();
for reply in [
"BotMgr: companions are switched off (CoaBots.Enable = 0).",
"BotMgr: spawncustom rejected: level 60 is above this realm's cap.",
"BotMgr: spawncustom created and spawned 0 of 50 bots (level 60, class 0, spec 0).",
] {
let (port, h) = fake_ra(reply);
let mut ra = Ra::connect_to(port, "u", "p").unwrap();
let err = ra.spawn_custom(50, 60, None, None, None).unwrap_err().to_string();
assert!(err.contains("did not create"), "{reply}: {err}");
drop(ra);
h.join().unwrap();
}
let (port, h) = fake_ra("BotMgr: spawncustom created and spawned 50 of 50 bots (level 60, class 0, spec 0).");
let mut ra = Ra::connect_to(port, "u", "p").unwrap();
assert!(ra.spawn_custom(50, 60, None, None, None).unwrap().contains("50 of 50"));
drop(ra);
h.join().unwrap();
}
#[test]
fn duplicate_account_and_input_validation() {
let _lock = serial();
+61 -1
View File
@@ -311,7 +311,36 @@ fn install_recommended(realm_root: &Path, progress: &dyn Fn(&str, &str)) -> Vec<
out
}
/// The commit this core recommends for an installed module when it differs from the one the module was built
/// from. Never acted on by itself: the owner decides when to update (the Modules page asks).
pub fn available_update(realm_root: &Path, id: &str) -> Option<String> {
let rec = recommended(realm_root)?;
let want = &rec.modules.iter().find(|m| m.id == id)?.commit;
let have = build_engine::read_build_recipe(realm_root, id)?.source_commit?;
let same = have.starts_with(want.as_str()) || want.starts_with(have.as_str());
(!same).then(|| want.clone())
}
/// Rebuild one installed module from the commit this core recommends and swap it in (the world must be stopped).
/// The module's settings are merged, not reset, and the previous build stays in the plugin store.
pub fn update_to_recommended(realm_root: &Path, id: &str) -> std::result::Result<String, String> {
let rec = recommended(realm_root).ok_or("this server's core does not list recommended modules")?;
let m = rec.modules.iter().find(|m| m.id == id).ok_or_else(|| format!("'{id}' is not a recommended module of this core"))?;
if !plugins::load_registry(realm_root).map_err(|e| e.to_string())?.plugins.contains_key(id) {
return Err(format!("'{id}' is not installed"));
}
install_module_sources(realm_root, m, true)?;
let mut handled = load_handled(realm_root);
handled.insert(m.id.clone(), m.commit.clone());
save_handled(realm_root, &handled);
Ok(m.commit.clone())
}
fn install_one(realm_root: &Path, m: &RecommendedModule) -> std::result::Result<(), String> {
install_module_sources(realm_root, m, false)
}
fn install_module_sources(realm_root: &Path, m: &RecommendedModule, update: bool) -> std::result::Result<(), String> {
let cache = source_cache();
let (owner, name) = split_repo(&m.repo)?;
let primary = crate::module_sources::fetch_pinned(owner, name, &m.commit, &cache).map_err(|e| e.to_string())?;
@@ -337,7 +366,11 @@ fn install_one(realm_root: &Path, m: &RecommendedModule) -> std::result::Result<
}
let (meta, dll, confs) = crate::preview::built_package(realm_root, &m.id, &built.version).map_err(|e| e.to_string())?;
let confs: Vec<(String, &[u8])> = confs.iter().map(|(n, b)| (n.clone(), b.as_slice())).collect();
plugins::install(realm_root, meta, &dll, None, &confs, true).map_err(|e| e.to_string())
if update {
plugins::update(realm_root, meta, &dll, None, &confs).map_err(|e| e.to_string())
} else {
plugins::install(realm_root, meta, &dll, None, &confs, true).map_err(|e| e.to_string())
}
}
@@ -497,6 +530,33 @@ mod tests {
assert!(rebuild_for_current_core(server, &|_, _| panic!("nothing is built")).unwrap().is_empty());
}
#[test]
fn a_newer_recommended_build_is_offered_never_applied_by_itself() {
let dir = tempfile::tempdir().unwrap();
let server = dir.path();
fs::create_dir_all(server.join("Core/plugins")).unwrap();
fs::write(server.join("Core/plugins/recommended.json"), r#"{"schema":1,"modules":[
{"id":"companions","repo":"Corfirean/mod-coa-playerbots","commit":"178a7fde6abe1c3c8813d338073b2c83835da497"}]}"#).unwrap();
// no recipe: the manager cannot tell what is installed, so it offers nothing
assert_eq!(available_update(server, "companions"), None);
let recipes = plugins::meta_dir(server).join("build-recipes");
fs::create_dir_all(&recipes).unwrap();
let recipe = |commit: &str| {
format!(r#"{{"schema":1,"source_dir":"x","bundled":[],"source_commit":"{commit}"}}"#)
};
fs::write(recipes.join("companions.json"), recipe("447558bc27d6bb447aaf10eefcb2e85ac2b15c32")).unwrap();
assert_eq!(
available_update(server, "companions").as_deref(),
Some("178a7fde6abe1c3c8813d338073b2c83835da497")
);
// already built from the recommended commit (a short form counts too)
fs::write(recipes.join("companions.json"), recipe("178a7fde")).unwrap();
assert_eq!(available_update(server, "companions"), None);
assert_eq!(available_update(server, "unknown-module"), None);
// a core change rebuilds the old sources and does not move the module to the newer commit
assert!(load_handled(server).is_empty());
}
/// Real run: COA_TEST_RECOMMENDED_REALM is a plugin-host realm with Core/plugins/recommended.json (or
/// plugins/recommended.json); the modules are downloaded from GitHub, built and switched on.
#[test]