Files
WoW-Hybrid-gateway/tests/map_conversion_current_source_selection_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

65 lines
3.6 KiB
Python

"""The optional current selection binds saved map roles without reconversion."""
import hashlib
import json
from pathlib import Path
import sys
import tempfile
import unittest
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'ops'))
import map_conversion_batch as batch
def pin(path):
path = Path(path).resolve(); raw = path.read_bytes()
return {'path': str(path), 'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest()}
class CurrentSavedMapSource(unittest.TestCase):
def test_current_selection_and_conditional_holds(self):
base = ROOT / 'runtime/continuation-20261029'
paths = {'selection': base/'octo-update-freshness/current-openworld-142-selection.private.json',
'inventory': base/'octo-update-freshness/current-inventory.private.json',
'archive_order': ROOT/'runtime/continuation-20261028/current-source20-requalification/input-manifest.private.json'}
refs = {k: pin(v) for k, v in paths.items()}
req = json.loads((base/'converter-worldmap-reuse/source78-private-batch/input-manifest.json').read_text())
job = req['jobs'][0]; name = job['source_reference']; job['options']['roles'] = ['root']
req['jobs'] = [job]; req['payloads'] = {name: req['payloads'][name]}
saved = req['contracts']['saved']['reuse_saved']
saved['candidates'] = {name+':root': saved['candidates'][name+':root']}
saved['current_source_receipts'] = refs
with tempfile.TemporaryDirectory(prefix='map-current-source-', dir=base/'worldmap-flightmap-reuse') as tmp:
with mock.patch.object(batch, 'invoke', side_effect=AssertionError('saved source must not reconvert')):
result = batch.run_batch(req, action='convert', output=Path(tmp)/'out', base_directory=ROOT)
row = result['rows'][0]
self.assertEqual(row['status'], 'REUSED')
self.assertEqual(row['current_source_qualification']['member'], name.lower())
self.assertFalse(row['current_source_qualification']['launcher_hook_equivalence_verified'])
self.assertFalse(row['runtime_verified'])
selection = json.loads(paths['selection'].read_text())
wdt = selection['records']['world/maps/azeroth/azeroth.wdt']
self.assertEqual(batch.check_current_source_selection(selection, 'wdt-original529-links',
{'map_id':0}, wdt['prior_sha256'])['family'], 'wdt')
with self.assertRaises(ValueError):
batch.check_current_source_selection(selection, 'source-adt-split', job, '0'*64, 'source-only78')
with self.assertRaises(ValueError):
batch.check_current_source_selection(selection, 'source-adt-split', job,
req['payloads'][name]['sha256'], 'source-only62')
with self.assertRaises(ValueError):
batch.load_current_source_selection({'current_source_receipts': {'selection': refs['selection']}},
batch.Inputs(ROOT))
original_token = batch.token
def changed_archive(path):
identity = original_token(path)
return (*identity[:3], identity[3] + 1) if path.name.casefold() == 'patch-o.mpq' else identity
with mock.patch.object(batch, 'token', side_effect=changed_archive):
with self.assertRaisesRegex(ValueError, 'archive lifetime changed'):
batch.load_current_source_selection({'current_source_receipts': refs}, batch.Inputs(ROOT))
self.assertIsNone(batch.load_current_source_selection({}, batch.Inputs(ROOT)))
if __name__ == '__main__':
unittest.main()