153 lines
14 KiB
Python
153 lines
14 KiB
Python
"""New Windows packaging boundaries; synthetic files, no VM or native claims."""
|
|
import copy,json,os,subprocess,sys,tempfile,types,unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import linux_client_package as policy
|
|
import windows_client_package as package
|
|
import windows_backend_runtime_check as runtime_probe
|
|
import published_client_assets as publication
|
|
import ui_release_guard
|
|
|
|
def save(path,value):
|
|
path.parent.mkdir(parents=True,exist_ok=True);path.write_text(json.dumps(value));return dict(path=str(path),sha256=package.digest(path))
|
|
def client(base):
|
|
game=base/'_classic_beta_';(game/'WTF').mkdir(parents=True)
|
|
(game/'WTF/Config.wtf').write_text('SET gxApi "D3D11"\n')
|
|
for name in policy.PRODUCT_FILES:(base/name).write_bytes(b'product')
|
|
for name in policy.DATA_TREES:
|
|
folder=base/'Data'/name;folder.mkdir(parents=True);(folder/'unchanged').write_bytes(b'preserved')
|
|
for name in policy.GAME_FILES:(game/name).write_bytes(b'game')
|
|
for name in policy.GAME_TREES:
|
|
folder=game/name;folder.mkdir();(folder/'resource').write_bytes(b'resource')
|
|
(base/'Data/data/shmem').write_bytes(b'mutable cache')
|
|
|
|
class IncrementalAssets(unittest.TestCase):
|
|
def test_real_package_resume_and_artifact_transport_admission(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);linux=root/'linux';source=root/'source';modules=root/'modules';modules.mkdir()
|
|
client(linux/'runtime/native-client')
|
|
for folder in ('ops','docs','compat','runtime/native-handler-code'):
|
|
path=linux/folder;path.mkdir(parents=True,exist_ok=True);(path/'receipt.txt').write_text('frozen')
|
|
save(linux/'compat/native-engine-template.json',{})
|
|
lineage = dict(status='PASS_QUALIFIED_NATIVE_UI_NO_REMINDER_ADDON',
|
|
build_info_sha256=package.digest(linux/'runtime/native-client/.build.info'),
|
|
selected_sha256={str(fid):next(iter(choices)) for fid,choices in ui_release_guard.QUALIFIED.items()})
|
|
save(linux/'linux-release.json',dict(known_issues=[],ui_fix_lineage=lineage));(linux/'BUILD-NOTES.txt').write_text('notes')
|
|
for relative in ('ops/helper.py','launcher/launcher.py','native/windows_launcher_entry.c'):
|
|
path=source/relative;path.parent.mkdir(parents=True,exist_ok=True);path.write_text('frozen source')
|
|
profile=dict(schema=1,backend_transport='owned-stdio-ipc-v1')
|
|
for role,name in [('bridge','GWNativeBridge.dll'),('wire','GWNativeWire.dll'),('backend','GWNativeBackend.dll'),('codec','forever_codec.dll'),('backend_host','windows-backend-host.exe')]:
|
|
path=modules/name;path.write_bytes(name.encode());profile[role]=dict(path='build/'+name,sha256=package.digest(path))
|
|
provenance=dict(new_matching_canonical_IPC_frontend=True,changed_modules={name:dict(path='build/'+name,sha256=package.digest(modules/name)) for name in ('GWNativeWire.dll','GWNativeBackend.dll','windows-backend-host.exe')},codec_provenance=dict(codec='build/forever_codec.dll',codec_sha256=package.digest(modules/'forever_codec.dll')))
|
|
profile=package.artifact_profile_from_provenance(profile,provenance)
|
|
with self.assertRaises(ValueError):package.artifact_profile_from_provenance(profile,dict(provenance,new_matching_canonical_IPC_frontend=False))
|
|
profile_path=root/'artifact-profile.json';save(profile_path,profile)
|
|
(root/'windows-python-runtime-20261022').mkdir();(root/'windows-python-runtime-20261022/python.exe').write_bytes(b'python')
|
|
output=root/'candidate';work=root/'work';calls=[]
|
|
def command(args,**kwargs):
|
|
calls.append(args)
|
|
if '-o'in args:Path(args[args.index('-o')+1]).write_bytes(b'compiler output')
|
|
return subprocess.CompletedProcess(args,0,'offline synthetic check','')
|
|
# Exercise publish itself with only OS/compiler/image transformation replaced.
|
|
native_os=types.SimpleNamespace(**{key:getattr(os,key) for key in ('environ','pathsep','link','replace')},name='nt')
|
|
kwargs=dict(linux=linux,source=source,output=output,revision='frozen-revision',modules=modules,work_directory=work,module_profile=profile_path,module_profile_sha256=package.digest(profile_path))
|
|
with patch.object(package,'os',native_os),patch.object(package.subprocess,'run',side_effect=command),patch('windows_image_profile.prepare',return_value={}):
|
|
failure = subprocess.CompletedProcess([], 1, '', 'forever_codec.dll: [WinError 127] procedure not found')
|
|
with patch.object(package.subprocess, 'run', return_value=failure) as probe:
|
|
with self.assertRaisesRegex(ValueError, r'forever_codec\.dll.*WinError 127'):
|
|
package.publish(**kwargs)
|
|
self.assertEqual(probe.call_args.args[0][-1], str(modules))
|
|
self.assertFalse(output.exists())
|
|
result=package.publish(**kwargs)
|
|
actual=json.loads((output/'compat/windows-native.json').read_text())
|
|
self.assertEqual(actual['backend_transport'],'owned-stdio-ipc-v1')
|
|
self.assertEqual(actual['backend_host']['sha256'],package.digest(output/'build/windows-backend-host.exe'))
|
|
self.assertEqual(result['package_input_identity']['artifacts']['windows-backend-host.exe'],profile['backend_host']['sha256'])
|
|
package.publish(**kwargs) # Same completed inputs resume through actual path.
|
|
self.assertTrue(any(str(output/'build') == call[-1] and '-I' in call for call in calls))
|
|
before=len(calls)
|
|
for changes in (dict(revision='other'),dict(backend_transport='wrong')):
|
|
with self.assertRaises(ValueError):package.publish(**dict(kwargs,**changes))
|
|
helper=source/'ops/helper.py';helper.write_text('changed source')
|
|
with self.assertRaises(ValueError):package.publish(**kwargs)
|
|
helper.write_text('frozen source')
|
|
old=(modules/'windows-backend-host.exe').read_bytes();(modules/'windows-backend-host.exe').unlink()
|
|
fresh=root/'must-not-exist'
|
|
with self.assertRaises(ValueError):package.publish(**dict(kwargs,output=fresh))
|
|
self.assertFalse(fresh.exists());self.assertEqual(len(calls),before)
|
|
(modules/'windows-backend-host.exe').write_bytes(old)
|
|
save(profile_path,dict(profile,backend_transport=None))
|
|
with self.assertRaises(ValueError):package.publish(**dict(kwargs,output=fresh,module_profile_sha256=package.digest(profile_path)))
|
|
self.assertFalse(fresh.exists())
|
|
|
|
def test_backend_probe_uses_only_local_and_system_dependencies(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory).resolve()
|
|
with patch.object(runtime_probe.ctypes, 'WinDLL', create=True) as load:
|
|
runtime_probe.check_runtime(root)
|
|
loaded = [(call.args[0], call.kwargs['winmode']) for call in load.call_args_list[1:]]
|
|
self.assertEqual(loaded, [(str(root/name), 0x0900) for name in ('forever_codec.dll', 'GWNativeBackend.dll')])
|
|
load.reset_mock()
|
|
load.side_effect = [types.SimpleNamespace(SetErrorMode=lambda mode: None),
|
|
OSError('[WinError 127] procedure not found')]
|
|
with self.assertRaisesRegex(RuntimeError, r'forever_codec\.dll.*WinError 127'):
|
|
runtime_probe.check_runtime(root)
|
|
self.assertEqual(load.call_count, 2)
|
|
|
|
def test_reviewed_v4_descendant_real_copy_and_fail_closed_lineage(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);base=root/'old/runtime/native-client';new=root/'source/runtime/native-client'
|
|
client(base);client(new)
|
|
parent_root='2ed14fe112a8f061e07eabc80b2ac128';next_root='040bd93c5e362c5a9947360b3088eaef'
|
|
(base/'Data/data/changed').write_bytes(b'old');(new/'Data/data/changed').write_bytes(b'new')
|
|
(new/'.build.info').write_bytes(b'new activation')
|
|
assets=[dict(file_data_id=i,path=str(i),bytes=1,content_key='a'*32,sha256='a'*64) for i in range(1,6806)]
|
|
added=dict(file_data_id=6806,path='new.blp',bytes=3,content_key='b'*32,sha256='b'*64)
|
|
before=save(root/'before.json',dict(assets=assets,registry=dict(slots={}),source_icon_bindings=841))
|
|
after=save(root/'after.json',dict(assets=assets+[added],registry=dict(slots={}),source_icon_bindings=841,source_parent_manifest_sha256=before['sha256']))
|
|
frame0=save(root/'frame0.json',dict(root=dict(content_key=parent_root),asset_manifest_sha256=before['sha256'],warrior_ui_content_key='f'*32))
|
|
parent_receipt=dict(schema_version=1,kind='closed-private-qa-material-publication-v1',applied=True,target=str(base),registered_assets=6805,source_icon_bindings=841,new_assets=32,composed_root=parent_root,published_build_info_sha256=package.digest(base/'.build.info'),framing_manifest_sha256=frame0['sha256'])
|
|
def declare(folder,receipt,validation):
|
|
vr=save(folder/'changed-validation.json',validation);receipt['changed_validation_sha256']=vr['sha256'];rr=save(folder/'receipt.json',receipt)
|
|
return dict(receipt_path=rr['path'],composed_root=receipt['composed_root'],validation_sha256=vr['sha256'])
|
|
decl0=declare(root/'parent-proof',parent_receipt,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=parent_root))
|
|
save(base.parent.parent/'windows-release.json',dict(private_asset_publication=decl0))
|
|
# Parent receipt used by source lineage belongs to that source lifetime.
|
|
source_parent=copy.deepcopy(parent_receipt);source_parent['target']=str(new)
|
|
decl_historical=declare(root/'source-parent-proof',source_parent,json.loads((root/'parent-proof/changed-validation.json').read_text()))
|
|
frame=save(root/'frame.json',dict(root=dict(content_key=next_root),parent_root=parent_root,asset_manifest_sha256=after['sha256'],source_rows=[dict(asset=added)],old_asset_count=6805,registered_asset_count=6806,new_asset_count=1,warrior_ui_content_key='f'*32,source_icon_bindings_preserved=841,encoding_audit=dict(all_original_content_key_encoding_bindings_preserved=True),download_audit=dict(original_entry_bytes_preserved=True,original_tag_bits_preserved=True),tvfs_child_audit=dict(old_cft_vfs_and_spec_prefixes_preserved=True)))
|
|
sdk=save(root/'sdk.json',dict(schema_version=1,kind='native-sdk-selected-fileid-readback-v1',passed=True,status='PASS_NATIVE_SDK_FILEID_BODY_READBACK',effective_root=next_root,parent_root=parent_root,product='wow_classic_beta',build=70334,body_reads=1,native_render_acceptance=False,game_launched=False,rows=[dict(requested_file_data_id=6806,status='PASS',expected_content_key='b'*32,observed_body_MD5='b'*32,expected_size=3,observed_size=3)]))
|
|
metadata=save(root/'metadata.json',dict(status='PASS_OWNING',prefix_exact=True,unique_record_ids=True,push_identity_and_pages_exact=True,input_identity=dict(base_package=save(root/'old-package.json',{}),package=save(root/'new-package.json',{})),base_rows=1,new_rows=1,rows=2))
|
|
plan=dict(required_parent_ROOT=parent_root,new_ROOT=next_root,new_file_data_ids=[6806],parent_asset_count=6805,new_asset_count=6806,new_source_payloads=1,files=[dict(relative='.build.info'),dict(relative='Data/data/changed')])
|
|
plan_path=root/'plan.json';delta=save(plan_path,plan)
|
|
inputs=dict(parent_assets=before,assets=after,parent_frames=frame0,frames=frame,sdk=sdk,metadata=metadata,delta_plan=delta)
|
|
receipt=dict(schema_version=4,kind='closed-private-equipment-delta-publication-v4',applied=True,target=str(new),parent_registered_assets=6805,registered_assets=6806,source_icon_bindings=841,new_assets=1,old_root=parent_root,composed_root=next_root,new_file_data_ids=[6806],parent_publication=dict(receipt_path=decl_historical['receipt_path'],receipt_sha256=package.digest(decl_historical['receipt_path']),validation_sha256=decl_historical['validation_sha256']),inputs=inputs,framing_manifest_sha256=frame['sha256'],metadata_base_package_sha256=json.loads(Path(metadata['path']).read_text())['input_identity']['base_package']['sha256'],metadata_package_sha256=json.loads(Path(metadata['path']).read_text())['input_identity']['package']['sha256'],published_build_info_sha256=package.digest(new/'.build.info'))
|
|
validation=dict(schema_version=4,kind='reused-completed-generic-equipment-delta-validation-v4',passed=True,changed_assets=1,staged_native_SDK_FileID_bodies_exact=1,metadata_rows_added=1,warrior_ui_preserved=True,all_parent_records_and_aliases_preserved=True,native_render_acceptance_verified=False,new_physical_delta_files_copied_and_hash_exact=2,composed_root=next_root)
|
|
decl=declare(root/'child-proof',receipt,validation);save(new.parent.parent/'linux-release.json',dict(private_asset_publication=decl))
|
|
target=root/'candidate';activations=[];replace=os.replace
|
|
def replaced(src,dst):activations.append(Path(dst).name);return replace(src,dst)
|
|
with patch.object(package.os,'replace',side_effect=replaced):copied=package.copy_public_client(new,target,base,plan_path)
|
|
self.assertEqual(copied['retained_asset_publication']['source_manifest_sha256'],package.digest(new.parent.parent/'linux-release.json'))
|
|
inherited=root/'inherited/runtime/native-client';inherited.mkdir(parents=True);(inherited/'.build.info').write_bytes((new/'.build.info').read_bytes())
|
|
save(inherited.parent.parent/'windows-release.json',dict(retained_asset_publication=copied['retained_asset_publication']))
|
|
inherited_proof,_,_=package.reviewed_package_publication(inherited,'windows-release.json')
|
|
self.assertEqual(inherited_proof['composed_root'],next_root)
|
|
(inherited/'.build.info').write_bytes(b'wrong copied generation')
|
|
with self.assertRaises(ValueError):package.reviewed_package_publication(inherited,'windows-release.json')
|
|
self.assertEqual(activations[-1],'.build.info')
|
|
self.assertEqual((target/'Data/data/changed').read_bytes(),b'new');self.assertEqual((base/'Data/data/changed').read_bytes(),b'old')
|
|
self.assertEqual((target/'Data/data/unchanged').stat().st_ino,(base/'Data/data/unchanged').stat().st_ino)
|
|
self.assertNotEqual((target/'Data/data/shmem').stat().st_ino,(base/'Data/data/shmem').stat().st_ino)
|
|
for number,change in enumerate((dict(new_ROOT='0'*32),dict(required_parent_ROOT='1'*32),dict(files=[dict(relative='../escape')]))):
|
|
save(plan_path,dict(plan,**change));refused=root/f'refused-{number}'
|
|
with self.assertRaises(ValueError):package.copy_public_client(new,refused,base,plan_path)
|
|
self.assertFalse(refused.exists())
|
|
save(plan_path,plan)
|
|
# The actual owning validator, not a Root-name whitelist, rejects a lost pin.
|
|
decl['validation_sha256']='0'*64;save(new.parent.parent/'linux-release.json',dict(private_asset_publication=decl))
|
|
with self.assertRaises(ValueError):package.copy_public_client(new,root/'bad-proof',base,plan_path)
|
|
self.assertFalse((root/'bad-proof').exists())
|
|
|
|
if __name__=='__main__':unittest.main()
|