From d971fd5e28a5045e5f2273ee5786351cb582c3f1 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: Tue, 6 Oct 2026 08:36:34 +0500 Subject: [PATCH] fix(portable): carry only the minimal build/spec/starter/reset settings (Phase 2.1) character_settings policy v2: the carry list is ten strict key patterns (core.ascension_active_spec, _starter, _starter_live, _reset_credits, _slot.active, _slot.#, _slot.#.build.#, _slot.#.bar.#, _build.#, _bar.#), matched exactly, not by prefix. Spell charges, Destiny Weaver, dynamic XP, Runemaster, prestige/glory, tutorial flags, Wildcard state and anything unknown are quarantined in the opaque extension and never applied. The importer's own marker source (coa.portable.) is dropped. Co-Authored-By: Claude Sonnet 5.5 --- crates/coa-core/src/portable/realm/policy.rs | 164 ++++++++++++++----- crates/coa-core/src/portable/realm/tests.rs | 19 ++- docs/PORTABLE_EXPORT.md | 22 ++- 3 files changed, 155 insertions(+), 50 deletions(-) diff --git a/crates/coa-core/src/portable/realm/policy.rs b/crates/coa-core/src/portable/realm/policy.rs index 0c3bcc7..f2c4e19 100644 --- a/crates/coa-core/src/portable/realm/policy.rs +++ b/crates/coa-core/src/portable/realm/policy.rs @@ -1,21 +1,30 @@ -//! Which `character_settings` sources travel with a character (decision D2). +//! Which `character_settings` sources travel with a character (decision D2, tightened in Phase 2.1). //! //! `character_settings` is a free-form `(guid, source) -> integers` store used by the core and by modules; CoA keeps its -//! specialisation, talent builds and per-spec action bars there. The list is versioned data, not scattered `if`s: +//! specialisation, talent builds and per-spec action bars there. Only the **minimal build / spec / starter / reset +//! state** is carried, by **strict key patterns** (no broad prefixes): //! -//! * `Carry` imported at the destination (known gameplay state); -//! * `Drop` never carried (bots, tests, high-risk bookkeeping); -//! * `Quarantine` kept in the canonical snapshot as an opaque extension but **not** imported anywhere; an unknown -//! source is never destroyed and never applied blindly. +//! * `Carry` applied at the destination: exactly the keys in [`CARRY`]; +//! * `Drop` never carried (bots, tests, high-risk bookkeeping, this importer's own marker); +//! * `Quarantine` everything else: kept in the canonical snapshot as an opaque extension, **never applied** at a realm +//! (spell charges, Destiny Weaver, dynamic XP, Runemaster, prestige/glory, tutorial flags, Wildcard +//! state and anything unknown). +//! +//! In a pattern `#` stands for one run of 1-9 ASCII digits and every other character must match exactly, so +//! `core.ascension_build.54` is carried while `core.ascension_build.54x`, `core.ascension_build.`, +//! `core.ascension_build.54.extra` and `core.ascension_build.-1` are not. use super::super::model::Ruleset; -/// Bump when the lists change; recorded with the quarantined extension. -pub const SETTINGS_POLICY_VERSION: u32 = 1; +/// Bump when the lists change. +pub const SETTINGS_POLICY_VERSION: u32 = 2; /// Extension namespace holding the quarantined sources. pub const QUARANTINE_EXTENSION: &str = "coa:unlisted-settings"; +/// The source the offline importer writes to mark "this character was imported by import N": see `import.rs`. +pub const IMPORT_MARKER_SOURCE: &str = "coa.portable.import"; + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Disposition { Carry, @@ -23,34 +32,48 @@ pub enum Disposition { Quarantine, } -const CARRY_EXACT: &[&str] = &[ - "core.ascension", +/// The complete list of carried keys. `#` = digits. +pub const CARRY: &[&str] = &[ "core.ascension_active_spec", "core.ascension_starter", "core.ascension_starter_live", "core.ascension_reset_credits", "core.ascension_slot.active", - "core.destiny_weaver", - "core.dynamic_xp.preset", - "core.runemaster.echoes", - "core.coa_prestige", - "core.coa_prestige_bar", - "core.coa_glory", + "core.ascension_slot.#", + "core.ascension_slot.#.build.#", + "core.ascension_slot.#.bar.#", + "core.ascension_build.#", + "core.ascension_bar.#", ]; -const CARRY_PREFIX: &[&str] = &["core.ascension_slot.", "core.ascension_build.", "core.ascension_bar.", "core.spell_charge.", "core.ascension.tutorial_"]; +const DROP_PREFIX: &[&str] = &["coa.bot", "coa.gameplay_test", "coa.highrisk", "coa.portable."]; -const DROP_PREFIX: &[&str] = &["coa.bot", "coa.gameplay_test", "coa.highrisk"]; +/// Does `source` match `pattern`? `#` = 1-9 ASCII digits, anything else literal. +pub fn matches_pattern(source: &str, pattern: &str) -> bool { + fn go(s: &[u8], p: &[u8]) -> bool { + match p.split_first() { + None => s.is_empty(), + Some((b'#', rest)) => { + let digits = s.iter().take_while(|b| b.is_ascii_digit()).count().min(9); + // the digit run must be maximal: a digit right after it would make it longer than 9 digits + if digits == 0 || s.get(digits).is_some_and(|b| b.is_ascii_digit()) { + return false; + } + go(&s[digits..], rest) + } + Some((c, rest)) => s.first() == Some(c) && go(&s[1..], rest), + } + } + go(source.as_bytes(), pattern.as_bytes()) +} -pub fn classify_setting(source: &str, ruleset: Ruleset) -> Disposition { +/// The ruleset is accepted for forward compatibility: today every ruleset uses the same minimal list and Wildcard +/// state is quarantined until its keys have been reviewed one by one. +pub fn classify_setting(source: &str, _ruleset: Ruleset) -> Disposition { if DROP_PREFIX.iter().any(|p| source.starts_with(p)) { return Disposition::Drop; } - if source == "core.wildcard" || source.starts_with("core.wildcard.") { - // Wildcard state only means something to the Wildcard ruleset. - return if ruleset == Ruleset::Wildcard { Disposition::Carry } else { Disposition::Quarantine }; - } - if CARRY_EXACT.contains(&source) || CARRY_PREFIX.iter().any(|p| source.starts_with(p)) { + if CARRY.iter().any(|p| matches_pattern(source, p)) { return Disposition::Carry; } Disposition::Quarantine @@ -61,42 +84,109 @@ mod tests { use super::*; #[test] - fn known_coa_gameplay_state_is_carried() { + fn exactly_the_minimal_build_spec_starter_and_reset_state_is_carried() { for s in [ "core.ascension_active_spec", "core.ascension_starter", + "core.ascension_starter_live", + "core.ascension_reset_credits", "core.ascension_slot.active", "core.ascension_slot.2", + "core.ascension_slot.12", "core.ascension_slot.2.build.54", + "core.ascension_slot.2.bar.54", "core.ascension_build.54", "core.ascension_bar.54", - "core.spell_charge.804197", - "core.ascension.tutorial_verified", - "core.destiny_weaver", + "core.ascension_build.0", ] { assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Carry, "{s}"); } } #[test] - fn bots_tests_and_bookkeeping_are_dropped() { - for s in ["coa.bot.gear", "coa.bot_profile", "coa.gameplay_test", "coa.highrisk"] { + fn nonessential_state_is_quarantined_not_applied() { + for s in [ + "core.spell_charge.804197", + "core.spell_charge.712389", + "core.destiny_weaver", + "core.dynamic_xp.preset", + "core.runemaster.echoes", + "core.coa_prestige", + "core.coa_prestige_bar", + "core.coa_glory", + "core.ascension.tutorial_verified", + "core.ascension.tutorial_tracking", + "core.ascension", + "coa.gear_pref_weapon", + "coa.gear_pref_armor", + "mod.someone.new_feature", + "core.unheard_of", + ] { + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s}"); + } + } + + #[test] + fn keys_are_matched_strictly_not_by_prefix() { + for s in [ + "core.ascension_build.", + "core.ascension_build.54x", + "core.ascension_build.x54", + "core.ascension_build.54.extra", + "core.ascension_build.-1", + "core.ascension_build.+1", + "core.ascension_build.5 4", + "core.ascension_build.1234567890", + "core.ascension_slot.", + "core.ascension_slot.active.x", + "core.ascension_slot.2.build.", + "core.ascension_slot.2.build.54.1", + "core.ascension_slot.2.talent.54", + "core.ascension_slot..build.54", + "core.ascension_active_spec.1", + "core.ascension_active_spec ", + "core.ascension_bar", + "Core.Ascension_Active_Spec", + "core.ascension_starter_liveX", + "core.ascension_resetcredits", + ] { + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s:?} must not be carried"); + } + } + + #[test] + fn the_pattern_matcher_itself() { + assert!(matches_pattern("a.5", "a.#")); + assert!(matches_pattern("a.123456789", "a.#")); + assert!(!matches_pattern("a.1234567890", "a.#"), "more than nine digits"); + assert!(!matches_pattern("a.", "a.#")); + assert!(matches_pattern("a.1.b.22", "a.#.b.#")); + assert!(!matches_pattern("a.1.b.22.", "a.#.b.#")); + assert!(!matches_pattern("a.1b", "a.#.b")); + assert!(matches_pattern("", "")); + assert!(!matches_pattern("x", "")); + } + + #[test] + fn bots_tests_bookkeeping_and_the_importers_own_marker_are_dropped() { + for s in ["coa.bot.gear", "coa.bot_profile", "coa.gameplay_test", "coa.highrisk", "coa.portable.import"] { assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Drop, "{s}"); } } #[test] - fn unknown_sources_are_quarantined_never_dropped() { - for s in ["mod.someone.new_feature", "core.unheard_of", "coa.gear_pref_weapon", "core.ascensionx"] { + fn wildcard_state_is_quarantined_on_every_ruleset_until_reviewed() { + for s in ["core.wildcard", "core.wildcard.cards", "core.wildcard.spec", "core.wildcard.scrolls.spec2"] { + assert_eq!(classify_setting(s, Ruleset::Wildcard), Disposition::Quarantine, "{s}"); assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s}"); } + // the carried keys are the same on a Wildcard realm + assert_eq!(classify_setting("core.ascension_active_spec", Ruleset::Wildcard), Disposition::Carry); } #[test] - fn wildcard_state_belongs_to_the_wildcard_ruleset() { - for s in ["core.wildcard", "core.wildcard.cards", "core.wildcard.scrolls.spec2"] { - assert_eq!(classify_setting(s, Ruleset::Wildcard), Disposition::Carry, "{s}"); - assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s}"); - } + fn the_carry_list_is_exactly_what_was_approved() { + assert_eq!(CARRY.len(), 10); + assert!(CARRY.iter().all(|p| p.starts_with("core.ascension_")), "nothing outside the ascension build/spec/starter/reset family"); } } diff --git a/crates/coa-core/src/portable/realm/tests.rs b/crates/coa-core/src/portable/realm/tests.rs index 16348a1..729151a 100644 --- a/crates/coa-core/src/portable/realm/tests.rs +++ b/crates/coa-core/src/portable/realm/tests.rs @@ -180,16 +180,17 @@ fn spells_talents_glyphs_skills_settings_and_macros() { assert_eq!(m.settings["core.ascension_build.54"], vec![3, 56710, 56320, 90101]); assert_eq!(m.settings["core.ascension_bar.54"], vec![2, 0, 500_003, 1, 500_006]); assert_eq!(m.settings["core.ascension_slot.active"], vec![0]); - assert_eq!(m.settings["core.spell_charge.804197"], vec![2, 1_790_000_000]); - // bots: dropped; unknown / other rulesets' state: kept aside, not carried + // bots: dropped; nonessential and unknown state is quarantined: kept aside, never applied (policy v2) assert!(!m.settings.contains_key("coa.bot.gear")); - for aside in ["coa.gear_pref_weapon", "mod.example.new_feature", "core.wildcard.cards"] { + for aside in ["coa.gear_pref_weapon", "core.spell_charge.804197", "mod.example.new_feature", "core.wildcard.cards"] { assert!(!m.settings.contains_key(aside), "{aside} must not be carried"); } let ext = &m.extensions["coa:unlisted-settings"]; assert!(ext.is_intact()); let aside: std::collections::BTreeMap> = serde_json::from_slice(&ext.payload.0).unwrap(); - assert_eq!(aside.keys().map(String::as_str).collect::>(), vec!["coa.gear_pref_weapon", "core.wildcard.cards", "mod.example.new_feature"]); + assert_eq!(aside.keys().map(String::as_str).collect::>(), vec!["coa.gear_pref_weapon", "core.spell_charge.804197", "core.wildcard.cards", "mod.example.new_feature"]); + assert_eq!(aside["core.spell_charge.804197"], vec![2, 1_790_000_000], "the values are kept exactly"); + assert_eq!(m.settings.keys().map(String::as_str).collect::>(), vec!["core.ascension_active_spec", "core.ascension_bar.54", "core.ascension_build.54", "core.ascension_slot.active", "core.ascension_starter"]); assert_eq!(aside["mod.example.new_feature"], vec![9, 8, 7]); assert!(e.warnings.iter().any(|w| w.contains("kept aside"))); @@ -330,14 +331,18 @@ fn the_same_realm_data_gives_the_same_canonical_bytes() { } #[test] -fn the_wildcard_ruleset_reads_wildcard_state_and_uses_its_own_namespace() { +fn the_wildcard_ruleset_uses_its_own_namespace_and_quarantines_wildcard_state() { let coa = export_as(1004, Ruleset::Coa, &HashMap::new()).unwrap().model; let wildcard = export_as(1004, Ruleset::Wildcard, &HashMap::new()).unwrap().model; assert_eq!(wildcard.ruleset, Ruleset::Wildcard); assert_eq!(wildcard.content_namespace, "wildcard"); assert_eq!(wildcard.identity.class.to_string(), "wildcard:class:25"); - assert!(wildcard.settings.contains_key("core.wildcard.cards"), "Wildcard state is gameplay state on a Wildcard realm"); - assert!(!coa.settings.contains_key("core.wildcard.cards")); + // Wildcard keys are not on the carry list on any ruleset (policy v2); they are kept, not applied + for m in [&coa, &wildcard] { + assert!(!m.settings.contains_key("core.wildcard.cards")); + assert!(m.extensions["coa:unlisted-settings"].is_intact()); + } + assert_eq!(wildcard.settings, coa.settings); // the realm profile of a database decides the ruleset, not the caller let wc_db = Db::with_tools(std::path::PathBuf::new(), 1, "root", "x", Mode::Wildcard); let coa_db = Db::with_tools(std::path::PathBuf::new(), 1, "root", "x", Mode::Coa); diff --git a/docs/PORTABLE_EXPORT.md b/docs/PORTABLE_EXPORT.md index 34390a5..8b722eb 100644 --- a/docs/PORTABLE_EXPORT.md +++ b/docs/PORTABLE_EXPORT.md @@ -62,13 +62,23 @@ quests, position and homebind are never part of v1. Left out *with a warning* (the realm would delete them on load anyway): inventory rows without an `item_instance`, items in a bag that is not on the character, items in buyback slots. -### `character_settings` policy (`policy.rs`, version 1) +### `character_settings` policy (`policy.rs`, version 2) -* **Carry**: known CoA gameplay state (`core.ascension_*`, `core.spell_charge.*`, `core.destiny_weaver`, ...), and - `core.wildcard*` on a Wildcard realm. -* **Drop**: `coa.bot*`, `coa.gameplay_test`, `coa.highrisk`. -* **Quarantine**: everything else is kept in the snapshot as the opaque extension `coa:unlisted-settings` (never - destroyed, never applied at a realm). +Only the **minimal build / spec / starter / reset state** is carried, and only by strict key patterns (`#` = 1-9 digits, +everything else literal; no broad prefixes): + +``` +core.ascension_active_spec core.ascension_starter core.ascension_starter_live +core.ascension_reset_credits core.ascension_slot.active core.ascension_slot.# +core.ascension_slot.#.build.# core.ascension_slot.#.bar.# core.ascension_build.# core.ascension_bar.# +``` + +* **Quarantine**: everything else (`core.spell_charge.*`, Destiny Weaver, dynamic XP, Runemaster, prestige/glory, + tutorial flags, Wildcard state, unknown sources) is kept in the snapshot as the opaque extension + `coa:unlisted-settings` with its values, and is **never applied** at a realm. +* **Drop**: `coa.bot*`, `coa.gameplay_test`, `coa.highrisk`, `coa.portable.` (the importer's own marker). + +Version 1 (Phase 2) carried broad prefixes; version 2 is the corrective Phase 2.1 change. ### Table registry (`registry.rs`)