367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
149 lines
9.8 KiB
Python
149 lines
9.8 KiB
Python
"""Source-confirmed set relationship metadata; spell conversion stays separate.
|
|
|
|
This independent policy publishes source names, rosters and bonus thresholds.
|
|
It does not mark referenced spells as converted or waive the existing spell
|
|
definition dependency gate in item_source_corrections.
|
|
"""
|
|
from copy import deepcopy
|
|
from collections import Counter
|
|
import hashlib
|
|
from item_set_compat import generate,TABLES,source_set,REMOVAL_POLICY
|
|
from item_sparse_compat import package_payloads,package_pages,encode
|
|
|
|
POLICY='source-confirmed-set-relationship-metadata-independent-closure-v1'
|
|
|
|
def migrate_source_selection(package,previous_component,source,native_sets,native_children,
|
|
schemas,native_max):
|
|
"""Recompose a reviewed source-set cohort after its DBC selection changes.
|
|
|
|
The previous component must still be byte-identical in the private package.
|
|
Retired source-owned child IDs become pinned RecordRemoved rows and remain
|
|
reserved; all unrelated package rows are retained by the normal composer.
|
|
"""
|
|
if previous_component.get('kind')!='source-item-set-components':
|
|
raise ValueError('Reviewed prior source set component required')
|
|
old_rows=previous_component['records']
|
|
old={(r['table_name'],r['id']):r for r in old_rows}
|
|
current={(r['table_name'],r['id']):r for r in package['rows']}
|
|
if len(old)!=len(old_rows) or len(current)!=len(package['rows']):
|
|
raise ValueError('Duplicate source set or package identity')
|
|
if any(current.get(key)!=row for key,row in old.items()):
|
|
raise ValueError('Prior source set component differs from private package')
|
|
prior=previous_component['registry']
|
|
if prior.get('version')!=1 or not isinstance(prior.get('slots'),dict):
|
|
raise ValueError('Reviewed source set registry required')
|
|
native_by_set={}
|
|
for row in native_children:native_by_set.setdefault(row['ItemSetID'],[]).append(row)
|
|
active=set()
|
|
for row in source:
|
|
_,bonuses=source_set(row)
|
|
existing=native_by_set.get(row['id'],[])
|
|
wanted=sorted((spell,threshold,0,0) for _,spell,threshold in bonuses)
|
|
actual=sorted((child['SpellID'],child['Threshold'],child['ChrSpecID'],
|
|
child['TraitSubTreeID']) for child in existing)
|
|
if existing and actual==wanted:continue
|
|
active.update(f"{row['id']}:{slot}" for slot,_,_ in bonuses)
|
|
slots=prior['slots'];retired=dict(prior.get('retired_slots',{}))
|
|
if not all(isinstance(key,str) and type(value)is int for key,value in slots.items()):
|
|
raise ValueError('Prior source set slots differ')
|
|
if set(retired)&set(slots) or set(retired)&active:
|
|
raise ValueError('Retired source set slot reappeared without review')
|
|
removed=sorted(set(slots)-active)
|
|
for key in removed:retired[key]=slots[key]
|
|
all_ids=(list(slots.values())+list(retired.values())+
|
|
[r['id'] for r in package['rows'] if r['table_name']=='ItemSetSpell'])
|
|
new_slots={key:value for key,value in slots.items() if key in active}
|
|
if len(set(new_slots.values())|set(retired.values()))!=len(new_slots)+len(retired):
|
|
raise ValueError('Source set registry ID collision')
|
|
next_id=max([native_max,*all_ids])
|
|
for key in sorted(active-set(slots)):
|
|
next_id+=1;new_slots[key]=next_id
|
|
registry=dict(version=1,slots=new_slots,retired_slots=retired)
|
|
base=deepcopy(package);base['rows']=[r for r in base['rows']
|
|
if (r['table_name'],r['id']) not in old]
|
|
for key in removed:
|
|
ident=slots[key];prior_row=old.get(('ItemSetSpell',ident))
|
|
if prior_row is None or prior_row.get('record_status','valid')!='valid':
|
|
raise ValueError('Retired set child lacks prior valid record')
|
|
baseline=dict(prior_row['record'],ID=ident)
|
|
base['rows'].append(dict(table_name='ItemSetSpell',table_hash=hex(TABLES['ItemSetSpell'][0]),
|
|
id=ident,record_status='removed',record=None,wire_hex='',
|
|
sha256=hashlib.sha256(b'').hexdigest(),source_set=int(key.split(':',1)[0]),
|
|
baseline_record=baseline,baseline_record_sha256=prior_row['sha256'],
|
|
policy=REMOVAL_POLICY))
|
|
base['push_id']=package_payloads(base['rows'])[0]
|
|
base['pushes']=package_pages(base['rows'])
|
|
result=compose(base,source,native_sets,native_children,schemas,native_max,registry)
|
|
result['migration']=dict(previous_component_rows=len(old),retired_slots=removed,
|
|
new_slots=sorted(active-set(slots)),unchanged_slots=len(active&set(slots)),
|
|
unrelated_package_rows_preserved=True,previous_component_exact=True)
|
|
result['all_published_rows_preserved']=False
|
|
result['published_rows_replaced']=len(old)
|
|
result['registry']=registry
|
|
return result
|
|
|
|
def compose(package,source,native_sets,native_children,schemas,native_max,registry):
|
|
"""Preserve published rows; add exact source-owned rows/tombstones only.
|
|
|
|
A differing already-published row is a migration blocker, even when source
|
|
metadata is known. Original-native removals retain the existing set-owned
|
|
baseline/hash policy. The final effective relationships must match source.
|
|
"""
|
|
if(package.get('build')!='1.60.1.70334'or package.get('schema')!='wowstatic_camelot_1_60_1'
|
|
or package.get('push_id')!=package_payloads(package.get('rows'))[0]):
|
|
raise ValueError('Pinned relationship package identity differs')
|
|
records=package['rows'];index={(r['table_name'],r['id']):r for r in records}
|
|
if len(index)!=len(records):raise ValueError('Duplicate published relationship identity')
|
|
component=generate(source,native_sets,native_children,schemas,native_max,registry,replace_existing=True)
|
|
# The existing encoder validates every source-owned removal baseline and
|
|
# refuses tombstones for another table, owner, or unreviewed delete policy.
|
|
package_payloads(component['records'])
|
|
added=[];same=[]
|
|
for row in component['records']:
|
|
key=(row['table_name'],row['id']);old=index.get(key)
|
|
if old is None:added.append(deepcopy(row));continue
|
|
if(old.get('record_status','valid')!=row.get('record_status','valid')or
|
|
old.get('wire_hex')!=row['wire_hex']or old.get('sha256')!=row['sha256']):
|
|
raise ValueError('Published set row differs; explicit migration required')
|
|
same.append(key)
|
|
result=deepcopy(package);result['rows']+=added
|
|
result['push_id']=package_payloads(result['rows'])[0];result['pushes']=package_pages(result['rows'])
|
|
if len({(r['table_name'],r['id'])for r in result['rows']})!=len(result['rows']):raise ValueError('New set relationship collision')
|
|
parents={r['ID']:deepcopy(r)for r in native_sets};children={r['ID']:deepcopy(r)for r in native_children}
|
|
for row in result['rows']:
|
|
if row['table_name']=='ItemSet':
|
|
if row.get('record_status','valid')!='valid':raise ValueError('ItemSet removal is outside relationship policy')
|
|
value=row.get('record');wire=encode(value,schemas['ItemSet'])
|
|
if row['id']!=value.get('ID')or row['wire_hex']!=wire.hex()or row['sha256']!=hashlib.sha256(wire).hexdigest():raise ValueError('Published ItemSet bytes differ')
|
|
parents[row['id']]=value
|
|
elif row['table_name']=='ItemSetSpell':
|
|
if row.get('record_status','valid')=='removed':children.pop(row['id'],None)
|
|
else:
|
|
value=row.get('record');wire=encode(value,schemas['ItemSetSpell'])
|
|
if row['wire_hex']!=wire.hex()or row['sha256']!=hashlib.sha256(wire).hexdigest():raise ValueError('Published ItemSetSpell bytes differ')
|
|
children[row['id']]=dict(value,ID=row['id'])
|
|
children_by_set={}
|
|
for row in children.values():children_by_set.setdefault(row['ItemSetID'],[]).append(row)
|
|
verified=[]
|
|
for original in sorted(source,key=lambda r:r['id']):
|
|
expected,bonuses=source_set(original);ident=expected['ID']
|
|
actual=parents.get(ident)
|
|
if actual!=expected:raise ValueError('Effective source set parent differs')
|
|
wanted=sorted((spell,threshold,0,0)for _,spell,threshold in bonuses)
|
|
linked=sorted((r['SpellID'],r['Threshold'],r['ChrSpecID'],r['TraitSubTreeID'])for r in children_by_set.get(ident,[]))
|
|
if linked!=wanted:raise ValueError('Effective source bonus relationship differs')
|
|
verified.append(dict(set_id=ident,name=expected['Name_lang'],member_ids=[i for i in expected['ItemID']if i],bonus_slots=[dict(source_slot=slot,spell_id=spell,threshold=threshold)for slot,spell,threshold in bonuses],required_skill=expected['RequiredSkill'],required_skill_rank=expected['RequiredSkillRank']))
|
|
return dict(kind='source-set-relationship-metadata-candidate',relationship_policy=POLICY,
|
|
package=result,records=added,all_source_component=component,
|
|
source_set_count=len(source),source_bonus_slots=sum(len(r['bonus_slots'])for r in verified),
|
|
verified_effective_sets=verified,already_published_identical_rows=len(same),
|
|
added_counts={table+':'+status:count for(table,status),count in Counter((r['table_name'],r.get('record_status','valid'))for r in added).items()},
|
|
all_published_rows_preserved=True,published_rows_replaced=0,
|
|
membership_fields_modified=False,spell_definitions_modified=False,
|
|
source_relationship_metadata_complete=True,spell_definition_closure_complete=False,
|
|
existing_spell_definition_dependency_guard_modified=False,dependency_complete=False,
|
|
installable=False,installed=False,engine_accepted=False,gameplay_verified=False,
|
|
limits=['Independent source-confirmed relationship metadata only; referenced spell definition presence/semantics remains separately inventoried.',
|
|
'No new class/spec eligibility, learned spells, item stats, aura holders or gameplay effects are synthesized.',
|
|
'All previously published rows remain exact; original-native bonus replacements use existing source-set-owned tombstones.'])
|