883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
110 lines
8.1 KiB
Python
110 lines
8.1 KiB
Python
#!/usr/bin/env python3
|
|
import copy,hashlib,json,re,sys,tempfile,unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import source_race_class_creation as m
|
|
import spell_passive_compat as typed
|
|
|
|
class SourceRaceClassCreationTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):cls.fixture=json.loads((Path(__file__).parent/'fixtures/source-race-class-creation.json').read_text())
|
|
def case(self):
|
|
f=copy.deepcopy(self.fixture);native=f['native_rows'];native=native.get('rows',[]) if isinstance(native,dict) else native
|
|
return [f['source_pairs'],copy.deepcopy(f['source_pairs']),f['start_tables'],native]
|
|
def assessment(self):return m.derive(*self.case())
|
|
def rehash(self,content):content['sha256']=hashlib.sha256('\n'.join('\t'.join(row) for row in content['rows']).encode()).hexdigest()
|
|
def test_all_fiftynine_exact_source_pairs_without_cross_product(self):
|
|
r=self.assessment();self.assertEqual(len(r['source_pairs']),59)
|
|
self.assertIn((6,5),r['source_pairs']);self.assertNotIn((6,2),r['source_pairs'])
|
|
self.assertEqual(len(r['proposed_original_ui_pairs']),48);self.assertEqual(len(r['custom_race_menu_held_pairs']),11)
|
|
self.assertEqual(sorted(r['proposed_original_ui_pairs']+r['custom_race_menu_held_pairs']),r['source_pairs'])
|
|
self.assertFalse(r['native_creation_verified']);self.assertFalse(r['source_character_created'])
|
|
def test_all_missing_native_pairs_additive_and_preserve_native_only_rows(self):
|
|
a=self.case();r=m.derive(*a);rows=m.additive_char_base_rows(r,a[3],max(x['ID'] for x in a[3]))
|
|
self.assertEqual(len(rows),16);self.assertTrue(any(x['RaceID']==6 and x['ClassID']==5 for x in rows))
|
|
old=copy.deepcopy(a[3]);combined=old+rows
|
|
self.assertEqual(a[3],old);self.assertEqual(len({(x['RaceID'],x['ClassID']) for x in combined}),72)
|
|
self.assertEqual(len(r['native_only_pairs_retained']),13)
|
|
self.assertTrue(set(r['source_pairs']).issubset({(x['RaceID'],x['ClassID']) for x in combined}))
|
|
def test_tauren_priest_complete_start_relationships(self):
|
|
r=self.assessment()['starting_relationship_counts']['6:5']
|
|
self.assertEqual(r,{'playercreateinfo':1,'playercreateinfo_item':7,'playercreateinfo_spell':35,'playercreateinfo_action':6})
|
|
def test_source_server_mismatch_and_duplicate_pairs_rejected(self):
|
|
a=self.case();a[1].pop()
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
a=self.case();a[0].append(a[0][0])
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_modern_or_boolean_identity_not_silently_admitted(self):
|
|
for pair in ([6,6],[6,10],[True,1],[12,5]):
|
|
a=self.case();a[0].append(pair);a[1].append(pair)
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_missing_two_read_proof_and_changed_digest_rejected(self):
|
|
for key,value in (('matching_reads',1),('matching_reads',True),('sha256','0'*64)):
|
|
a=self.case();a[2]['playercreateinfo_spell'][key]=value
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_missing_source_start_position_or_spells_rejected(self):
|
|
for table in ('playercreateinfo','playercreateinfo_spell'):
|
|
a=self.case();block=a[2][table];block['rows']=[r for r in block['rows'] if r[:2]!=['6','5']];self.rehash(block)
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_nonfinite_start_position_and_unproven_pair_rejected(self):
|
|
a=self.case();b=a[2]['playercreateinfo'];b['rows'][0][4]='NaN';self.rehash(b)
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
a=self.case();b=a[2]['playercreateinfo_item'];b['rows'][0][:2]=['6','2'];self.rehash(b)
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_native_unknown_field_crossfaction_and_duplicate_rejected(self):
|
|
for key,value in (('OtherFactionRaceID',1),('Unknown',0)):
|
|
a=self.case();a[3][0][key]=value
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
a=self.case();a[3].append(copy.deepcopy(a[3][0]))
|
|
with self.assertRaises(ValueError):m.derive(*a)
|
|
def test_native_namespace_and_missing_set_tampering_rejected(self):
|
|
a=self.case();r=m.derive(*a)
|
|
with self.assertRaises(ValueError):m.additive_char_base_rows(r,a[3],1)
|
|
r['native_missing_pairs'].pop()
|
|
with self.assertRaises(ValueError):m.additive_char_base_rows(r,a[3],max(x['ID'] for x in a[3]))
|
|
def test_header_changes_exactly_one_declaration_and_includes_all59(self):
|
|
header=self.fixture['original_profile'];out=m.profile_candidate(header,self.assessment())
|
|
pattern=r'inline constexpr std::array<std::array<uint8_t,2>,\d+> TurtleNativeCreationRaceClasses=\{\{.*?\}\};'
|
|
self.assertEqual(re.sub(pattern,'REPLACED',header),re.sub(pattern,'REPLACED',out))
|
|
declaration=re.search(pattern,out)[0]
|
|
self.assertIn(',59>',declaration);self.assertIn('{{6,5}}',declaration)
|
|
self.assertNotIn('{{6,2}}',declaration)
|
|
def test_staged_source_identity_all59_mask_and_custom_factions(self):
|
|
import turtle_login_profile as original
|
|
header=self.fixture['original_profile'];assessment=self.assessment()
|
|
out=m.profile_candidate(header,assessment,source_identity=True)
|
|
pair_pattern=r'inline constexpr std::array<std::array<uint8_t,2>,\d+> TurtleNativeCreationRaceClasses=\{\{.*?\}\};'
|
|
alias_pattern=r'inline constexpr std::array<std::array<uint8_t,3>,2> TurtleRosterVisualRaceAliases=\{\{.*?\}\};'
|
|
mask_pattern=r'inline constexpr uint32_t TurtleNativeCreationClassDisableMask=0x[0-9A-Fa-f]{8};'
|
|
pairs=[tuple(map(int,row.split(','))) for row in re.findall(r'\{\{([0-9,]+)\}\}',re.search(pair_pattern,out).group())]
|
|
self.assertEqual(pairs,assessment['source_pairs']);self.assertEqual(len(pairs),59)
|
|
aliases=[tuple(map(int,row.split(','))) for row in re.findall(r'\{\{([0-9,]+)\}\}',re.search(alias_pattern,out).group())]
|
|
self.assertEqual(aliases,[(9,9,1),(10,10,0)])
|
|
mask=int(re.search(mask_pattern,out).group().split('=0x')[1][:-1],16)
|
|
self.assertEqual(mask,0x1A20)
|
|
self.assertEqual([i for i in range(1,14) if mask&(1<<(i-1))],[6,10,12,13])
|
|
before,after=header,out
|
|
for pattern in (pair_pattern,alias_pattern,mask_pattern):before=re.sub(pattern,'CHANGED',before);after=re.sub(pattern,'CHANGED',after)
|
|
self.assertEqual(before,after)
|
|
self.assertEqual(original.ROSTER_VISUAL_ALIASES,((9,27,1),(10,29,0)))
|
|
self.assertEqual(m.profile_candidate(out,assessment,source_identity=True),out)
|
|
changed=copy.deepcopy(assessment);changed['source_pairs'].remove((6,5));changed['source_pairs'].append((6,2));changed['source_pairs'].sort()
|
|
with self.assertRaises(ValueError):m.profile_candidate(header,changed,source_identity=True)
|
|
with self.assertRaises(ValueError):m.profile_candidate(header.replace('{{9,27,1}}','{{9,28,1}}'),assessment,source_identity=True)
|
|
# The older approved pair-only stage remains byte-for-byte scoped.
|
|
old=m.profile_candidate(header,assessment)
|
|
self.assertEqual(re.sub(pair_pattern,'PAIRS',header),re.sub(pair_pattern,'PAIRS',old))
|
|
def test_unknown_header_declaration_not_blindly_replaced(self):
|
|
with self.assertRaises(ValueError):m.profile_candidate('unrecognized',self.assessment())
|
|
def test_reviewed_native_schema_and_actual_wire_order(self):
|
|
d=self.fixture['native_schema'];fields=[tuple(f) for f in d['fields']]
|
|
self.assertEqual(typed.canonical_sha256(fields),m.CHAR_BASE_METADATA[2])
|
|
self.assertEqual(typed.encode({'ID':999,'RaceID':6,'ClassID':5,'OtherFactionRaceID':0},fields),b'\x06\x05\x00')
|
|
text='int RaceID\nint ClassID\nint OtherFactionRaceID\n\nLAYOUT '+f'{m.CHAR_BASE_METADATA[1]:08X}'+'\nBUILD '+typed.BUILD+'\n$noninline,id$ID<32>\nRaceID<8>\nClassID<8>\nOtherFactionRaceID<8>\n'
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
p=Path(temp)/'CharBaseInfo.dbd';p.write_text(text);self.assertEqual(m.native_schema(p),fields)
|
|
p.write_text(text.replace('ClassID<8>','ClassID<16>'))
|
|
with self.assertRaises(ValueError):m.native_schema(p)
|
|
|
|
if __name__=='__main__':unittest.main()
|