diff --git a/.forgejo/workflows/dunegroups.yml b/.forgejo/workflows/dunegroups.yml index 179a90e9..6b076573 100644 --- a/.forgejo/workflows/dunegroups.yml +++ b/.forgejo/workflows/dunegroups.yml @@ -32,8 +32,9 @@ jobs: gradle --no-daemon -p DuneGroups test jar mkdir dunegroups-artifacts cp JarvisConnector/build/libs/jarvistranslator.jar DuneGroups/build/libs/DuneGroups.jar dunegroups-artifacts/ + 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 SOURCE_COMMIT > SHA256SUMS) + (cd dunegroups-artifacts && sha256sum -- *.jar *.py SOURCE_COMMIT > SHA256SUMS) - uses: actions/upload-artifact@v3 with: name: DuneRealms-DuneGroups-Replacement diff --git a/.forgejo/workflows/plugins.yml b/.forgejo/workflows/plugins.yml index a99015eb..5c17c067 100644 --- a/.forgejo/workflows/plugins.yml +++ b/.forgejo/workflows/plugins.yml @@ -28,7 +28,7 @@ jobs: shell: bash run: | set -euo pipefail - modules=(DuneEss DuneLobby DuneLobbyAccount DuneNPC DuneRealms-minecraft-only DuneRealmsGUI DuneTerrain JarvisConnector DuneMenus) + modules=(DuneEss DuneLobby DuneLobbyAccount DuneNPC DuneRealms-minecraft-only DuneRealmsGUI DuneTerrain JarvisConnector DuneMenus DuneGroups) mkdir -p plugin-artifacts for module in "${modules[@]}"; do gradle --no-daemon -p "$module" test jar @@ -47,13 +47,20 @@ jobs: (cd plugin-artifacts && sha256sum -- *.jar SOURCE_COMMIT > SHA256SUMS) - name: Validate rollout contract and build stacked menu overlay shell: bash + env: + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -euo pipefail python3 tools/test_plugin_ci_policy.py -v pillager_input="$(mktemp -d)" python3 tools/plugin_navigator_transition.py --stage-pillager-baseline "$pillager_input/baseline" DUNE_PILLAGER_BASELINE_DIR="$pillager_input/baseline" python3 tools/test_plugin_pillager_profile.py -v - python3 tools/plugin_navigator_transition.py + # Navigator predates the selectable DuneGroups backend. Validate its + # exact historical connector against the original unchanged contract. + git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git 5d727d7f59e6af26fba07a3878fd79035a5923ce + git worktree add --detach "$pillager_input/navigator" FETCH_HEAD + gradle --no-daemon -p "$pillager_input/navigator/JarvisConnector" jar + python3 tools/plugin_navigator_transition.py --historical-jarvis "$pillager_input/navigator/JarvisConnector/build/libs/jarvistranslator.jar" python3 tools/test_plugin_pillager_art.py -v python3 tools/test_plugin_fleet_install.py -v python3 tools/test_plugin_menu_pack.py -v diff --git a/tools/plugin_dunegroups.py b/tools/plugin_dunegroups.py new file mode 100644 index 00000000..3a39664f --- /dev/null +++ b/tools/plugin_dunegroups.py @@ -0,0 +1,87 @@ +"""Verify or assemble the reviewed Arrakis-only JARVIS transition.""" + +import argparse +from copy import copy +import hashlib +from pathlib import Path +from zipfile import ZipFile + + +BASELINE = '883969e04ef6a3436e6ebef54112d16a1311555226b386ae75a8c1199556c7ca' +PREFIX = 'com/dunerealms/jarvis/' +REPLACED = { + PREFIX + name + '.class' for name in + ('ImperialRaid', 'ImperialRaid$Order', 'ImperialRaidWorker', 'JarvisTranslator', 'NativeKeyWorker') +} | {'plugin.yml'} +ADDED = { + PREFIX + name + '.class' for name in + ('CentralClanDirectory', 'ClanDirectory', 'DuneGroupsAcknowledgements', + 'DuneGroupsAcknowledgements$Writer', 'DuneGroupsKeyWorker', 'FactionClanDirectory', + 'NativeKeys', 'OrganisationDirectory', 'OrganisationDirectory$Group', + 'OrganisationDirectory$Home', 'OrganisationDirectory$War') +} + + +def digest(path): + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def names(archive): + records = archive.namelist() + if len(set(records)) != len(records): + raise ValueError('Duplicate archive entry') + return set(records) + + +def verify_artifact(artifact, source): + pinned = {'jarvistranslator.jar', 'DuneGroups.jar', 'SOURCE_COMMIT', + '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'} + lines = (artifact / 'SHA256SUMS').read_text().splitlines() + sums = dict(line.split(' ', 1)[::-1] for line in lines) + if len(lines) != len(sums) or sums.keys() != pinned or any( + digest(artifact / name) != checksum for name, checksum in sums.items() + ): + raise ValueError('Unexpected DuneGroups artifact manifest') + if (artifact / 'SOURCE_COMMIT').read_text().strip() != source: + raise ValueError('Unexpected DuneGroups source') + + +def transition(baseline, compiled, candidate, assemble=False): + if digest(baseline) != BASELINE: + raise ValueError('Expected exact Arrakis retained JARVIS') + 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): + 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') + 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): + out.writestr(copy(built.getinfo(name)), updates[name]) + with ZipFile(candidate) as incoming: + if names(incoming) != kept | ADDED: + raise ValueError('Unexpected DuneGroups candidate entries') + 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}') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('baseline', type=Path) + parser.add_argument('artifact', type=Path) + parser.add_argument('source') + parser.add_argument('candidate', type=Path) + args = parser.parse_args() + verify_artifact(args.artifact, args.source) + transition(args.baseline, args.artifact / 'jarvistranslator.jar', args.candidate, assemble=True) diff --git a/tools/plugin_navigator_transition.py b/tools/plugin_navigator_transition.py index e0327067..b0f6bb6f 100644 --- a/tools/plugin_navigator_transition.py +++ b/tools/plugin_navigator_transition.py @@ -102,12 +102,15 @@ def main(): parser.add_argument('--contract', type=Path, default=Path('tools/navigator-transition.json')) parser.add_argument('--abi', type=Path, default=Path('JarvisConnector/src/test/resources/retained-jarvis-public-abi.json')) parser.add_argument('--stage-pillager-baseline', type=Path) + parser.add_argument('--historical-jarvis', type=Path) args = parser.parse_args() fixture = json.loads(args.contract.read_text()) if args.stage_pillager_baseline is not None: stage_pillager_baseline(args.stage_pillager_baseline, fixture) return for name, path in JARS.items(): + if name == 'JarvisTranslator' and args.historical_jarvis is not None: + path = args.historical_jarvis guard = fixture['modules'][name] report = verify_jarvis(path, guard, json.loads(args.abi.read_text())) if name == 'JarvisTranslator' else verify_module(path, guard) print(name, json.dumps(report, sort_keys=True)) diff --git a/tools/test_plugin_ci_policy.py b/tools/test_plugin_ci_policy.py index 0ddd1d77..405be7d7 100644 --- a/tools/test_plugin_ci_policy.py +++ b/tools/test_plugin_ci_policy.py @@ -30,14 +30,14 @@ def validate(text): modules = re.search(r'^\s*modules=\(([^)]+)\)', text, re.M) if not modules or set(modules[1].split()) != { 'DuneEss', 'DuneLobby', 'DuneLobbyAccount', 'DuneNPC', 'DuneRealms-minecraft-only', - 'DuneRealmsGUI', 'DuneTerrain', 'JarvisConnector', 'DuneMenus', + 'DuneRealmsGUI', 'DuneTerrain', 'JarvisConnector', 'DuneMenus', 'DuneGroups', }: - raise ValueError('All nine source modules must retain tests and compilation') + raise ValueError('All ten source modules must retain tests and compilation') for script in CHECKS: if 'python3 tools/' + script + ' -v' not in text: raise ValueError('Missing release regression check: ' + script) for command in ('python3 tools/plugin_navigator_transition.py --stage-pillager-baseline', - '\n python3 tools/plugin_navigator_transition.py\n'): + 'python3 tools/plugin_navigator_transition.py --historical-jarvis'): if command not in text: raise ValueError('Missing Navigator transition check: ' + command.strip()) if re.search(r'^\s*(continue-on-error|if):', text, re.M): @@ -74,13 +74,13 @@ class PluginCIPolicyTests(unittest.TestCase): validate(self.text.replace(' runs-on:', ' continue-on-error: true\n runs-on:', 1)) def test_missing_module_and_unpinned_checkout_are_rejected(self): - for old, new in ((' DuneMenus)', ')'), ('git checkout --detach FETCH_HEAD', 'git checkout main')): + for old, new in ((' DuneGroups)', ')'), ('git checkout --detach FETCH_HEAD', 'git checkout main')): with self.subTest(old=old), self.assertRaises(ValueError): validate(self.text.replace(old, new)) def test_legacy_baseline_and_navigator_candidate_both_remain_checked(self): for command in ('python3 tools/plugin_navigator_transition.py --stage-pillager-baseline', - '\n python3 tools/plugin_navigator_transition.py\n'): + 'python3 tools/plugin_navigator_transition.py --historical-jarvis'): with self.subTest(command=command), self.assertRaises(ValueError): validate(self.text.replace(command, ''))