883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
106 lines
5.4 KiB
Python
106 lines
5.4 KiB
Python
import copy
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
from types import SimpleNamespace
|
|
import unittest
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
import prepare_warrior_cooldown_modifiers as prep
|
|
|
|
|
|
class PreparationTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory(prefix='flat11-test-', dir=prep.ROOT / 'runtime')
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.root = Path(self.tmp.name)
|
|
self.rows = [dict(entry=10, spellFamilyName=4, spellFamilyFlags=1),
|
|
dict(entry=20, spellFamilyName=4, spellFamilyFlags=0,
|
|
effect1=6, effectApplyAuraName1=107, effectMiscValue1=11)]
|
|
self.audit = {'modifier_rows': [dict(spell=20, talent='Fixture Talent', source_aura=107, operation=11,
|
|
effect_index=0, source_affect_mask=1, source_affect_bits=[0])]}
|
|
self.package = {'rows': []}
|
|
self.native = [dict(ID=30, SpellID=10, ModalNextSpell=0, SpellClassSet=4, SpellClassMask=[1, 0, 0, 0])]
|
|
|
|
def write(self, path, value):
|
|
path.write_text(json.dumps(value, sort_keys=True, separators=(',', ':')) + '\n')
|
|
return path
|
|
|
|
def args(self):
|
|
chunk = self.write(self.root / 'spells.json', self.rows)
|
|
self.manifest = {'schema_version': 1, 'spell_count': 2, 'total_chunk_bytes': chunk.stat().st_size,
|
|
'first_id': 10, 'last_id': 20, 'limits': [],
|
|
'chunks': [dict(path='spells.json', sha256=prep.sha(chunk), bytes=chunk.stat().st_size,
|
|
count=2, first_id=10, last_id=20)]}
|
|
manifest = self.write(self.root / 'manifest.json', self.manifest)
|
|
native = self.write(self.root / 'native.json', self.native)
|
|
package = self.write(self.root / 'package.json', self.package)
|
|
audit = self.write(self.root / 'audit.json', self.audit)
|
|
return SimpleNamespace(source_manifest=manifest, source_manifest_sha256=prep.sha(manifest),
|
|
native=native, native_sha256=prep.sha(native), package=package,
|
|
package_sha256=prep.sha(package), audit=audit, audit_sha256=prep.sha(audit),
|
|
expected_package_rows=0, output=self.root / 'out')
|
|
|
|
def test_complete_inputs_derive_real_candidate_without_source_rewrite(self):
|
|
args = self.args();chunk = self.root / 'spells.json';before = chunk.read_bytes()
|
|
report = prep.prepare(args)
|
|
self.assertEqual((report['admitted_bits'], report['complete_audited_effects']), (1, 1))
|
|
self.assertEqual(chunk.read_bytes(), before)
|
|
self.assertFalse(report['native_runtime_integrated'])
|
|
self.assertEqual(json.loads((args.output / 'mapping-profile.json').read_text())['admitted'][0]['native_bit'], 0)
|
|
|
|
def test_input_digest_and_chunk_mutation_fail_before_outputs(self):
|
|
for mode in ['manifest', 'native', 'package', 'audit', 'chunk']:
|
|
args = self.args()
|
|
path = self.root / ('spells.json' if mode == 'chunk' else mode + '.json')
|
|
path.write_bytes(path.read_bytes() + b' ')
|
|
with self.subTest(mode=mode), self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
self.assertFalse(args.output.exists())
|
|
|
|
def test_chunk_path_escape_rejects(self):
|
|
args = self.args();self.manifest['chunks'][0]['path'] = '../outside.json'
|
|
self.write(args.source_manifest, self.manifest);args.source_manifest_sha256 = prep.sha(args.source_manifest)
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
|
|
def test_incomplete_source_count_rejects(self):
|
|
args = self.args();self.manifest['spell_count'] = 3
|
|
self.write(args.source_manifest, self.manifest);args.source_manifest_sha256 = prep.sha(args.source_manifest)
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
|
|
def test_audit_mask_slot_or_effect_mutation_rejects(self):
|
|
for patch in [dict(effect_index=True), dict(source_affect_bits=[1]), dict(source_affect_mask=0)]:
|
|
args = self.args();audit = copy.deepcopy(self.audit);audit['modifier_rows'][0].update(patch)
|
|
self.write(args.audit, audit);args.audit_sha256 = prep.sha(args.audit)
|
|
with self.subTest(patch=patch), self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
self.rows[1]['effectApplyAuraName1'] = 108
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(self.args())
|
|
|
|
def test_native_duplicate_or_invalid_overlay_rejects(self):
|
|
self.native += self.native
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(self.args())
|
|
self.native = self.native[:1]
|
|
self.package['rows'] = [dict(table_name='SpellClassOptions', id=30, record_status='invalid')]
|
|
args = self.args();args.expected_package_rows = 1
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
|
|
def test_existing_output_is_preserved_and_scope_is_restricted(self):
|
|
args = self.args();args.output.mkdir();sentinel = args.output / 'preserve';sentinel.write_text('unchanged')
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
self.assertEqual(sentinel.read_text(), 'unchanged')
|
|
args.output = prep.ROOT / 'ops' / 'not-an-output'
|
|
with self.assertRaises(ValueError):
|
|
prep.prepare(args)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|