From fc38adeba20b9e4d09ba967431db443815d32155 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:37:57 +0100 Subject: [PATCH] Preserve retained planet and Lobby JARVIS variants in DuneGroups rollout --- .forgejo/workflows/dunegroups.yml | 7 ++- JarvisConnector/build.gradle.kts | 8 +++ .../dunerealms/jarvis/NativeKeyWorker.java | 23 ++++++++ tools/install-plugin-fleet.py | 38 +++++++----- tools/plugin_dunegroups.py | 58 +++++++++++++------ tools/plugin_fleet_rollback.py | 5 +- tools/test_plugin_dunegroups.py | 7 +++ 7 files changed, 110 insertions(+), 36 deletions(-) create mode 100644 JarvisConnector/src/lobbyDuneGroups/java/com/dunerealms/jarvis/NativeKeyWorker.java diff --git a/.forgejo/workflows/dunegroups.yml b/.forgejo/workflows/dunegroups.yml index ee0121fc..baf8af82 100644 --- a/.forgejo/workflows/dunegroups.yml +++ b/.forgejo/workflows/dunegroups.yml @@ -2,7 +2,7 @@ name: DuneGroups Replacement Build on: workflow_dispatch: push: - branches: ['feat/dunegroups-replacement-*'] + branches: ['feat/dunegroups-replacement-*', 'feat/dunegroups-fleet-*'] jobs: dunegroups: @@ -28,14 +28,15 @@ jobs: shell: bash run: | set -euo pipefail - gradle --no-daemon -p JarvisConnector test jar + gradle --no-daemon -p JarvisConnector test jar compileLobbyDuneGroupsBridge gradle --no-daemon -p DuneGroups test jar python3 tools/test_plugin_dunegroups.py -v mkdir dunegroups-artifacts cp JarvisConnector/build/libs/jarvistranslator.jar DuneGroups/build/libs/DuneGroups.jar dunegroups-artifacts/ + cp JarvisConnector/build/classes/lobby-dunegroups/com/dunerealms/jarvis/NativeKeyWorker.class dunegroups-artifacts/lobby-native-key-worker.class cp tools/{plugin_dunegroups,install-plugin-fleet,write-plugin-manifest,plugin_menu_pack,plugin_backend_abi,plugin_fleet_rollback,plugin_pack_properties,plugin_pillager_abi}.py dunegroups-artifacts/ printf '%s\n' "$(git rev-parse HEAD)" > dunegroups-artifacts/SOURCE_COMMIT - (cd dunegroups-artifacts && sha256sum -- *.jar *.py SOURCE_COMMIT > SHA256SUMS) + (cd dunegroups-artifacts && sha256sum -- *.jar *.py *.class SOURCE_COMMIT > SHA256SUMS) - uses: actions/upload-artifact@v3 with: name: DuneRealms-DuneGroups-Replacement diff --git a/JarvisConnector/build.gradle.kts b/JarvisConnector/build.gradle.kts index 0f34f47f..6c7fa07d 100644 --- a/JarvisConnector/build.gradle.kts +++ b/JarvisConnector/build.gradle.kts @@ -21,3 +21,11 @@ tasks.processResources { } sourceSets.main { java.srcDir("../citizens-common/src/main/java") } + +tasks.register("compileLobbyDuneGroupsBridge") { + dependsOn(tasks.classes) + source("src/lobbyDuneGroups/java/com/dunerealms/jarvis/NativeKeyWorker.java") + classpath = sourceSets.main.get().output + configurations.compileClasspath.get() + destinationDirectory.set(layout.buildDirectory.dir("classes/lobby-dunegroups")) + javaCompiler.set(javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(21)) }) +} diff --git a/JarvisConnector/src/lobbyDuneGroups/java/com/dunerealms/jarvis/NativeKeyWorker.java b/JarvisConnector/src/lobbyDuneGroups/java/com/dunerealms/jarvis/NativeKeyWorker.java new file mode 100644 index 00000000..690b3a55 --- /dev/null +++ b/JarvisConnector/src/lobbyDuneGroups/java/com/dunerealms/jarvis/NativeKeyWorker.java @@ -0,0 +1,23 @@ +package com.dunerealms.jarvis; + +import org.bukkit.plugin.java.JavaPlugin; + +/** Entry point for the retained Lobby translator, which does not expose a backend switch. */ +final class NativeKeyWorker implements AutoCloseable { + private final DuneGroupsKeyWorker worker; + + NativeKeyWorker(JavaPlugin plugin, SharedGameApi api) throws ReflectiveOperationException { + if (!"dunegroups".equals(plugin.getConfig().getString("native.backend"))) { + throw new IllegalStateException("Expected the explicit Lobby DuneGroups profile"); + } + try { + worker = new DuneGroupsKeyWorker(plugin, api); + } catch (Exception failure) { + throw new ReflectiveOperationException("Lobby DuneGroups unavailable", failure); + } + } + + String status() { return worker.status(); } + void request() { worker.request(); } + @Override public void close() { worker.close(); } +} diff --git a/tools/install-plugin-fleet.py b/tools/install-plugin-fleet.py index 2862617a..062ee6d5 100644 --- a/tools/install-plugin-fleet.py +++ b/tools/install-plugin-fleet.py @@ -75,10 +75,10 @@ def verify_dunechest_fleet_target(sid, root, unit, incoming, installed): def plan(artifacts, inventory, expected_source): mode=inventory.get('mode') - if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus','lobby-food','lobby-account','arrakis-dunegroups'}: + if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus','lobby-food','lobby-account','arrakis-dunegroups','fleet-dunegroups'}: raise ValueError('An explicit supported rollout mode is required') compact_menus=mode=='compact-menus' - dunegroups=mode=='arrakis-dunegroups' + dunegroups=mode in {'arrakis-dunegroups','fleet-dunegroups'} lobby_food=mode=='lobby-food' lobby_account=mode=='lobby-account' jerboa=mode=='arrakis-jerboa' @@ -192,9 +192,12 @@ def plan(artifacts, inventory, expected_source): if raw_spice and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service' or wanted != {'jarvistranslator'} or selected_prerequisites): raise ValueError('Raw spice rollout may only replace JARVIS on Arrakis') - if dunegroups and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service' - or wanted != {'jarvistranslator','dunegroups'} or selected_prerequisites): - raise ValueError('DuneGroups canary requires the exact Arrakis service and approved plugin pair') + if dunegroups: + target = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid + approved = {'arrakis'} if mode == 'arrakis-dunegroups' else DUNECHEST_PLANETS | {'lobby'} + if (sid not in approved or root != target or unit != f'dune-{sid}.service' + or wanted != {'jarvistranslator','dunegroups'} or selected_prerequisites): + raise ValueError('DuneGroups requires an exact reviewed server and plugin pair') if lobby_food and (sid != 'lobby' or root != Path('/opt/dunerealms/lobby') or unit != 'dune-lobby.service' or wanted != {'jarvistranslator'} or selected_prerequisites): raise ValueError('Lobby food rollout may only replace JARVIS on Lobby') @@ -408,7 +411,7 @@ def plan(artifacts, inventory, expected_source): for path in sorted(plugins.glob('*.jar')) if path.name not in replaced] configurations = [] if dunegroups: - from plugin_dunegroups import CONFIG_BASELINE, VENDORS, enable_backend, transition, verify_artifact + from plugin_dunegroups import CONFIG_BASELINES, VENDORS, enable_backend, transition, verify_artifact incoming = {entry['name'].casefold(): entry for entry in chosen} upstream = artifacts / 'upstream' verify_artifact(upstream, expected_source) @@ -417,7 +420,7 @@ def plan(artifacts, inventory, expected_source): raise ValueError('DuneGroups canary requires retained JARVIS, WorldGuard and a first installation') if digest(upstream/'DuneGroups.jar') != incoming['dunegroups']['sha256']: raise ValueError('DuneGroups differs from the canonical build') - transition(installed, upstream/'jarvistranslator.jar', Path(incoming['jarvistranslator']['source'])) + transition(installed, upstream/'jarvistranslator.jar', Path(incoming['jarvistranslator']['source']), server=sid) for identity_key, (filename, sha) in VENDORS.items(): vendor = existing_paths.get(identity_key) if vendor is None or vendor.name != filename or digest(vendor) != sha: @@ -427,12 +430,14 @@ def plan(artifacts, inventory, expected_source): retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)} for path in sorted(plugins.glob('*.jar')) if path.name not in replaced] config = plugins/'JarvisTranslator/config.yml' - if config.is_symlink() or config.parent.is_symlink() or digest(config) != CONFIG_BASELINE: - raise ValueError('Unexpected private Arrakis JARVIS config revision') - updated = enable_backend(config.read_bytes().decode('utf-8')).encode('utf-8') + preimage = digest(config) if config.is_file() else None + if config.is_symlink() or config.parent.is_symlink() or preimage != CONFIG_BASELINES[sid]: + raise ValueError('Unexpected private JARVIS config revision') + config_text = config.read_bytes().decode('utf-8') if preimage else None + updated = enable_backend(config_text, sid).encode('utf-8') configurations.append({'path': 'JarvisTranslator/config.yml', 'transform': 'enable-dunegroups', 'sha256': hashlib.sha256(updated).hexdigest(), - 'previousSha256': CONFIG_BASELINE, 'previousMetadata': metadata(config)}) + 'previousSha256': preimage, 'previousMetadata': metadata(config) if preimage else None}) if uses_menu or crysknife or dunechest or jerboa: if menu is None: raise ValueError('DuneMenus requires a verified published built menu overlay') @@ -539,10 +544,15 @@ def apply(deployment, backup_root, control=systemctl): set_owner(target.parent, plugins.stat(), 0o750) if config.get('transform') == 'enable-dunegroups': from plugin_dunegroups import enable_backend - if digest(target) != config['previousSha256']: + preimage = digest(target) if target.is_file() else None + if preimage != config['previousSha256']: raise ValueError('Private JARVIS config changed after service stop') - target.write_bytes(enable_backend(target.read_bytes().decode('utf-8')).encode('utf-8')) - restore_metadata(target, config['previousMetadata']) + content = target.read_bytes().decode('utf-8') if preimage else None + target.write_bytes(enable_backend(content, server['id']).encode('utf-8')) + if config['previousMetadata'] is None: + set_owner(target, plugins.stat(), 0o640) + else: + restore_metadata(target, config['previousMetadata']) else: target.write_bytes(config['content'].encode()) set_owner(target, plugins.stat(), 0o640) diff --git a/tools/plugin_dunegroups.py b/tools/plugin_dunegroups.py index b7ef7487..b3d09926 100644 --- a/tools/plugin_dunegroups.py +++ b/tools/plugin_dunegroups.py @@ -9,7 +9,16 @@ from zipfile import ZipFile BASELINE = '883969e04ef6a3436e6ebef54112d16a1311555226b386ae75a8c1199556c7ca' -CONFIG_BASELINE = 'c90db002680004ac5784fdb3fdb38a6ccc0e6b9018a3bdcb6abfb109fc5d4a14' +PLANET_BASELINE = 'ebe8d2edc9f3300a039de1f76b81a2435895569704b2087e0625db699effe5d7' +LOBBY_BASELINE = 'e28907c52e675c5b1860f80adbda1601e1f389480b20a6939c992948fc46dcfa' +CONFIG_BASELINES = { + 'arrakis': 'c90db002680004ac5784fdb3fdb38a6ccc0e6b9018a3bdcb6abfb109fc5d4a14', + 'caladan': 'db4b6dbdfde6b3775cfe3d08bf6a56b336fbb29abb49057beed6b94b28ea4aba', + 'giedi_prime': 'b54e357ae5be48e7c01cf55269ced46ecd8ba3695615abf444aed17f4e94d54a', + 'kaitain': '87ce8fa35ddc54828570e50b9952c5914bb98961a52d3f2aaf3be94179199519', + 'sigma_draconis_iv': '3992734a42612c0426bb7f72a86736d76aac8c4990ed372f50f5271760101eb1', + 'lobby': None, +} VENDORS = { 'towny': ('Towny-0.103.2.0.jar', 'c8d7d59984eaf2606fce4192e860f7f969f3384e5a51b26b97225efbbe747c70'), 'medievalfactions': ('medieval-factions-11.1.0-all.jar', 'a3d5d448a15c3a864e90db659342782584bc3284b434ff926f21019d51e3350e'), @@ -32,15 +41,20 @@ def digest(path): return hashlib.sha256(path.read_bytes()).hexdigest() -def enable_backend(config): +def enable_backend(config, server='arrakis'): + if server == 'lobby' and config is None: + return 'native:\n server-key: lobby\n backend: dunegroups\n' + if config is None: + raise ValueError('Expected retained native config') headers = list(re.finditer(r'(?m)^native:[ \t]*(?:#[^\r\n]*)?(\r?\n)', config)) if len(headers) != 1: raise ValueError('Expected exactly one native config section') header = headers[0] nested = re.match(r'(?m)(?:[ \t]+[^\r\n]*\r?\n|[ \t]*\r?\n)*', config[header.end():])[0] - key = re.search(r'(?m)^([ ]+)server-key:[ \t]*arrakis[ \t]*(?:#[^\r\n]*)?\r?$', nested) + key = re.search(r'(?m)^([ ]+)server-key:[ \t]*' + re.escape(server.replace('_', '-')) + + r'[ \t]*(?:#[^\r\n]*)?\r?$', nested) if not key or re.search(r'(?m)^\s+backend\s*:', nested): - raise ValueError('Expected the Arrakis native config without a backend override') + raise ValueError('Expected native config without a backend override') return config[:header.end()] + key[1] + 'backend: dunegroups' + header[1] + config[header.end():] @@ -52,7 +66,7 @@ def names(archive): def verify_artifact(artifact, source): - pinned = {'jarvistranslator.jar', 'DuneGroups.jar', 'SOURCE_COMMIT', + pinned = {'jarvistranslator.jar', 'DuneGroups.jar', 'SOURCE_COMMIT', 'lobby-native-key-worker.class', 'plugin_dunegroups.py', 'install-plugin-fleet.py', 'write-plugin-manifest.py', 'plugin_menu_pack.py', 'plugin_backend_abi.py', 'plugin_fleet_rollback.py', 'plugin_pack_properties.py', 'plugin_pillager_abi.py'} @@ -66,29 +80,36 @@ def verify_artifact(artifact, source): raise ValueError('Unexpected DuneGroups source') -def transition(baseline, compiled, candidate, assemble=False): - if digest(baseline) != BASELINE: - raise ValueError('Expected exact Arrakis retained JARVIS') +def transition(baseline, compiled, candidate, assemble=False, server='arrakis'): + if server not in CONFIG_BASELINES: + raise ValueError('Unexpected server') + expected = BASELINE if server == 'arrakis' else LOBBY_BASELINE if server == 'lobby' else PLANET_BASELINE + if digest(baseline) != expected: + raise ValueError('Expected exact retained JARVIS') + replaced = {'plugin.yml', PREFIX+'NativeKeyWorker.class'} if server == 'lobby' else REPLACED + added = ADDED - {PREFIX+'FactionClanDirectory.class'} if server == 'lobby' else ADDED with ZipFile(baseline) as old, ZipFile(compiled) as built: kept = names(old) - if not REPLACED <= kept or kept & ADDED or not REPLACED | ADDED <= names(built): + if not replaced <= kept or kept & added or not (replaced | added) <= names(built): raise ValueError('Unexpected JARVIS transition inputs') - updates = {name: built.read(name) for name in REPLACED | ADDED} - old_descriptor = old.read('plugin.yml').replace(b'\r\n', b'\n') - new_descriptor = updates['plugin.yml'].replace(b'\r\n', b'\n') - if new_descriptor.replace(b', DuneGroups]', b']') != old_descriptor or b', DuneGroups]' not in new_descriptor: - raise ValueError('Expected only the DuneGroups soft dependency in the descriptor') + updates = {name: built.read(name) for name in replaced | added} + descriptor, count = re.subn(rb'(?m)^(softdepend: \[[^\r\n]+)\]', rb'\1, DuneGroups]', old.read('plugin.yml')) + if count != 1 or old.read('plugin.yml').count(b'DuneGroups'): + raise ValueError('Unexpected retained JARVIS soft dependencies') + updates['plugin.yml'] = descriptor + if server == 'lobby': + updates[PREFIX+'NativeKeyWorker.class'] = compiled.with_name('lobby-native-key-worker.class').read_bytes() if assemble: with ZipFile(candidate, 'x') as out: for entry in old.infolist(): name = entry.filename out.writestr(copy(entry), updates[name] if name in updates else old.read(entry)) - for name in sorted(ADDED): + for name in sorted(added): out.writestr(copy(built.getinfo(name)), updates[name]) with ZipFile(candidate) as incoming: - if names(incoming) != kept | ADDED: + if names(incoming) != kept | added: raise ValueError('Unexpected DuneGroups candidate entries') - for name in kept | ADDED: + for name in kept | added: expected = updates[name] if name in updates else old.read(name) if incoming.read(name) != expected: raise ValueError(f'Unreviewed JARVIS change: {name}') @@ -100,6 +121,7 @@ if __name__ == '__main__': parser.add_argument('artifact', type=Path) parser.add_argument('source') parser.add_argument('candidate', type=Path) + parser.add_argument('--server', choices=sorted(CONFIG_BASELINES), default='arrakis') args = parser.parse_args() verify_artifact(args.artifact, args.source) - transition(args.baseline, args.artifact / 'jarvistranslator.jar', args.candidate, assemble=True) + transition(args.baseline, args.artifact / 'jarvistranslator.jar', args.candidate, assemble=True, server=args.server) diff --git a/tools/plugin_fleet_rollback.py b/tools/plugin_fleet_rollback.py index 4e52a532..982cf038 100644 --- a/tools/plugin_fleet_rollback.py +++ b/tools/plugin_fleet_rollback.py @@ -54,8 +54,11 @@ def rollback_receipt(receipt_path, expected_source, apply=False, run=control, le configs=server.get('configurations',[]) for entry in configs: relative=entry['path'] + sid = server['id'] + reviewed = {'arrakis', 'caladan', 'giedi_prime', 'kaitain', 'sigma_draconis_iv', 'lobby'} + target = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid private_jarvis = (relative == 'JarvisTranslator/config.yml' and entry.get('transform') == 'enable-dunegroups' - and server['id'] == 'arrakis' and root == Path('/opt/dunerealms/servers/arrakis')) + and sid in reviewed and root == target and unit == f'dune-{sid}.service') if relative not in ('MCGUI/config.yml','DunerealmsGUI/menu-pack.yml') and not private_jarvis: raise ValueError('Unsafe rollback configuration path') current=plugins/relative diff --git a/tools/test_plugin_dunegroups.py b/tools/test_plugin_dunegroups.py index e10c505e..37b3d7af 100644 --- a/tools/test_plugin_dunegroups.py +++ b/tools/test_plugin_dunegroups.py @@ -15,6 +15,13 @@ class DuneGroupsConfigurationTest(unittest.TestCase): with self.subTest(source=source), self.assertRaises(ValueError): enable_backend(source) + def test_scoped_planet_and_absent_lobby_config(self): + source = 'native:\n server-key: giedi-prime\n' + self.assertIn('backend: dunegroups', enable_backend(source, 'giedi_prime')) + self.assertEqual(enable_backend(None, 'lobby'), 'native:\n server-key: lobby\n backend: dunegroups\n') + with self.assertRaises(ValueError): + enable_backend(None, 'caladan') + if __name__ == '__main__': unittest.main()