From da94fb49a4d81e2cf9b7d47eda5c24a248ac7b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 5 Nov 2026 15:36:16 +0500 Subject: [PATCH] Rebuild installed modules for the new core during an update The core changes almost daily and a plugin loads only into the core it was built for. update::apply now brings every enabled plugin to the new core before the trial start: a build already in the store is reused, otherwise it is rebuilt from the sources recorded at its last build (build recipe). A plugin that cannot be rebuilt is switched off with the reason (and plugins that depend on it); the core update always goes ahead. A rollback puts the builds for the restored core back. The update result lists rebuilt and switched-off modules. Also: plugin.json records the real compiler instead of a fixed string. Co-Authored-By: Claude Opus 5.5 --- .../20261105-modules-follow-core-updates.md | 7 + crates/coa-core/src/build_engine.rs | 36 ++- crates/coa-core/src/lib.rs | 1 + crates/coa-core/src/plugins.rs | 51 +++- crates/coa-core/src/preview.rs | 65 +++-- crates/coa-core/src/rebuild.rs | 241 ++++++++++++++++++ crates/coa-core/src/update.rs | 27 ++ src/i18n/locales/de.ts | 2 + src/i18n/locales/en.ts | 2 + src/i18n/locales/es.ts | 2 + src/i18n/locales/fr.ts | 2 + src/i18n/locales/ru.ts | 2 + src/i18n/locales/zh.ts | 2 + src/lib/api.ts | 8 +- src/lib/serverUpdate.ts | 7 +- src/screens/Overview.tsx | 2 + 16 files changed, 424 insertions(+), 33 deletions(-) create mode 100644 changelog.d/20261105-modules-follow-core-updates.md create mode 100644 crates/coa-core/src/rebuild.rs diff --git a/changelog.d/20261105-modules-follow-core-updates.md b/changelog.d/20261105-modules-follow-core-updates.md new file mode 100644 index 0000000..e08acdf --- /dev/null +++ b/changelog.d/20261105-modules-follow-core-updates.md @@ -0,0 +1,7 @@ +--- +area: manager +type: added +audience: admins +title: Modules are rebuilt automatically after a core update +--- +After the core is updated, the Manager rebuilds every enabled module for the new core before the first start, or reuses a build it already has. A module that cannot be rebuilt is switched off with the reason shown, and the core update still goes ahead. Rolling back the core puts the earlier module builds back. diff --git a/crates/coa-core/src/build_engine.rs b/crates/coa-core/src/build_engine.rs index 6bb5052..84e5534 100644 --- a/crates/coa-core/src/build_engine.rs +++ b/crates/coa-core/src/build_engine.rs @@ -832,6 +832,33 @@ pub fn build_module_from_source( build_module_with_bundle(module_source_dir, &[], realm_root, custom_staging_dir, progress_callback) } +/// The sources a plugin was last built from, kept per realm so the manager can rebuild it on its own +/// after a core update. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BuildRecipe { + pub schema: u32, + pub source_dir: PathBuf, + #[serde(default)] + pub bundled: Vec, + #[serde(default)] + pub source_commit: Option, +} + +fn build_recipe_path(realm_root: &Path, module_id: &str) -> PathBuf { + crate::plugins::meta_dir(realm_root).join("build-recipes").join(format!("{module_id}.json")) +} + +fn write_build_recipe(realm_root: &Path, module_id: &str, recipe: &BuildRecipe) -> Result<()> { + let path = build_recipe_path(realm_root, module_id); + fs::create_dir_all(path.parent().unwrap())?; + crate::fsx::atomic_write(&path, serde_json::to_string_pretty(recipe)?.as_bytes())?; + Ok(()) +} + +pub fn read_build_recipe(realm_root: &Path, module_id: &str) -> Option { + serde_json::from_slice(&fs::read(build_recipe_path(realm_root, module_id)).ok()?).ok() +} + /// Builds `module_source_dir` into one plugin DLL, together with `bundled` source trees that must live /// in the same image (a module that derives from another module's C++ classes, such as Dungeon Clear /// on SQUID). Each bundled tree's loader is called from the plugin's registration. @@ -1218,7 +1245,7 @@ if errorlevel 1 exit /b 103 "dll_sha256": dll_sha256, "abi_fingerprint": host_abi_fingerprint, "master_loader": canonical_loader, - "compiler": "MSVC 19.51.36247 (x64 /MD)", + "compiler": toolchain.msvc_cl_version.as_deref().map(|v| format!("MSVC {v} (x64 /MD)")), "built_at_iso": chrono_now_iso(), "configs": packaged_confs, "sql_files": packaged_sqls, @@ -1233,6 +1260,13 @@ if errorlevel 1 exit /b 103 } }); fs::write(store_dir.join("plugin.json"), serde_json::to_string_pretty(&manifest_content)?)?; + // What to rebuild from when the core changes (crate::rebuild). + write_build_recipe(realm_root, &module_id, &BuildRecipe { + schema: 1, + source_dir: module_source_dir.to_path_buf(), + bundled: bundled.to_vec(), + source_commit: source_commit.clone(), + })?; let duration = start_time.elapsed().as_secs_f64(); emit_progress("SUCCESS", 100, "Module built, qualified and packaged successfully.", None); diff --git a/crates/coa-core/src/lib.rs b/crates/coa-core/src/lib.rs index c91e754..440fef5 100644 --- a/crates/coa-core/src/lib.rs +++ b/crates/coa-core/src/lib.rs @@ -60,6 +60,7 @@ pub mod race_availability; pub mod realm_registry; pub mod realmlist; pub mod realms; +pub mod rebuild; pub mod registry; pub mod release; pub mod release_history; diff --git a/crates/coa-core/src/plugins.rs b/crates/coa-core/src/plugins.rs index 7862c58..2fd4a2c 100644 --- a/crates/coa-core/src/plugins.rs +++ b/crates/coa-core/src/plugins.rs @@ -57,6 +57,10 @@ pub struct PluginEntry { pub deps: Vec, #[serde(default = "yes")] pub required: bool, + /// Why the manager switched this plugin off by itself (it could not be rebuilt for the current + /// core). Such a plugin is rebuilt and switched back on after the next core change. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub disabled_reason: Option, } /// The root registry document in `.manager/plugins.json`. @@ -776,6 +780,7 @@ pub fn install( conf_files: meta.conf_files.clone(), deps: meta.deps.clone(), required: meta.required, + disabled_reason: None, }; reg.plugins.insert(meta.id.clone(), entry); @@ -830,6 +835,14 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> { if id == "playerbots" && reg.plugins.get("companions").map(|p| p.enabled).unwrap_or(false) { return Err(Error::BotModulesConflict); } + // The core refuses a plugin built for another core: it has to be rebuilt first. + if let (Some(host), Some(built)) = (crate::provenance::realm_host_fingerprint(server), installed_plugin_fingerprint(server, id)) { + if host != built { + return Err(Error::Invalid(format!( + "Plugin '{id}' was built for a previous core; rebuild it before switching it on" + ))); + } + } for dep in &entry.deps { if !reg.plugins.get(dep).map(|p| p.enabled).unwrap_or(false) { @@ -849,7 +862,9 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> { } tx.set_phase(TransactionPhase::Applying)?; - reg.plugins.get_mut(id).unwrap().enabled = enabled; + let e = reg.plugins.get_mut(id).unwrap(); + e.enabled = enabled; + e.disabled_reason = None; save_registry(server, ®)?; check_crash_injection("after_registry_write"); @@ -882,6 +897,39 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> { Ok(()) } +/// Switches a plugin off because it cannot run on the current core, together with every enabled plugin +/// that depends on it, and records why. The core itself is never held back by a plugin. +pub fn disable_with_reason(server: &Path, id: &str, reason: &str) -> Result> { + require_server_stopped(server)?; + let mut tx = TxGuard::begin_op(server, PluginOpType::Disable, id)?; + let mut reg = load_registry_direct(server)?; + if !reg.plugins.contains_key(id) { + return Err(Error::Invalid(format!("Plugin '{id}' is not installed"))); + } + let mut off = vec![id.to_string()]; + let mut i = 0; + while i < off.len() { + let cur = off[i].clone(); + for (other_id, other) in ®.plugins { + if other.enabled && other.deps.contains(&cur) && !off.contains(other_id) { + off.push(other_id.clone()); + } + } + i += 1; + } + tx.set_phase(TransactionPhase::Applying)?; + for (n, pid) in off.iter().enumerate() { + let e = reg.plugins.get_mut(pid).unwrap(); + e.enabled = false; + e.disabled_reason = Some(if n == 0 { reason.to_string() } else { format!("depends on '{id}', which was switched off: {reason}") }); + } + save_registry(server, ®)?; + regenerate_lockfile(server, ®)?; + tx.set_phase(TransactionPhase::Validating)?; + tx.commit()?; + Ok(off) +} + /// Update an installed plugin to a new version with 3-way configuration merge. pub fn update( server: &Path, @@ -941,6 +989,7 @@ pub fn update( conf_files: new_meta.conf_files, deps: new_meta.deps, required: new_meta.required, + disabled_reason: None, }; reg.plugins.insert(new_meta.id, updated_entry); diff --git a/crates/coa-core/src/preview.rs b/crates/coa-core/src/preview.rs index 0e92ad6..f004a94 100644 --- a/crates/coa-core/src/preview.rs +++ b/crates/coa-core/src/preview.rs @@ -146,34 +146,9 @@ pub fn plan_sql_review(module_id: &str, report: &CompatibilityReport) -> Option< }) } -/// Installs a qualified build package into the realm's Plugin Store and enables it. -/// Enforces Stop-Gate and SQL Review Gate. -pub fn install_qualified_module( - realm_root: &Path, - module_id: &str, - version: &str, - apply_sql: bool, - sql_plan: Option<&SqlReviewPlan>, -) -> Result { - // 1. Enforce Stop-Gate - require_server_stopped(realm_root)?; - - // 2. Check SQL Review Gate - if let Some(plan) = sql_plan { - if !apply_sql && plan.total_sql_files > 0 { - return Ok(PreviewInstallResult { - success: false, - module_id: module_id.to_string(), - display_name: module_id.to_string(), - enabled: false, - sql_applied: false, - message: "SQL Review required before activating module. User confirmation needed.".into(), - sql_plan: Some(plan.clone()), - }); - } - } - - // 3. Locate package in plugin store +/// A module the build engine packaged into `.manager/plugin-store//`: its metadata, DLL and +/// configuration templates, ready for the registry. +pub fn built_package(realm_root: &Path, module_id: &str, version: &str) -> Result<(PluginMetadata, Vec, Vec<(String, Vec)>)> { let store_dir = realm_root.join(".manager").join("plugin-store").join(module_id).join(version); let dll_name = format!("{}.dll", module_id); let dll_path = store_dir.join(&dll_name); @@ -250,6 +225,40 @@ pub fn install_qualified_module( icon: None, }; + Ok((meta, dll_bytes, dist_confs)) +} + +/// Installs a qualified build package into the realm's Plugin Store and enables it. +/// Enforces Stop-Gate and SQL Review Gate. +pub fn install_qualified_module( + realm_root: &Path, + module_id: &str, + version: &str, + apply_sql: bool, + sql_plan: Option<&SqlReviewPlan>, +) -> Result { + // 1. Enforce Stop-Gate + require_server_stopped(realm_root)?; + + // 2. Check SQL Review Gate + if let Some(plan) = sql_plan { + if !apply_sql && plan.total_sql_files > 0 { + return Ok(PreviewInstallResult { + success: false, + module_id: module_id.to_string(), + display_name: module_id.to_string(), + enabled: false, + sql_applied: false, + message: "SQL Review required before activating module. User confirmation needed.".into(), + sql_plan: Some(plan.clone()), + }); + } + } + + // 3. Locate package in plugin store + let (meta, dll_bytes, dist_confs) = built_package(realm_root, module_id, version)?; + let display_name = meta.name.clone(); + let dist_confs_ref: Vec<(String, &[u8])> = dist_confs.iter().map(|(n, b)| (n.clone(), b.as_slice())).collect(); // 4. Execute transactional install into store & enable in plugins.lock diff --git a/crates/coa-core/src/rebuild.rs b/crates/coa-core/src/rebuild.rs new file mode 100644 index 0000000..7ac963e --- /dev/null +++ b/crates/coa-core/src/rebuild.rs @@ -0,0 +1,241 @@ +//! Keeps installed plugins usable across core changes. +//! +//! A plugin loads only into the core whose ABI fingerprint it was built with, and the core changes almost +//! every day. After a core update (or a rollback) every plugin that should run is brought to the current +//! fingerprint: an earlier build already in the store is reused, otherwise it is rebuilt from the sources +//! it was last built from. A plugin that cannot be brought up to date is switched off with the reason; the +//! core update itself always goes ahead. + +use std::fs; +use std::path::Path; + +use serde::Serialize; + +use crate::build_engine; +use crate::error::Result; +use crate::plugins; + +#[derive(Debug, Clone, Serialize, PartialEq, Eq)] +#[serde(tag = "result", rename_all = "camelCase")] +pub enum ModuleRebuild { + /// Already built for this core. + UpToDate { id: String }, + /// An earlier build for this core was still in the store (a rollback to a core seen before). + Reused { id: String }, + Rebuilt { id: String, seconds: u64 }, + /// Switched off; `also` lists the plugins that depend on it and were switched off with it. + Disabled { id: String, reason: String, also: Vec }, +} + +/// Whether a plugin takes part: enabled, or switched off earlier only because a rebuild failed. +fn wanted(entry: &plugins::PluginEntry) -> bool { + entry.installed && (entry.enabled || entry.disabled_reason.is_some()) +} + +/// Brings every plugin that should run to the realm's current core. Does nothing for a core without +/// plugin support. Never fails because of one plugin: each outcome is reported. +pub fn rebuild_for_current_core( + realm_root: &Path, + progress: &dyn Fn(&str, &str), +) -> Result> { + let Some(host) = crate::provenance::realm_host_fingerprint(realm_root) else { + return Ok(Vec::new()); + }; + let registry = plugins::load_registry(realm_root)?; + let mut out = Vec::new(); + for (id, entry) in registry.plugins.iter().filter(|(_, e)| wanted(e)) { + if entry.enabled && plugins::installed_plugin_fingerprint(realm_root, id).as_deref() == Some(host.as_str()) { + out.push(ModuleRebuild::UpToDate { id: id.clone() }); + continue; + } + if out.iter().any(|o| matches!(o, ModuleRebuild::Disabled { also, .. } if also.contains(id))) { + continue; // switched off together with a plugin it depends on + } + progress(id, "Building the module for the new core"); + let result = bring_up_to_date(realm_root, id, &host, progress).and_then(|done| { + if !plugins::load_registry(realm_root).map_err(|e| e.to_string())?.plugins.get(id).is_some_and(|e| e.enabled) { + plugins::set_enabled(realm_root, id, true).map_err(|e| e.to_string())?; + } + Ok(done) + }); + out.push(match result { + Ok(done) => done, + Err(reason) => { + let reason = first_line(&reason); + progress(id, &format!("Switched off: {reason}")); + let off = plugins::disable_with_reason(realm_root, id, &reason)?; + ModuleRebuild::Disabled { id: id.clone(), reason, also: off.into_iter().skip(1).collect() } + } + }); + } + Ok(out) +} + +fn bring_up_to_date( + realm_root: &Path, + id: &str, + host: &str, + progress: &dyn Fn(&str, &str), +) -> std::result::Result { + if let Some(sha) = stored_build_for(realm_root, id, host) { + reuse_stored(realm_root, id, &sha).map_err(|e| e.to_string())?; + return Ok(ModuleRebuild::Reused { id: id.to_string() }); + } + let recipe = build_engine::read_build_recipe(realm_root, id) + .ok_or("the manager does not know which sources this module was built from; install it again")?; + if !recipe.source_dir.is_dir() || recipe.bundled.iter().any(|b| !b.is_dir()) { + return Err("the module's sources are no longer on this PC; install it again".into()); + } + let started = std::time::Instant::now(); + let built = build_engine::build_module_with_bundle(&recipe.source_dir, &recipe.bundled, realm_root, None, None) + .map_err(|e| e.to_string())?; + if built.module_id != id { + return Err(format!("the sources now build module '{}', not '{id}'", built.module_id)); + } + progress(id, "Installing the rebuilt module"); + let (meta, dll, confs) = crate::preview::built_package(realm_root, 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::update(realm_root, meta, &dll, None, &confs).map_err(|e| e.to_string())?; + if plugins::installed_plugin_fingerprint(realm_root, id).as_deref() != Some(host) { + return Err("the rebuilt module does not match the installed core".into()); + } + Ok(ModuleRebuild::Rebuilt { id: id.to_string(), seconds: started.elapsed().as_secs() }) +} + +/// The store keeps every build by content hash: find one made for `host`. +fn stored_build_for(realm_root: &Path, id: &str, host: &str) -> Option { + let dir = plugins::store_dir(realm_root).join(id); + fs::read_dir(dir).ok()?.flatten().find_map(|e| { + let dll = e.path().join(format!("{id}.dll")); + (crate::provenance::file_abi_fingerprint(&dll).as_deref() == Some(host)) + .then(|| e.file_name().to_string_lossy().into_owned()) + }) +} + +fn reuse_stored(realm_root: &Path, id: &str, sha: &str) -> Result<()> { + let dir = plugins::store_dir(realm_root).join(id).join(sha); + let meta = plugins::load_store_metadata(realm_root, id, sha)?; + let dll = fs::read(dir.join(format!("{id}.dll")))?; + let mut confs = Vec::new(); + for name in &meta.conf_files { + if let Ok(bytes) = fs::read(dir.join(name)) { + confs.push((name.clone(), bytes)); + } + } + let confs: Vec<(String, &[u8])> = confs.iter().map(|(n, b)| (n.clone(), b.as_slice())).collect(); + plugins::update(realm_root, meta, &dll, None, &confs) +} + +fn first_line(s: &str) -> String { + let line = s.lines().find(|l| !l.trim().is_empty()).unwrap_or(s).trim(); + if line.chars().count() > 300 { line.chars().take(300).collect::() + "…" } else { line.to_string() } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::plugins::{PluginMetadata, PluginsRegistry}; + use std::collections::BTreeMap; + + /// The smallest PE image with a ".coapl" section, as plugins and plugin hosts carry it. + fn image(id: &str, fp: &str) -> Vec { + let text = format!("COAPLUGIN1|{id}|{fp}\0"); + let mut b = vec![0u8; 0x200]; + b[0] = b'M'; + b[1] = b'Z'; + b[0x3C..0x40].copy_from_slice(&0x40u32.to_le_bytes()); + b[0x40..0x44].copy_from_slice(b"PE\0\0"); + b[0x46..0x48].copy_from_slice(&1u16.to_le_bytes()); // one section, no optional header + let sec = 0x40 + 24; + b[sec..sec + 6].copy_from_slice(b".coapl"); + let len = text.len() as u32; + b[sec + 8..sec + 12].copy_from_slice(&len.to_le_bytes()); + b[sec + 16..sec + 20].copy_from_slice(&len.to_le_bytes()); + b[sec + 20..sec + 24].copy_from_slice(&0x100u32.to_le_bytes()); + b[0x100..0x100 + text.len()].copy_from_slice(text.as_bytes()); + b + } + + fn meta(id: &str, dll: &[u8]) -> PluginMetadata { + PluginMetadata { + id: id.into(), + name: id.into(), + version: "1.0.0".into(), + description: BTreeMap::new(), + sha256: plugins::sha256_digest(dll), + required: false, + deps: vec![], + conf_files: vec![], + enable_key: None, + status: None, + icon: None, + } + } + + fn registry(server: &Path) -> PluginsRegistry { + plugins::load_registry(server).unwrap() + } + + #[test] + fn plugins_follow_the_core_or_are_switched_off_with_a_reason() { + let old_fp = "a".repeat(64); + let new_fp = "b".repeat(64); + let dir = tempfile::tempdir().unwrap(); + let server = dir.path(); + fs::create_dir_all(server.join("Core")).unwrap(); + fs::write(server.join("Core/worldserver.exe"), image("worldserver", &old_fp)).unwrap(); + + // "kept" was built for both cores (the store has both builds); "lost" only for the old one and + // the manager has no recipe to rebuild it from. + let kept_new = image("kept", &new_fp); + let kept_old = image("kept", &old_fp); + plugins::install(server, meta("kept", &kept_new), &kept_new, None, &[], true).unwrap(); + plugins::update(server, meta("kept", &kept_old), &kept_old, None, &[]).unwrap(); + let lost = image("lost", &old_fp); + plugins::install(server, meta("lost", &lost), &lost, None, &[], true).unwrap(); + // A plugin the owner switched off stays off and is not rebuilt. + let idle = image("idle", &old_fp); + plugins::install(server, meta("idle", &idle), &idle, None, &[], false).unwrap(); + + // Same core: nothing to do. + let same = rebuild_for_current_core(server, &|_, _| {}).unwrap(); + assert_eq!(same, vec![ + ModuleRebuild::UpToDate { id: "kept".into() }, + ModuleRebuild::UpToDate { id: "lost".into() }, + ]); + + // New core. + fs::write(server.join("Core/worldserver.exe"), image("worldserver", &new_fp)).unwrap(); + let out = rebuild_for_current_core(server, &|_, _| {}).unwrap(); + assert_eq!(out[0], ModuleRebuild::Reused { id: "kept".into() }); + assert!(matches!(&out[1], ModuleRebuild::Disabled { id, reason, .. } if id == "lost" && reason.contains("install it again"))); + assert_eq!(out.len(), 2); + let reg = registry(server); + assert!(reg.plugins["kept"].enabled); + assert_eq!(plugins::installed_plugin_fingerprint(server, "kept").as_deref(), Some(new_fp.as_str())); + assert!(!reg.plugins["lost"].enabled); + assert!(reg.plugins["lost"].disabled_reason.is_some()); + assert!(!reg.plugins["idle"].enabled && reg.plugins["idle"].disabled_reason.is_none()); + let lock = fs::read_to_string(plugins::lockfile_path(server)).unwrap(); + assert!(lock.contains("kept") && !lock.contains("\"lost\""), "{lock}"); + + // Back to the old core (a rollback): the old builds are put back, "lost" is switched on again. + fs::write(server.join("Core/worldserver.exe"), image("worldserver", &old_fp)).unwrap(); + let back = rebuild_for_current_core(server, &|_, _| {}).unwrap(); + assert_eq!(back, vec![ + ModuleRebuild::Reused { id: "kept".into() }, + ModuleRebuild::Reused { id: "lost".into() }, + ]); + let reg = registry(server); + assert!(reg.plugins["kept"].enabled && reg.plugins["lost"].enabled); + assert!(reg.plugins["lost"].disabled_reason.is_none()); + } + + #[test] + fn a_monolithic_core_needs_no_rebuild() { + let dir = tempfile::tempdir().unwrap(); + fs::create_dir_all(dir.path().join("Core")).unwrap(); + fs::write(dir.path().join("Core/worldserver.exe"), b"MZ no plugin host").unwrap(); + assert!(rebuild_for_current_core(dir.path(), &|_, _| {}).unwrap().is_empty()); + } +} diff --git a/crates/coa-core/src/update.rs b/crates/coa-core/src/update.rs index 76daf3e..d0ef646 100644 --- a/crates/coa-core/src/update.rs +++ b/crates/coa-core/src/update.rs @@ -116,6 +116,11 @@ pub trait Env { fn migrate(&self, manifest: &Manifest, staged_migrations: &Path) -> Result; /// Start the server and confirm it becomes healthy. fn validate(&self) -> Result<()>; + /// Bring installed plugins to the new core before it is started. Never fails the update: a plugin + /// that cannot be rebuilt is switched off and reported. + fn rebuild_plugins(&self, _report: &dyn Fn(&str, &str)) -> Vec { + Vec::new() + } } fn updates_dir(meta: &Path) -> PathBuf { @@ -692,6 +697,9 @@ pub struct Outcome { pub txn: Txn, pub preexisting_character_count: usize, pub migrations: Option, + /// What happened to each installed plugin on the new core (rebuilt, reused or switched off). + #[serde(default)] + pub modules: Vec, } fn step(report: &dyn Fn(&str, u8), name: &str, pct: u8) { @@ -916,6 +924,9 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result { } } + step(report, "Building modules for the new core", 80); + let modules = p.env.rebuild_plugins(&|id, what| report(&format!("{id}: {what}"), 80)); + step(report, "Starting the updated server", 85); // Core startup can apply SQL and write character data even when the package has no explicit migrations. txn.databases_started = true; @@ -938,6 +949,7 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result { txn, preexisting_character_count, migrations: migrated, + modules, }); } @@ -949,6 +961,7 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result { txn, preexisting_character_count, migrations: migrated, + modules, }) } @@ -1198,6 +1211,9 @@ fn restore_transaction( if saved_meta.exists() { fsx::atomic_write(&meta.join("install.json"), &fs::read(saved_meta)?)?; } + // Plugins may already have been rebuilt for the core that was just taken back out; the builds for + // the restored core are still in the plugin store and are put back (or rebuilt). + let _ = env.rebuild_plugins(&|_, _| {}); Ok(()) } @@ -1703,6 +1719,17 @@ impl RepackEnv<'_> { } impl Env for RepackEnv<'_> { + fn rebuild_plugins(&self, report: &dyn Fn(&str, &str)) -> Vec { + match crate::rebuild::rebuild_for_current_core(self.root, report) { + Ok(done) => done, + Err(e) => { + tracing::warn!(error = %e, "plugins could not be brought to the new core"); + report("modules", &format!("not rebuilt: {e}")); + Vec::new() + } + } + } + fn recover_validation(&self) -> Result<()> { crate::update_isolation::restore(self.root, self.meta_dir) } diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index fee3534..b722def 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -3,6 +3,8 @@ import type en from "./en"; /** Deutsch. Entwurf einer Übersetzung; vor der Veröffentlichung von Muttersprachlern zu prüfen. */ const de: Partial> = { "upd.preexistingCharacters": "Bereits vor dem Update fehlten bei {n} Charakterdatensätzen die Startdaten für Volk/Klasse. Unveränderte Datensätze wurden bewahrt und blockierten das Update nicht. Details stehen in der Diagnose; diese älteren Unstimmigkeiten wurden nicht automatisch behoben.", + "upd.modulesRebuilt": "Für den neuen Core neu gebaute Module: {list}.", + "upd.moduleOff": "Modul {id} wurde abgeschaltet, weil es sich nicht für den neuen Core bauen ließ: {reason}. Der Server wurde ohne es aktualisiert.", "settings.autoManager": "Updates im Hintergrund herunterladen", "settings.startServer": "Nach dem Update starten", "settings.version": "Version {v}", diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index de74805..1c5790e 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -1,6 +1,8 @@ /** English is the source of truth: every key must exist here; other locales fall back to it. */ const en = { "upd.preexistingCharacters": "Before the update, {n} character records already lacked race/class starting data. Unchanged records were preserved and did not block the update. Details are saved in diagnostics; these older inconsistencies have not been automatically repaired.", + "upd.modulesRebuilt": "Modules rebuilt for the new core: {list}.", + "upd.moduleOff": "Module {id} was switched off because it could not be built for the new core: {reason}. The server was updated without it.", "settings.autoManager": "Download updates in the background", "settings.startServer": "Start after updating", "settings.version": "Version {v}", diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index 3bd966c..2279adb 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -3,6 +3,8 @@ import type en from "./en"; /** Español. Traducción provisional; debe revisarla un hablante nativo antes de publicarse. */ const es: Partial> = { "upd.preexistingCharacters": "Antes de actualizar, a {n} registros de personaje ya les faltaban datos iniciales de raza/clase. Los registros sin cambios se conservaron y no bloquearon la actualización. Los detalles están en el diagnóstico; estas inconsistencias anteriores no se repararon automáticamente.", + "upd.modulesRebuilt": "Módulos recompilados para el nuevo núcleo: {list}.", + "upd.moduleOff": "El módulo {id} se desactivó porque no se pudo compilar para el nuevo núcleo: {reason}. El servidor se actualizó sin él.", "settings.autoManager": "Descargar actualizaciones en segundo plano", "settings.startServer": "Iniciar tras actualizar", "settings.version": "Versión {v}", diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index a1a4f25..5916e17 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -3,6 +3,8 @@ import type en from "./en"; /** Français. Traduction provisoire ; à faire relire par un locuteur natif avant la publication. */ const fr: Partial> = { "upd.preexistingCharacters": "Avant la mise à jour, {n} fiches de personnage n’avaient déjà pas de données de départ pour leur race/classe. Les fiches inchangées ont été conservées sans bloquer la mise à jour. Les détails sont dans le diagnostic ; ces incohérences anciennes n’ont pas été corrigées automatiquement.", + "upd.modulesRebuilt": "Modules recompilés pour le nouveau cœur : {list}.", + "upd.moduleOff": "Le module {id} a été désactivé, car il n’a pas pu être compilé pour le nouveau cœur : {reason}. Le serveur a été mis à jour sans lui.", "settings.autoManager": "Télécharger les mises à jour en arrière-plan", "settings.startServer": "Démarrer après la mise à jour", "settings.version": "Version {v}", diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index cf9b496..6a61136 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -3,6 +3,8 @@ import type en from "./en"; /** Русский. Черновой перевод; требует проверки носителем перед релизом. */ const ru: Partial> = { "upd.preexistingCharacters": "До обновления у {n} записей персонажей уже отсутствовали стартовые данные расы/класса. Неизменившиеся записи сохранены и не заблокировали обновление. Подробности есть в диагностике; эти старые несоответствия автоматически не исправлялись.", + "upd.modulesRebuilt": "Модули пересобраны под новое ядро: {list}.", + "upd.moduleOff": "Модуль {id} выключен: его не удалось собрать под новое ядро ({reason}). Сервер обновлён без него.", "settings.autoManager": "Скачивать обновления в фоне", "settings.startServer": "Запустить после обновления", "settings.version": "Версия {v}", diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index dab7ba6..e7054bf 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -1,6 +1,8 @@ /** Simplified Chinese localization (zh-CN) */ const zh = { "upd.preexistingCharacters": "更新前已有 {n} 条角色记录缺少种族/职业初始数据。未变化的记录已保留,不会阻止更新。详情已保存到诊断报告;这些既有问题尚未自动修复。", + "upd.modulesRebuilt": "已为新核心重新编译的模块:{list}。", + "upd.moduleOff": "模块 {id} 无法为新核心编译,已被关闭:{reason}。服务器已在没有它的情况下完成更新。", "settings.autoManager": "在后台下载更新", "settings.startServer": "更新后启动", "settings.version": "版本 {v}", diff --git a/src/lib/api.ts b/src/lib/api.ts index 8aabac5..c265bd0 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -6,6 +6,12 @@ const queuedUpdateCheck = updateCheckQueue(); export const REMOTE_CLIENT_ID = "@remote-client"; export interface RemoteConnection { host: string; client_path: string | null } +/** What an update did to an installed plugin on the new core (coa-core rebuild::ModuleRebuild). */ +export type ModuleRebuild = + | { result: "upToDate" | "reused"; id: string } + | { result: "rebuilt"; id: string; seconds: number } + | { result: "disabled"; id: string; reason: string; also: string[] }; + export type Classification = "healthy" | "partial" | "unknown-custom" | "incompatible"; export type ItemStatus = "found" | "missing" | "attention"; @@ -798,7 +804,7 @@ export const api = { ), pendingUpdate: (id: string) => invoke("pending_update", { id }), applyUpdate: (id: string, resolutions: Record, source?: string) => - invoke<{ txn: UpdateTxn; preexisting_character_count?: number }>("apply_update", { id, source: source ?? null, resolutions }), + invoke<{ txn: UpdateTxn; preexisting_character_count?: number; modules?: ModuleRebuild[] }>("apply_update", { id, source: source ?? null, resolutions }), rollbackUpdate: (id: string, txn: string) => invoke("rollback_update", { id, txn }), retryUpdateValidation: (id: string, txn: string) => invoke("retry_update_validation", { id, txn }), population: (id: string) => invoke("get_population", { id }), diff --git a/src/lib/serverUpdate.ts b/src/lib/serverUpdate.ts index 3bacd07..fca9e28 100644 --- a/src/lib/serverUpdate.ts +++ b/src/lib/serverUpdate.ts @@ -22,7 +22,7 @@ export interface ServerUpdateState { stateError: UiError | null; stateRevision: number; /** How the last update ended; kept here so the Settings card can show it after the user left and came back. */ - result: { committed: string; preexistingCharacters?: number } | { pending: UpdateTxn } | null; + result: { committed: string; preexistingCharacters?: number; modulesRebuilt?: string[]; modulesOff?: { id: string; reason: string }[] } | { pending: UpdateTxn } | null; } const EMPTY: ServerUpdateState = { preview: null, available: false, checking: false, applying: false, step: null, percent: 0, error: null, uiError: null, stateError: null, stateRevision: 0, result: null }; @@ -105,7 +105,10 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record m.result === "rebuilt" || m.result === "reused").map((m) => m.id); + const off = mods.flatMap((m) => m.result === "disabled" ? [{ id: m.id, reason: m.reason }, ...m.also.map((a) => ({ id: a, reason: m.reason }))] : []); + set(id, { result: out.txn.state === "committed" ? { committed: out.txn.to_version ?? "", ...(out.preexisting_character_count ? { preexistingCharacters: out.preexisting_character_count } : {}), ...(rebuilt.length ? { modulesRebuilt: rebuilt } : {}), ...(off.length ? { modulesOff: off } : {}) } : { pending: out.txn } }); if (out.txn.state === "committed" && !wasRunning && !startAfterUpdate("server", id)) await api.stop(id).catch(() => undefined); return true; } catch (e) { diff --git a/src/screens/Overview.tsx b/src/screens/Overview.tsx index 9252e89..4676d3f 100644 --- a/src/screens/Overview.tsx +++ b/src/screens/Overview.tsx @@ -551,6 +551,8 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o

)} {upd.result && "committed" in upd.result && !!upd.result.preexistingCharacters &&

{t("upd.preexistingCharacters", { n: upd.result.preexistingCharacters })}

} + {upd.result && "committed" in upd.result && !!upd.result.modulesRebuilt?.length &&

{t("upd.modulesRebuilt", { list: upd.result.modulesRebuilt.join(", ") })}

} + {upd.result && "committed" in upd.result && upd.result.modulesOff?.map((m) =>

{t("upd.moduleOff", { id: m.id, reason: m.reason })}

)} {upd.available && upd.preview && (

{t("overview.updateAvail", { to: upd.preview.to_version, from: upd.preview.from_version ?? "?" })}