Files
WoW-Hybrid-gateway/tests/published_client_assets_test.py

305 lines
20 KiB
Python

import copy
import hashlib
import json
import os
from pathlib import Path
import sys
import tempfile
import unittest
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import published_client_assets as a
import linux_client_package as package
class PublishedAssetsTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.base = Path(self.temp.name)
self.source = self.base / 'source'
self.client = self.source / 'runtime/native-client'
self.client.mkdir(parents=True)
self.info = b'Active!DEC:1|Version!STRING:0|Build Key!HEX:16\n1|1.60.1.70334|0123456789abcdef0123456789abcdef\n'
(self.client / '.build.info').write_bytes(self.info)
self.proof = self.base / 'proof'
self.proof.mkdir()
self.root = '760135c6a63a4917ffde4a65c29c6b39'
self.validation = dict(passed=True, changed_assets=32, fdid_resolutions_exact=32,
strict_ckey_payloads_exact=32, warrior_ui_preserved=True,
all_parent_records_and_aliases_preserved=True, composed_root=self.root)
self.receipt = dict(schema_version=1,kind='closed-private-qa-material-publication-v1',applied=True,
target=str(self.client),registered_assets=6805,source_icon_bindings=841,new_assets=32,
composed_root=self.root,published_build_info_sha256=hashlib.sha256(self.info).hexdigest())
self.save()
def save(self):
vp = self.proof / 'changed-validation.json'
vp.write_text(json.dumps(self.validation))
self.receipt['changed_validation_sha256'] = a.digest(vp)
rp = self.proof / 'receipt.json'
rp.write_text(json.dumps(self.receipt))
declared = dict(receipt_path=str(rp),composed_root=self.root,validation_sha256=a.digest(vp))
(self.source / 'linux-release.json').write_text(json.dumps(dict(private_asset_publication=declared)))
def test_original_source_uses_existing_overlay(self):
(self.source/'linux-release.json').unlink()
self.assertIsNone(a.published_source(self.source))
def test_retains_publication_without_opening_data(self):
target=self.base/'copy';target.mkdir();(target/'.build.info').write_bytes(self.info)
real=a.digest
def bounded(path):
self.assertNotIn('Data',Path(path).parts)
return real(path)
with mock.patch.object(a,'digest',side_effect=bounded), mock.patch('warrior_action_bar_ui.stage_ui_assets',side_effect=AssertionError('old root reapplication')):
report=package.package_warrior_action_bar(self.source,target,self.base/'unused')
self.assertEqual(report['registered_asset_count'],6805)
self.assertEqual(report['root_audit']['new_content_key'],self.root)
self.assertEqual(report['source_icon_bindings'],841)
self.assertFalse((self.base/'unused').exists())
self.assertEqual((target/'.build.info').read_bytes(),self.info)
self.assertNotIn('target',json.dumps(report))
def test_retains_reviewed7866_delta_with_scoped_representative_evidence(self):
self.receipt.update(schema_version=2,kind='closed-private-material-delta-publication-v2',registered_assets=7866,new_assets=1061)
self.validation=dict(schema_version=2,kind='reused-completed-material-delta-validation-v2',passed=True,changed_assets=1061,registered_root_and_payloads_exact=1061,staged_CASC_representatives=4,staged_CASC_representatives_byte_exact=4,warrior_ui_preserved=True,all_parent_records_and_aliases_preserved=True,native_render_acceptance_verified=False,composed_root=self.root)
self.save();target=self.base/'delta-copy';target.mkdir();(target/'.build.info').write_bytes(self.info)
real=a.digest
def bounded(path):
self.assertNotIn('Data',Path(path).parts)
return real(path)
with mock.patch.object(a,'digest',side_effect=bounded),mock.patch('warrior_action_bar_ui.stage_ui_assets',side_effect=AssertionError('Do not reapply UI or rescanData')):
report=package.package_warrior_action_bar(self.source,target,self.base/'unused-delta')
self.assertEqual(report['registered_asset_count'],7866)
self.assertEqual(report['source_icon_bindings'],841)
self.assertEqual(report['owning_publication']['registered_assets'],7866)
marker=json.loads((target/'warrior-action-bar-casc.json').read_text())
self.assertEqual(marker['registered_asset_count'],7866)
self.assertEqual(marker['root_audit']['new_content_key'],self.root)
self.assertFalse(report['native_engine_acceptance_verified'])
for key,value in [('registered_root_and_payloads_exact',4),('staged_CASC_representatives',1061),('native_render_acceptance_verified',True)]:
previous=self.validation[key];self.validation[key]=value;self.save()
with self.assertRaises(ValueError):a.published_source(self.source)
self.validation[key]=previous
def test_stale_build_rejected(self):
(self.client/'.build.info').write_bytes(self.info+b'\n')
with self.assertRaisesRegex(ValueError,'build identity'):a.published_source(self.source)
def test_equipment7871_explicit_proof_writes_genuine_marker_without_release_mutation(self):
before=(self.source/'linux-release.json').read_bytes()
proof=self.base/'equipment-proof';proof.mkdir()
receipt=dict(self.receipt,schema_version=3,kind='closed-private-equipment-delta-publication-v3',
parent_registered_assets=7866,registered_assets=7871,new_assets=5,
old_root='edf3875d93cc173bb39d3bee42598e98')
validation=dict(schema_version=3,kind='reused-completed-equipment-delta-validation-v3',
passed=True,changed_assets=5,staged_native_SDK_FileID_bodies_exact=5,
metadata_rows_added=7,warrior_ui_preserved=True,
all_parent_records_and_aliases_preserved=True,
native_render_acceptance_verified=False,composed_root=self.root)
def declared():
vp=proof/'changed-validation.json';vp.write_text(json.dumps(validation))
receipt['changed_validation_sha256']=a.digest(vp)
rp=proof/'receipt.json';rp.write_text(json.dumps(receipt))
return dict(receipt_path=str(rp),composed_root=self.root,
validation_sha256=receipt['changed_validation_sha256'])
real=a.digest
def bounded(path):
self.assertNotIn('Data',Path(path).parts)
return real(path)
with mock.patch.object(a,'digest',side_effect=bounded):
report=a.retained_bar_package(self.source,self.client,declared_publication=declared())
self.assertEqual(report['registered_asset_count'],7871)
self.assertEqual(report['source_icon_bindings'],841)
self.assertFalse(report['native_engine_acceptance_verified'])
marker=json.loads((self.client/'warrior-action-bar-casc.json').read_text())
self.assertEqual(marker['kind'],'retained-published-controller-and-item-assets-v1')
self.assertEqual(marker['owning_publication']['registered_assets'],7871)
self.assertEqual((self.source/'linux-release.json').read_bytes(),before)
for key,value in (('old_root','0'*32),('parent_registered_assets',True)):
old=receipt[key];receipt[key]=value
with self.assertRaisesRegex(ValueError,'Unreviewed'):a.retained_bar_package(self.source,self.client,declared_publication=declared())
receipt[key]=old
for key,value in (('staged_native_SDK_FileID_bodies_exact',4),('native_render_acceptance_verified',True)):
old=validation[key];validation[key]=value
with self.assertRaisesRegex(ValueError,'not validated'):a.retained_bar_package(self.source,self.client,declared_publication=declared())
validation[key]=old
def test_generic_equipment_delta_uses_exact_parent_ids_sdk_and_metadata_lineage(self):
"""New publication boundary consumes the completed real private proofs."""
evidence=Path(os.environ.get('GW_TEST_PUBLICATION_PROOFS',
str(Path(__file__).resolve().parents[1]/'runtime/rea-system-jobs-20261022')))
job=evidence/'equipment-view-event-category-20261024'
staff=evidence/'high-elf-starting-appearance-20261024'
if not job.exists() or not staff.exists():
self.skipTest('Optional private equipment publication receipts absent: '+str(evidence))
# Supplied but partial/corrupt receipts must still fail the original
# strict digest and lineage checks below; never bless substitute data.
real_digest=a.digest;real_read=a.read;digests={};documents={};frozen=set()
def bounded_digest(path):
p=Path(path)
self.assertNotIn('Data',p.parts)
self.assertNotIn(p.suffix,('.m2','.skin','.blp','.blte'))
if p in frozen:
if p not in digests:digests[p]=real_digest(p)
return digests[p]
return real_digest(p)
def bounded_read(path):
p=Path(path)
self.assertNotIn('Data',p.parts)
if p in frozen:
if p not in documents:documents[p]=real_read(p)
return documents[p]
return real_read(p)
def ref(path):
path=Path(path);frozen.add(path)
return dict(path=str(path),sha256=bounded_digest(path))
inputs=dict(parent_assets=ref(staff/'registered-staff-canonical/manifest.json'),
assets=ref(job/'registered-seven-family-primary/manifest.json'),
parent_frames=ref(staff/'framed-staff-incremental/manifest.json'),
frames=ref(job/'framed-seven-family-incremental/manifest.json'),
sdk=ref(job/'native-SDK-readback-21-assets.json'),
metadata=ref(job/'sequential-six-supported-stage/validation.json'),
delta_plan=ref(job/'asset-publication-delta-plan.json'))
# The metadata artifacts are frozen dependencies too; consume their
# existing identity once, not once per negative-input subcase.
metadata=bounded_read(inputs['metadata']['path'])
for identity in metadata['input_identity'].values():frozen.add(Path(identity['path']))
parent_dir=self.base/'generic-parent';parent_dir.mkdir()
parent_receipt=real_read(staff/'closed-B-7871-publication/runtime-update-receipt.json')
parent_validation=real_read(staff/'closed-B-7871-publication/changed-validation.json')
parent_receipt=dict(parent_receipt,target=str(self.client))
parent_v=parent_dir/'changed-validation.json';parent_v.write_text(json.dumps(parent_validation))
parent_receipt['changed_validation_sha256']=real_digest(parent_v)
parent_p=parent_dir/'receipt.json';parent_p.write_text(json.dumps(parent_receipt))
frame=bounded_read(inputs['frames']['path']);delta=bounded_read(inputs['delta_plan']['path'])
ids=delta['new_file_data_ids'];self.assertEqual(len(ids),21)
proof=self.base/'generic-proof';proof.mkdir()
validation=dict(schema_version=4,kind='reused-completed-generic-equipment-delta-validation-v4',passed=True,
changed_assets=21,staged_native_SDK_FileID_bodies_exact=21,metadata_rows_added=24,
warrior_ui_preserved=True,all_parent_records_and_aliases_preserved=True,native_render_acceptance_verified=False,
new_physical_delta_files_copied_and_hash_exact=16,composed_root=frame['root']['content_key'])
receipt=dict(schema_version=4,kind='closed-private-equipment-delta-publication-v4',applied=True,
target=str(self.client),parent_registered_assets=7871,registered_assets=7892,source_icon_bindings=841,new_assets=21,
old_root=frame['parent_root'],composed_root=frame['root']['content_key'],new_file_data_ids=ids,
parent_publication=dict(receipt_path=str(parent_p),receipt_sha256=real_digest(parent_p),validation_sha256=real_digest(parent_v)),
inputs=inputs,framing_manifest_sha256=inputs['frames']['sha256'],
metadata_base_package_sha256=metadata['input_identity']['base_package']['sha256'],
metadata_package_sha256=metadata['input_identity']['package']['sha256'],published_build_info_sha256=hashlib.sha256(self.info).hexdigest())
def declared():
vp=proof/'changed-validation.json';vp.write_text(json.dumps(validation));receipt['changed_validation_sha256']=real_digest(vp)
rp=proof/'receipt.json';rp.write_text(json.dumps(receipt))
return dict(receipt_path=str(rp),composed_root=receipt['composed_root'],validation_sha256=receipt['changed_validation_sha256'])
def reject_field(key,value):
previous=receipt[key];receipt[key]=value
with self.assertRaises(ValueError):a._publication_proof(self.source,declared())
receipt[key]=previous
def reject_input(key,mutate):
previous=receipt['inputs'][key];doc=copy.deepcopy(bounded_read(previous['path']));mutate(doc)
path=proof/('mutated-'+key+'.json');path.write_text(json.dumps(doc));receipt['inputs'][key]=dict(path=str(path),sha256=real_digest(path))
with self.assertRaises(ValueError):a._publication_proof(self.source,declared())
receipt['inputs'][key]=previous
before=(self.source/'linux-release.json').read_bytes()
with mock.patch.object(a,'digest',side_effect=bounded_digest),mock.patch.object(a,'read',side_effect=bounded_read):
report=a.retained_bar_package(self.source,self.client,declared_publication=declared())
self.assertEqual(report['registered_asset_count'],7892)
self.assertEqual(report['root_audit']['new_content_key'],frame['root']['content_key'])
self.assertFalse(report['native_engine_acceptance_verified'])
self.assertEqual((self.source/'linux-release.json').read_bytes(),before)
marker=real_read(self.client/'warrior-action-bar-casc.json')
self.assertEqual(marker['kind'],'retained-published-controller-and-item-assets-v1')
self.assertEqual(marker['owning_publication']['registered_assets'],7892)
reject_field('parent_publication',dict(receipt['parent_publication'],receipt_sha256='0'*64))
reject_field('new_file_data_ids',ids[:-1])
reject_field('new_assets',True)
reject_field('registered_assets',7893)
reject_field('composed_root','0'*32)
reject_field('target',str(self.base/'other-client'))
reject_field('metadata_base_package_sha256','0'*64)
reject_input('sdk',lambda d:d['rows'][0].update(requested_file_data_id=1))
reject_input('sdk',lambda d:d['rows'][0].update(observed_body_MD5='0'*32))
reject_input('metadata',lambda d:d['input_identity']['base_package'].update(sha256='0'*64))
reject_input('metadata',lambda d:d.update(prefix_exact=False))
reject_input('delta_plan',lambda d:d.update(required_parent_ROOT='0'*32))
previous=validation['metadata_rows_added'];validation['metadata_rows_added']=25
with self.assertRaises(ValueError):a._publication_proof(self.source,declared())
validation['metadata_rows_added']=previous
previous=parent_receipt['target'];parent_receipt['target']=str(self.base/'foreign-parent')
parent_p.write_text(json.dumps(parent_receipt));receipt['parent_publication']['receipt_sha256']=real_digest(parent_p)
with self.assertRaises(ValueError):a._publication_proof(self.source,declared())
parent_receipt['target']=previous;parent_p.write_text(json.dumps(parent_receipt))
receipt['parent_publication']['receipt_sha256']=real_digest(parent_p)
(self.client/'.build.info').write_bytes(self.info+b'changed')
with self.assertRaisesRegex(ValueError,'build identity'):a._publication_proof(self.source,declared())
self.assertEqual((self.source/'linux-release.json').read_bytes(),before)
def test_foreign_target_rejected(self):
self.receipt['target']=str(self.base/'other');self.save()
with self.assertRaisesRegex(ValueError,'source manifest'):a.published_source(self.source)
def test_missing_or_changed_validation_rejected(self):
(self.proof/'changed-validation.json').write_text('{}')
with self.assertRaisesRegex(ValueError,'validation identity'):a.published_source(self.source)
def test_unproven_material_or_warrior_boundary_rejected(self):
for field,value in [('passed',False),('strict_ckey_payloads_exact',31),('warrior_ui_preserved',False),('all_parent_records_and_aliases_preserved',False)]:
with self.subTest(field=field):
original=self.validation[field];self.validation[field]=value;self.save()
with self.assertRaisesRegex(ValueError,'not validated'):a.published_source(self.source)
self.validation[field]=original
def test_receipt_counts_and_bool_schema_rejected(self):
for field,value in [('schema_version',True),('applied',1),('registered_assets',6773),('source_icon_bindings',839),('new_assets',13)]:
with self.subTest(field=field):
original=self.receipt[field];self.receipt[field]=value;self.save()
with self.assertRaisesRegex(ValueError,'Unreviewed'):a.published_source(self.source)
self.receipt[field]=original
def test_symlink_receipt_rejected(self):
p=self.proof/'receipt.json';p.rename(self.proof/'real.json');p.symlink_to(self.proof/'real.json')
with self.assertRaisesRegex(ValueError,'Regular publication'):a.published_source(self.source)
def test_copied_build_mismatch_rejected(self):
target=self.base/'copy';target.mkdir();(target/'.build.info').write_bytes(b'changed')
with self.assertRaisesRegex(ValueError,'Copied publication'):a.retained_bar_package(self.source,target)
def test_publication_helper_is_staging_only_not_a_client_runtime_dependency(self):
root=Path(__file__).resolve().parents[1]
runtime=set(package.ops_closure(root))
self.assertIn('ops/linux_client_package.py',runtime)
self.assertNotIn('ops/published_client_assets.py',runtime)
# Evaluate the same real imports with stage functions included: this
# distinguishes a deliberate package boundary from an orphaned helper.
with mock.patch.object(package,'STAGE_ONLY_IMPORT_FUNCTIONS',frozenset()):
staging=set(package.ops_closure(root))
self.assertIn('ops/published_client_assets.py',staging)
self.assertTrue(runtime <= staging)
class CopiedAddonBoundaryTest(unittest.TestCase):
def setUp(self):
self.temp=tempfile.TemporaryDirectory();self.addCleanup(self.temp.cleanup)
self.client=Path(self.temp.name)/'fresh';self.base=self.client/'_classic_beta_/Interface/AddOns'
self.path=self.base/'WoWHybridIssueReporter';self.path.mkdir(parents=True)
for name in ['WoWHybridIssueReporter.toc','IssueReporter.lua']:(self.path/name).write_text('copied')
def test_only_declared_fresh_copy_is_regenerated(self):
other=self.base/'Other';other.mkdir();(other/'keep.lua').write_text('keep')
a.discard_copied_packaged_addons(self.client)
self.assertFalse(self.path.exists());self.assertEqual((other/'keep.lua').read_text(),'keep')
def test_unknown_file_preserves_whole_addon(self):
(self.path/'unknown.lua').write_text('keep')
with self.assertRaisesRegex(ValueError,'undeclared'):a.discard_copied_packaged_addons(self.client)
self.assertTrue((self.path/'IssueReporter.lua').exists())
def test_symlink_file_is_never_removed(self):
(self.path/'IssueReporter.lua').unlink();target=Path(self.temp.name)/'keep';target.write_text('keep')
(self.path/'IssueReporter.lua').symlink_to(target)
with self.assertRaisesRegex(ValueError,'undeclared'):a.discard_copied_packaged_addons(self.client)
self.assertEqual(target.read_text(),'keep')
if __name__ == '__main__':unittest.main()