Files
WoW-Hybrid-gateway/tests/warrior_cooldown_private_bits_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

126 lines
6.7 KiB
Python

import copy
from pathlib import Path
import sys
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import warrior_cooldown_private_bits as private
from warrior_cooldown_modifier_test import src, native
def definitions(ids):
return {'Spell': [dict(ID=i) for i in ids],
'SpellName': [dict(ID=i, Name_lang='Fixture'+str(i)) for i in ids],
'SpellMisc': [dict(ID=i+100, SpellID=i, DifficultyID=0) for i in ids],
'SpellEffect': [dict(ID=i+200, SpellID=i, DifficultyID=0, EffectIndex=0, Effect=6) for i in ids]}
def sources(ids):
return {i: dict(entry=i, name='Fixture'+str(i), effect1=6, effect2=0, effect3=0) for i in ids}
class PrivateBitsTests(unittest.TestCase):
def setUp(self):
self.source = [src(10, 1), src(999, 0, 0)]
self.target = [native(10, 1), native(999, 1)]
self.tables = definitions([10])
self.closure = private.definition_closure(sources([10]), self.tables, [], [10])
def test_unused_bit_exact_scope_preserves_existing_native_rows(self):
before = copy.deepcopy(self.target)
result = private.allocate(self.source, self.target, self.closure, [0])
self.assertEqual(self.target, before)
self.assertEqual(result['allocations'], [dict(source_bit=0, native_bit=127, spell_ids=[10], globally_unused_in_baseline=True)])
changed = result['native_inventory']
self.assertEqual(changed[0]['SpellClassMask'], [1, 0, 0, -2147483648])
self.assertEqual(changed[1], before[1])
self.assertEqual({k:v for k,v in changed[0].items()if k!='SpellClassMask'},
{k:v for k,v in before[0].items()if k!='SpellClassMask'})
self.assertEqual(result['mapping_profile']['admitted'][0]['native_bit'], 127)
self.assertFalse(result['installable_package'])
def test_current_used_bit_never_reused(self):
target = copy.deepcopy(self.target)
target[1]['SpellClassMask'][3] = -2147483648
result = private.allocate(self.source, target, self.closure, [0])
self.assertEqual(result['allocations'][0]['native_bit'], 126)
self.assertEqual(result['native_inventory'][1], target[1])
def test_missing_class_identity_does_not_author_new_definitions(self):
source = self.source + [src(11, 1)]
result = private.allocate(source, self.target, self.closure, [0])
self.assertFalse(result['allocations'])
self.assertEqual(result['held_allocations'][0]['reason'], 'missing-native-class-identities')
self.assertEqual(result['native_inventory'], self.target)
def test_parent_or_name_or_effect_closure_holds(self):
for mutation in ['Spell', 'SpellName', 'SpellMisc', 'SpellEffect', 'name', 'duplicate-default']:
tables = copy.deepcopy(self.tables)
if mutation in private.TABLES:
tables[mutation] = []
elif mutation == 'name':
tables['SpellName'][0]['Name_lang'] = 'Other identity'
else:
tables['SpellMisc'].append(dict(ID=500, SpellID=10, DifficultyID=0))
proof = private.definition_closure(sources([10]), tables, [], [10])
self.assertFalse(proof[10]['complete'])
result = private.allocate(self.source, self.target, proof, [0])
self.assertFalse(result['allocations'])
self.assertEqual(result['held_allocations'][0]['reason'], 'incomplete-parent-definition-closure')
def test_malformed_default_definition_types_and_inactive_slot(self):
for table, patch in [('SpellMisc', dict(DifficultyID=False)),
('SpellEffect', dict(DifficultyID=True)),
('SpellEffect', dict(EffectIndex=False))]:
tables = copy.deepcopy(self.tables);tables[table][0].update(patch)
with self.assertRaises(ValueError):
private.definition_closure(sources([10]), tables, [], [10])
tables = copy.deepcopy(self.tables);tables['SpellEffect'][0]['Effect'] = 0
proof = private.definition_closure(sources([10]), tables, [], [10])
self.assertFalse(proof[10]['complete'])
self.assertIn('inactive-native-effect-slot', proof[10]['held_reasons'])
def test_source_enabled_slot_missing_holds(self):
rows = sources([10]);rows[10]['effect3'] = 6
proof = private.definition_closure(rows, self.tables, [], [10])
self.assertIn('missing-source-enabled-effect-slots', proof[10]['held_reasons'])
def test_duplicate_invalid_overlay_and_tombstone(self):
row = dict(table_name='SpellName', id=10, record=dict(ID=10, Name_lang='Fixture10'))
for overlays in [[row, row], [dict(row, record_status='invalid')],
[dict(row, record=dict(ID=True, Name_lang='Fixture10'))]]:
with self.assertRaises(ValueError):
private.definition_closure(sources([10]), self.tables, overlays, [10])
proof = private.definition_closure(sources([10]), self.tables,
[dict(table_name='SpellName', id=10, record_status='removed')], [10])
self.assertFalse(proof[10]['complete'])
def test_exhaustion_holds_without_mask_changes(self):
target = [native(10, 1), native(999, (1 << 128)-1)]
result = private.allocate(self.source, target, self.closure, [0])
self.assertFalse(result['allocations'])
self.assertEqual(result['held_allocations'][0]['reason'], 'no-unused-native-class-bit')
self.assertEqual(result['native_inventory'], target)
def test_existing_exact_route_needs_no_new_bit(self):
target = [native(10, 1), native(999, 2)]
result = private.allocate(self.source, target, self.closure, [0])
self.assertFalse(result['allocations'])
self.assertEqual(result['native_inventory'], target)
self.assertEqual(result['mapping_profile']['admitted'][0]['native_bit'], 0)
def test_stale_baseline_or_proposal_mutation_rejects(self):
result = private.allocate(self.source, self.target, self.closure, [0])
tampered = copy.deepcopy(result);tampered['native_inventory'][1]['SpellClassMask'][0] = 0
for proposal, target in [(tampered, self.target), (result, [native(10, 1), native(999, (1 << 127)|1)])]:
with self.assertRaises(ValueError):
private.validate_allocation(proposal, self.source, target, self.closure, [0])
def test_false_or_wrong_closure_identity_holds(self):
for patch in [dict(complete=1), dict(spell_id=True), dict(spell_id=11)]:
closure = copy.deepcopy(self.closure);closure[10].update(patch)
self.assertFalse(private.allocate(self.source, self.target, closure, [0])['allocations'])
if __name__ == '__main__':
unittest.main()