Files
WoW-Hybrid-gateway/ops/prepare_warrior_cooldown_modifiers.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

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

137 lines
8.2 KiB
Python

#!/usr/bin/env python3
"""Bounded offline inventory derivation for Warrior flat cooldown packets."""
import argparse
import hashlib
import json
from pathlib import Path
import warrior_cooldown_modifier as policy
ROOT = Path(__file__).resolve().parents[1]
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def prepare(args):
output = args.output.resolve()
if not output.is_relative_to(ROOT / 'runtime'):
raise ValueError('isolated runtime output required')
for path, expected in [(args.package, args.package_sha256), (args.native, args.native_sha256),
(args.source_manifest, args.source_manifest_sha256), (args.audit, args.audit_sha256)]:
if sha(path) != expected:
raise ValueError('pinned input digest mismatch')
manifest = json.loads(args.source_manifest.read_text())
if type(manifest.get('schema_version')) is not int or manifest['schema_version'] != 1:
raise ValueError('source manifest schema')
chunks = manifest.get('chunks')
if type(chunks) is not list or not 1 <= len(chunks) <= 1000:
raise ValueError('complete bounded source chunks required')
inventory, source_rows, pins, last, total = [], {}, {}, 0, 0
for chunk in chunks:
name = chunk['path']
if type(name) is not str or Path(name).name != name or not name.endswith('.json'):
raise ValueError('source chunk path escape')
path = args.source_manifest.parent / name
raw = path.read_bytes()
if len(raw) != chunk['bytes'] or len(raw) > 4000000 or hashlib.sha256(raw).hexdigest() != chunk['sha256']:
raise ValueError('source chunk identity mismatch')
rows = json.loads(raw)
if type(rows) is not list or len(rows) != chunk['count'] or not rows:
raise ValueError('source chunk row count')
if rows[0]['entry'] != chunk['first_id'] or rows[-1]['entry'] != chunk['last_id']:
raise ValueError('source chunk endpoint identities')
for row in rows:
ident = policy._integer(row['entry'], 1, 0x7fffffff, 'source identity')
if ident <= last or ident in source_rows:
raise ValueError('source order/duplicate identity')
last = ident
inventory.append({'id': ident, 'family': policy._integer(row['spellFamilyName'], 0, 0xffffffff, 'source family'),
'mask': policy._integer(row['spellFamilyFlags'], 0, 0xffffffffffffffff, 'source mask')})
# Preserve all fields from pinned chunks by reference, not a rewritten
# partial source snapshot. Family reporting reads the real rows.
source_rows[ident] = row
total += len(raw)
pins[str(path)] = sha(path)
if len(inventory) != manifest['spell_count'] or total != manifest['total_chunk_bytes']:
raise ValueError('complete source totals mismatch')
ids = sorted(source_rows)
if ids[0] != manifest['first_id'] or ids[-1] != manifest['last_id']:
raise ValueError('complete source endpoints mismatch')
native = json.loads(args.native.read_text())
if type(native) is not list or len(native) > 100000:
raise ValueError('complete native class export required')
seen, spell_ids = set(), set()
for row in native:
rid = policy._integer(row['ID'], 1, 0x7fffffff, 'native base identity')
spell = policy._integer(row['SpellID'], 1, 0x7fffffff, 'native base spell identity')
if rid in seen or spell in spell_ids:
raise ValueError('duplicate complete native identity')
seen.add(rid);spell_ids.add(spell)
base = [row for row in native if row['SpellClassSet'] == policy.FAMILY]
package = json.loads(args.package.read_text())
if len(package['rows']) != args.expected_package_rows:
raise ValueError('expected package row count differs')
target = policy.effective_native_class4(base, package['rows'])
profile = policy.derive(inventory, target)
audit = json.loads(args.audit.read_text())
admission = {row['source_bit']: row for row in profile['admitted']}
holds = {row['source_bit']: row for row in profile['held']}
families = []
for row in audit['modifier_rows']:
if row['operation'] != policy.OPERATION or row['source_aura'] != 107:
continue
sid = row['spell'];actual = source_rows.get(sid)
if actual is None:
raise ValueError('audited cooldown talent absent from complete source')
effect = policy._integer(row['effect_index'], 0, 2, 'audited source effect slot') + 1
if actual['effect' + str(effect)] != 6 or actual['effectApplyAuraName' + str(effect)] != 107 or actual['effectMiscValue' + str(effect)] != policy.OPERATION:
raise ValueError('audited source effect changed')
mask = policy._integer(row['source_affect_mask'], 1, 0xffffffffffffffff, 'audited source affect mask')
bits = [bit for bit in range(64) if mask & (1 << bit)]
if bits != row['source_affect_bits']:
raise ValueError('audited source mask/bit membership mismatch')
families.append({'source_spell': sid, 'talent': row['talent'], 'effect_index': row['effect_index'],
'source_mask': row['source_affect_mask'], 'source_bits': bits,
'status': 'complete-bit-mapping' if all(bit in admission for bit in bits) else 'held-bit-mapping',
'routes': [admission[bit] for bit in bits if bit in admission],
'holds': [holds[bit] for bit in bits if bit in holds]})
for path in [args.source_manifest, args.native, args.package, args.audit, Path(policy.__file__), Path(__file__)]:
pins[str(path)] = sha(path)
output.mkdir(parents=True, exist_ok=True)
if any(output.iterdir()):
raise ValueError('fresh output directory required')
for name, value in [('source-class-inventory.json', inventory), ('native-class4-inventory.json', target),
('mapping-profile.json', profile), ('cooldown-talent-families.json', families)]:
(output / name).write_text(json.dumps(value, sort_keys=True, separators=(',', ':')) + '\n')
report = {'kind': policy.POLICY, 'source_rows': len(inventory), 'source_class4_rows': sum(row['family'] == 4 for row in inventory),
'native_base_rows': len(native), 'native_base_class4_rows': len(base), 'native_effective_class4_rows': len(target),
'package_rows': len(package['rows']), 'source_bits': len(profile['source_bits']),
'admitted_bits': len(profile['admitted']), 'held_bits': len(profile['held']),
'audited_flat_cooldown_effects': len(families),
'complete_audited_effects': sum(row['status'] == 'complete-bit-mapping' for row in families),
'all_source_fields_preserved_in_original_chunks': True, 'input_sha256': pins,
'output_sha256': {path.name: sha(path) for path in sorted(output.glob('*.json'))},
'installed': False, 'native_runtime_integrated': False, 'live_acceptance': False,
'limitations': manifest.get('limits', []) + ['Complete native base+current overlays pinned; source snapshot date retained, not a fresh live database query.',
'Strict bit-level runtime aggregate routes only; static union-cover equivalence is held.',
'Only flat cooldown11. Percent/other semantic namespaces remain held.']}
(output / 'report.json').write_text(json.dumps(report, indent=2) + '\n')
return report
def main():
parser = argparse.ArgumentParser(description=__doc__)
for name in ['source-manifest', 'native', 'package', 'audit', 'output']:
parser.add_argument('--' + name, type=Path, required=True)
for name in ['source-manifest-sha256', 'native-sha256', 'package-sha256', 'audit-sha256']:
parser.add_argument('--' + name, required=True)
parser.add_argument('--expected-package-rows', type=int, required=True)
args = parser.parse_args()
report = prepare(args)
print(json.dumps({key: report[key] for key in ['source_class4_rows', 'native_effective_class4_rows', 'admitted_bits', 'held_bits', 'complete_audited_effects']}, sort_keys=True))
if __name__ == '__main__':
main()