Preserve retained planet and Lobby JARVIS variants in DuneGroups rollout
Some checks failed
DuneGroups Replacement Build / dunegroups (push) Successful in 55s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 9s
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-12-02 13:37:57 +01:00
commit 944fa69b69
7 changed files with 116 additions and 39 deletions

View file

@ -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

View file

@ -21,3 +21,11 @@ tasks.processResources {
}
sourceSets.main { java.srcDir("../citizens-common/src/main/java") }
tasks.register<JavaCompile>("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)) })
}

View file

@ -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(); }
}

View file

@ -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','arrakis-dunechat'}:
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','arrakis-dunechat'}:
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'}
dunechat=mode=='arrakis-dunechat'
lobby_food=mode=='lobby-food'
lobby_account=mode=='lobby-account'
@ -199,12 +199,15 @@ 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 dunechat and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service'
or wanted != {'dunechat'} or selected_prerequisites):
raise ValueError('DuneChat canary requires the exact Arrakis service and standalone plugin')
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')
@ -434,7 +437,7 @@ def plan(artifacts, inventory, expected_source):
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
for path in sorted(plugins.glob('*.jar'))]
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)
@ -443,7 +446,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:
@ -453,12 +456,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')
@ -563,15 +568,23 @@ def apply(deployment, backup_root, control=systemctl):
target.parent.mkdir(parents=True, exist_ok=True)
if new_parent:
set_owner(target.parent, plugins.stat(), 0o750)
if config.get('transform') in {'enable-dunegroups', 'enable-modern-discord'}:
if config['transform'] == 'enable-dunegroups':
from plugin_dunegroups import enable_backend as update
else:
from plugin_dunechat import enable_modern_discord as update
if config.get('transform') == 'enable-modern-discord':
from plugin_dunechat import enable_modern_discord
if digest(target) != config['previousSha256']:
raise ValueError('Private configuration changed after service stop')
target.write_bytes(update(target.read_bytes().decode('utf-8')).encode('utf-8'))
target.write_bytes(enable_modern_discord(target.read_bytes().decode('utf-8')).encode('utf-8'))
restore_metadata(target, config['previousMetadata'])
elif config.get('transform') == 'enable-dunegroups':
from plugin_dunegroups import enable_backend
preimage = digest(target) if target.is_file() else None
if preimage != config['previousSha256']:
raise ValueError('Private JARVIS config changed after service stop')
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)

View file

@ -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)

View file

@ -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')
private_discord = (relative == 'DiscordSRV/config.yml' and entry.get('transform') == 'enable-modern-discord'
and server['id'] == 'arrakis' and root == Path('/opt/dunerealms/servers/arrakis'))
if relative not in ('MCGUI/config.yml','DunerealmsGUI/menu-pack.yml') and not (private_jarvis or private_discord):

View file

@ -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()