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

430 lines
35 KiB
Python

"""Isolated packaging contracts: no real client, Wine, account or server access."""
from pathlib import Path
from copy import deepcopy
import hashlib,json,os,shutil,subprocess,sys,tempfile,unittest
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import linux_client_package as p
class LinuxClientPackageTests(unittest.TestCase):
def test_component_exclusions_preserve_unselected_addons_and_missing_talent_is_explicit(self):
from published_client_assets import discard_copied_packaged_addons
client=self.root/'component';base=client/'_classic_beta_/Interface/AddOns'
duplicate=base/'WoWHybridProfessionIcons';duplicate.mkdir(parents=True)
for name in ('WoWHybridProfessionIcons.toc','NativeProfessionBorderData.lua','NativeProfessionIcons.lua'):(duplicate/name).write_text('fixture')
unselected=base/'WoWHybridWarriorStance';unselected.mkdir();(unselected/'preserve.txt').write_text('unchanged unrelated addon')
previous_ui=base/'WoWHybridUI';previous_ui.mkdir()
for name in ('WoWHybridUI.toc','NativeNameplates.lua','NativeProfessionsBook.lua',
'NativeCharacterStats.lua','NativeProfessionBorderData.lua','NativeProfessionIcons.lua'):
(previous_ui/name).write_text('prior owned UI fixture')
with self.assertRaisesRegex(ValueError,'Known distinct packaged addon names required'):
discard_copied_packaged_addons(client,addon_names=('WoWHybridProfessionIcons','UnknownAddon'))
self.assertTrue(duplicate.exists())
discard_copied_packaged_addons(client,addon_names=('WoWHybridProfessionIcons',))
self.assertFalse(duplicate.exists());self.assertEqual((unselected/'preserve.txt').read_text(),'unchanged unrelated addon')
self.assertTrue(previous_ui.exists())
discard_copied_packaged_addons(client,addon_names=('WoWHybridUI',))
self.assertFalse(previous_ui.exists())
source=self.profession_source()
with self.assertRaisesRegex(ValueError,'Required generated talent prerequisite missing: .*TurtleData.lua'):
p.package_profession_icon_addon(source,self.root/'missing-data-output',include_talents=True)
self.assertFalse((self.root/'missing-data-output').exists())
def test_actual_launcher_closure_includes_lifecycle_and_original_popup_helpers(self):
source_root = Path(__file__).resolve().parents[1]
closure = p.ops_closure(source_root)
self.assertIn('ops/native_client_lifecycle.py', closure)
self.assertIn('ops/bootstrap_popup_ack.py', closure)
self.assertNotIn('ops/native_ui_login_test.py', closure)
self.assertNotIn('ops/local_login_input.py', closure)
self.assertNotIn('ops/package_octo_protocol.py', closure)
self.assertNotIn('ops/warrior_action_bar_ui.py', closure)
self.assertNotIn('ops/casc_asset_package.py', closure)
self.assertIn('ops/engine_pipe_host.py', closure)
self.assertTrue(all(path.startswith('ops/') and path.endswith('.py') for path in closure))
def setUp(self):
self.tmp=tempfile.TemporaryDirectory(prefix='Linux bundle spaces ');self.addCleanup(self.tmp.cleanup);self.root=Path(self.tmp.name)
def put(self,relative,data=b'public-fixture'):
q=self.root/relative;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes(data);return q
def template(self):
return dict(wire_unix_library={key:value for role,relative in p.MODULES.items()for key,value in[(role+'_path',relative),(role+'_sha256','a'*64)]},dll_sha256='b'*64)
def fake_cp(self,cmd,**kwargs):
self.assertIsInstance(cmd,list);self.assertIn('--reflink=always',cmd);self.assertIn('--',cmd);self.assertNotIn('shell',kwargs)
source,target=map(Path,cmd[-2:])
if '--recursive'in cmd:shutil.copytree(source,target)
else:shutil.copy2(source,target)
def test_config_copies_only_reviewed_display_fields(self):
raw='SET accountName "PRIVATE-ACCOUNT"\nSET savedAccountName "PRIVATE"\nSET password "NEVER-COPY"\nSET portal "foreign.example"\nSET gxWindowedResolution "2560x1440"\nSET gxApi "OpenGL"\nSET lastSelectedRealm "PRIVATE-REALM"\n'
out=p.safe_config(raw);self.assertIn('"2560x1440"',out);self.assertIn('SET portal "127.0.0.1"',out);self.assertIn('SET gxApi "D3D11"',out)
self.assertIn('SET GxMaximize "1"',out)
client=self.root/'client';(client/'_classic_beta_/WTF').mkdir(parents=True);(client/'_classic_beta_/WTF/Config.wtf').write_text(out)
from client_installation import window_arguments
self.assertEqual(window_arguments(client),[])
for value in('PRIVATE','NEVER-COPY','foreign.example','accountName','password','OpenGL'):self.assertNotIn(value,out)
def test_ambiguous_or_control_config_values_are_not_retained(self):
out=p.safe_config('SET gxResolution "1920x1080"\nSET gxResolution "800x600"\nSET uiScale "0.5;command"\n')
self.assertNotIn('gxResolution',out);self.assertNotIn('uiScale',out)
def test_client_subset_omits_account_logs_caches_and_old_profiles(self):
source=self.root/'source';source.mkdir()
for relative in(*p.PRODUCT_FILES,*('_classic_beta_/'+n for n in p.GAME_FILES)):
f=source/relative;f.parent.mkdir(parents=True,exist_ok=True);f.write_bytes(b'public')
for name in p.DATA_TREES:
f=source/'Data'/name/'public.content';f.parent.mkdir(parents=True,exist_ok=True);f.write_bytes(b'content')
for name in('.battle.net/account','compat/launcher.json','_classic_beta_/WTF/Account/PRIVATE/saved.lua','_classic_beta_/Cache/private','_classic_beta_/Logs/private.log','_classic_beta_/Screenshots/private.png','Data/ecache/private'):
f=source/name;f.parent.mkdir(parents=True,exist_ok=True);f.write_bytes(b'PRIVATE')
(source/'_classic_beta_/WTF/Config.wtf').write_text('SET accountName "PRIVATE"\nSET gxWindowedResolution "1920x1080"\n')
target=self.root/'target'
with patch.object(p.subprocess,'run',side_effect=self.fake_cp):p.copy_client_subset(source,target)
self.assertFalse((target/'.battle.net').exists());self.assertFalse((target/'compat').exists());self.assertFalse((target/'Data/ecache').exists())
for relative in('Account','Logs','Cache','Screenshots'):self.assertFalse((target/'_classic_beta_'/relative).exists())
self.assertEqual([q.name for q in(target/'_classic_beta_/WTF').iterdir()],['Config.wtf'])
self.assertNotIn('PRIVATE',(target/'_classic_beta_/WTF/Config.wtf').read_text())
self.assertEqual((source/'_classic_beta_/WTF/Account/PRIVATE/saved.lua').read_bytes(),b'PRIVATE')
def test_tree_link_rejected_before_copy(self):
source=self.root/'tree';source.mkdir();(source/'escape').symlink_to('/tmp')
with patch.object(p.subprocess,'run')as run:
with self.assertRaisesRegex(ValueError,'link rejected'):p.copy_tree(source,self.root/'new')
run.assert_not_called()
def test_existing_or_linked_destination_is_preserved(self):
source=self.put('source',b'public');external=self.put('external',b'PRIVATE');target=self.root/'link';target.symlink_to(external)
with self.assertRaisesRegex(ValueError,'preserved'):p.copy_file(source,target)
self.assertEqual(external.read_bytes(),b'PRIVATE')
def test_rebased_journal_moves_with_bundle(self):
template=self.template();a=p.rebased_journal(template,self.root/'first');b=p.rebased_journal(template,self.root/'moved')
for role,relative in p.MODULES.items():self.assertEqual(b['wire_unix_library'][role+'_path'],str(self.root/'moved'/relative))
self.assertNotEqual(a,b);self.assertEqual(template['wire_unix_library']['core_path'],'build/libgateway_native.so')
template['wire_unix_library']['core_path']='/external/lib.so'
with self.assertRaisesRegex(ValueError,'fixed relative'):p.rebased_journal(template,self.root)
def test_relative_launcher_profile_and_backend_hash(self):
self.put('ops/forever_launcher_backend.py');profile=p.launcher_profile(self.root)
self.assertEqual(profile['runtime_root'],'..');self.assertEqual(profile['platforms']['linux']['python'],'python3');self.assertNotIn(str(self.root),json.dumps(profile))
def prepared_bundle(self):
self.put('ops/runtime.py',b'public');self.put('compat/native-engine-template.json',json.dumps(self.template()).encode());manifest=dict(kind='linux-forever-client-folder-package-v1',runtime_file_sha256={relative:p.sha(self.root/relative)for relative in('ops/runtime.py','compat/native-engine-template.json')});self.put('linux-release.json',json.dumps(manifest).encode())
def test_runtime_rebinding_and_check_only_no_writes(self):
self.prepared_bundle();before=p.prepare_runtime(self.root,check_only=True,check_prerequisites=False);self.assertTrue(before['journal_rebase_needed']);self.assertFalse((self.root/'runtime/native-engine-pe.json').exists())
with patch.object(p,'client_running',return_value=False):p.prepare_runtime(self.root,check_prerequisites=False)
self.assertEqual(p.read_json(self.root/'runtime/native-engine-pe.json'),p.rebased_journal(self.template(),self.root))
def test_active_client_prevents_changed_journal_rebinding(self):
self.prepared_bundle()
with patch.object(p,'client_running',return_value=True):
with self.assertRaisesRegex(ValueError,'Close bundle client'):p.prepare_runtime(self.root,check_prerequisites=False)
self.assertFalse((self.root/'runtime/native-engine-pe.json').exists())
def test_changed_runtime_fails_before_journal_publication(self):
self.prepared_bundle();(self.root/'ops/runtime.py').write_bytes(b'changed')
with self.assertRaisesRegex(ValueError,'identity differs'):p.prepare_runtime(self.root,check_prerequisites=False)
self.assertFalse((self.root/'runtime/native-engine-pe.json').exists())
def test_stage_refuses_existing_output_or_live_source_before_copy(self):
out=self.root/'existing';out.mkdir()
with self.assertRaisesRegex(ValueError,'existing output preserved'):p.stage(self.root,out,self.root,check_prerequisites=False)
with patch.object(p,'client_running',return_value=True),patch.object(p,'verified_bindings')as verify:
with self.assertRaisesRegex(ValueError,'Close source private client'):p.stage(self.root,self.root/'new',self.root,check_prerequisites=False)
verify.assert_not_called();self.assertFalse((self.root/'new').exists())
def test_fresh_prefix_dll_replacement_never_follows_builtin_symlink(self):
system=self.root/'prefix/drive_c/windows/system32';system.mkdir(parents=True);external=self.put('host-wine.dll',b'HOST-BUILTIN');(system/'d3d11.dll').symlink_to(external)
source=self.put('source/runtime/native-wine-prefix/drive_c/windows/system32/d3d11.dll',b'OWNED-NATIVE')
with patch.object(p.subprocess,'run')as run:p.install_prefix_dlls(self.root/'source',self.root/'prefix',{'d3d11.dll':p.sha(source)},{'WINEPREFIX':str(self.root/'prefix')})
self.assertFalse((system/'d3d11.dll').is_symlink());self.assertEqual((system/'d3d11.dll').read_bytes(),b'OWNED-NATIVE');self.assertEqual(external.read_bytes(),b'HOST-BUILTIN');self.assertEqual(run.call_count,3)
def test_prefix_system_directory_cannot_escape(self):
outside=self.root/'outside';outside.mkdir();(self.root/'prefix/drive_c/windows').mkdir(parents=True);(self.root/'prefix/drive_c/windows/system32').symlink_to(outside,target_is_directory=True)
with self.assertRaisesRegex(ValueError,'escaped'):p.install_prefix_dlls(self.root,self.root/'prefix',{}, {})
def test_public_dx12_prefix_uses_only_explicit_bundle_files_and_overrides(self):
system=self.root/'prefix/drive_c/windows/system32';system.mkdir(parents=True)
names=('d3d12.dll','d3d12core.dll','dxgi.dll','GWNativeBridge.dll','GWNativeWire.dll')
sources={name:self.put('public-bundle/'+name,('public-'+name).encode())for name in names}
hashes={name:p.sha(path)for name,path in sources.items()}
with patch.object(p.subprocess,'run')as run:
p.install_prefix_dlls(self.root/'missing-local-source',self.root/'prefix',hashes,
{'WINEPREFIX':str(self.root/'prefix')},public_sources=sources,
overrides=('d3d12','d3d12core','dxgi'))
self.assertEqual({x.name for x in system.iterdir()},set(names))
self.assertTrue(all(p.sha(system/name)==hashes[name]for name in names))
registry=[call.args[0]for call in run.call_args_list if call.args[0][:3]==['wine','reg','add']]
self.assertEqual([cmd[cmd.index('/v')+1]for cmd in registry],['d3d12','d3d12core','dxgi'])
self.assertEqual(json.loads((self.root/'prefix/gateway-private-prefix.json').read_text())['native_dlls'],hashes)
def test_public_dx12_config_changes_only_renderer(self):
source='SET accountName "NEVER-COPY"\nSET gxApi "OpenGL"\nSET gxWindowedResolution "2560x1440"\n'
old=p.safe_config(source);new=p.safe_config(source,renderer='D3D12')
self.assertEqual(old.replace('SET gxApi "D3D11"','SET gxApi "D3D12"'),new)
self.assertNotIn('accountName',new)
with self.assertRaisesRegex(ValueError,'Unreviewed release renderer'):
p.safe_config(source,renderer='OpenGL')
def test_public_dx12_runtime_checks_bootstrap_without_legacy_journal(self):
root=self.root/'public-release';image=self.put('public-release/runtime/native-client/_classic_beta_/WowB.exe',b'owned-client-image')
bootstrap=root/'runtime/native-dx12-bootstrap.json'
record=dict(kind='native-inprocess-dx12-v1',source_profile=2,
public_authentication_tested=False,
runtime_file_sha256={'runtime/native-client/_classic_beta_/WowB.exe':p.sha(image)})
bootstrap.write_text(json.dumps(record))
(root/'linux-release.json').write_text(json.dumps(dict(
kind='linux-forever-client-folder-package-v1',dx12_public_bundle={'profile':2},
runtime_file_sha256={'runtime/native-dx12-bootstrap.json':p.sha(bootstrap)})))
result=p.prepare_runtime(root,check_only=True,check_prerequisites=False)
self.assertTrue(result['direct_inprocess_dx12'])
self.assertFalse((root/'runtime/native-engine-pe.json').exists())
image.write_bytes(b'tampered-client-image')
with self.assertRaisesRegex(ValueError,'Public DX12 direct launch identity differs'):
p.prepare_runtime(root,check_only=True,check_prerequisites=False)
def test_public_dx12_launcher_rejects_local_profile_before_process_start(self):
root=self.root/'profile-guard';bootstrap=self.put('profile-guard/runtime/native-dx12-bootstrap.json',
json.dumps(dict(kind='native-inprocess-dx12-v1',source_profile=5,
public_authentication_tested=False)).encode())
(root/'linux-release.json').write_text(json.dumps(dict(
kind='linux-forever-client-folder-package-v1',dx12_public_bundle={'profile':2},
runtime_file_sha256={'runtime/native-dx12-bootstrap.json':p.sha(bootstrap)})))
with self.assertRaisesRegex(ValueError,'Public DX12 profile-2 release receipt differs'):
p.launch_inprocess(root)
def test_python_closure_includes_fixed_dynamic_profile_without_other_files(self):
self.put('ops/a.py',b'import b\nPROFILES={"fixed":("engine_test","public")}\n');self.put('ops/b.py',b'from a import PROFILES\n');self.put('ops/engine_test.py',b'import json\n');self.put('ops/private.json',b'PRIVATE')
with patch.object(p,'SEEDS',('a',)):self.assertEqual(p.ops_closure(self.root),['ops/a.py','ops/b.py','ops/engine_test.py'])
def test_real_realm_memory_import_is_copied_and_manifest_bound_in_fresh_stage(self):
# Exercise the production stage/closure/manifest path with tiny public files;
# real client content, Wine, account stores and ELF loading are never used.
source=self.root/'source';source.mkdir();project=Path(__file__).resolve().parents[1]
closure=p.ops_closure(project);self.assertIn('ops/launcher_realm_preference.py',closure);self.assertIn('ops/launcher_trace_journal.py',closure)
for relative in closure+['launcher/launcher.py']:
q=source/relative;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes((project/relative).read_bytes())
for relative in[*p.MODULES.values(),'build/native-ptrace-abi',*p.PROOFS,*p.FIXED_CODE_DATA]:
q=source/relative;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes(b'public-test-fixture')
protocol=self.root/'protocol';protocol.mkdir();(protocol/'version-hash.bin').write_bytes(b'v'*20);(protocol/'addon-tail.bin').write_bytes(b'a'*28)
identity=dict(files={'_classic_beta_/WowB.exe':dict(sha256=p.EXE_SHA)},build_key='public-fixture')
dlls={name:hashlib.sha256(b'public-dll').hexdigest()for name in('d3d11.dll','dxgi.dll','GWNativeBridge.dll','GWNativeWire.dll')}
def subset(client,target,*,compacted_content=None):target.mkdir(parents=True);return {},{}
def prefix(path):path.mkdir(parents=True);return {}
def install(root,prefix,dlls,env):
system=prefix/'drive_c/windows/system32';system.mkdir(parents=True)
for name in dlls:(system/name).write_bytes(b'public-dll')
def warrior_ui(source_root,client_target,asset_output,*,compacted_content=None):
report=client_target/'warrior-action-bar-casc.json';report.write_text('{"synthetic_integration_fixture":true}')
return dict(kind='original-controller-warrior-stance-page-policy-v1',file_data_id=7430847,native_engine_acceptance_verified=False,new_build_config='b'*32,files={'runtime/native-client/warrior-action-bar-casc.json':hashlib.sha256(report.read_bytes()).hexdigest()})
target=self.root/'bundle'
with patch.object(p,'package_warrior_action_bar',side_effect=warrior_ui),patch.object(p,'client_running',return_value=False),patch.object(p,'source_git_revision',return_value='a'*40),patch.object(p,'verified_bindings',return_value=(self.template(),dlls)),patch.object(p,'elf_requirements',return_value={'libc.so.6':['GLIBC_2.43']}),patch.object(p,'lifecycle_pages',return_value=[]),patch.object(p,'copy_client_subset',side_effect=subset),patch.object(p,'install_prefix_dlls',side_effect=install),patch('client_installation.inspect_installation',return_value=identity),patch('ui_release_guard.verify_ui_lineage',return_value={'synthetic_fixture':True}):
icon_folder=source/'client_addons/WoWHybridUI';icon_folder.mkdir(parents=True)
canonical_addon=project/'client_addons/WoWHybridUI'
for original in [canonical_addon/'WoWHybridUI.toc',*canonical_addon.glob('*.lua')]:
shutil.copyfile(original,icon_folder/original.name)
self.accepted_ui_fixture(project,source)
for name in ('TurtleTalentProvider.lua','TurtleTalents.lua'):
q=source/'client_addons/GatewayDiagnostics'/name;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes((project/'client_addons/GatewayDiagnostics'/name).read_bytes())
talent_data=source/'build/turtle-data/TurtleData.lua';talent_data.parent.mkdir(parents=True);talent_data.write_text('GatewayTurtleData={tabs={},talents={}}\n')
for name in ('WoWHybridWarriorStance.toc','SourcePolicies.lua','WarriorStance.lua'):
q=source/'client_addons/WoWHybridWarriorStance'/name;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes((project/'client_addons/WoWHybridWarriorStance'/name).read_bytes())
manifest=p.stage(source,target,protocol,prefix_initializer=prefix,check_prerequisites=False)
self.assertTrue(manifest['profession_icon_addon']['talents_included'])
self.assertEqual(len(manifest['profession_icon_addon']['files']),len(manifest['profession_icon_addon']['load_order'])+1)
load_order=manifest['profession_icon_addon']['load_order']
talent_names=['TurtleData.lua','TurtleTalentProvider.lua','TurtleTalents.lua']
self.assertEqual([name for name in load_order if name in talent_names],talent_names)
self.assertTrue(manifest['profession_icon_addon']['talents_included'])
self.assertEqual(manifest['profession_icon_addon']['native_dependencies'],['Blizzard_SharedTalentUI'])
for omitted in ('ops/native_ui_login_test.py','ops/local_login_input.py',
'ops/package_octo_protocol.py','ops/warrior_action_bar_ui.py','ops/casc_asset_package.py'):
self.assertFalse((target/omitted).exists())
self.assertNotIn(omitted,manifest['runtime_file_sha256'])
frontend=p.frontend(target)
command,launch_root=frontend.launch_plan(target/'compat/launcher.json','octo',system='Linux')
self.assertEqual(launch_root,target.resolve())
self.assertEqual(Path(command[2]),target/'ops/forever_launcher_backend.py')
self.assertEqual(manifest['warrior_action_bar']['file_data_id'],7430847)
self.assertFalse(manifest['warrior_action_bar']['native_engine_acceptance_verified'])
self.assertEqual(manifest['runtime_file_sha256']['runtime/native-client/warrior-action-bar-casc.json'],manifest['warrior_action_bar']['files']['runtime/native-client/warrior-action-bar-casc.json'])
for icon_name,icon_sha in manifest['profession_icon_addon']['files'].items():
self.assertEqual(manifest['runtime_file_sha256']['runtime/native-client/'+icon_name],icon_sha)
self.assertNotIn('issue_reporter_addon',manifest)
self.assertFalse((target/'runtime/native-client/_classic_beta_/Interface/AddOns/WoWHybridIssueReporter').exists())
helper='ops/launcher_trace_journal.py';self.assertEqual((target/helper).read_bytes(),(project/helper).read_bytes());self.assertEqual(manifest['runtime_file_sha256'][helper],p.sha(project/helper))
(target/helper).write_text('changed journal dependency')
with self.assertRaisesRegex(ValueError,'identity differs'):p.prepare_runtime(target,check_only=True,check_prerequisites=False)
(target/helper).unlink()
with self.assertRaises((ValueError,FileNotFoundError)):p.prepare_runtime(target,check_only=True,check_prerequisites=False)
(target/helper).write_bytes((project/helper).read_bytes())
relative='ops/launcher_realm_preference.py';self.assertEqual((target/relative).read_bytes(),(project/relative).read_bytes());self.assertEqual(manifest['runtime_file_sha256'][relative],p.sha(project/relative))
self.assertTrue(p.prepare_runtime(target,check_only=True,check_prerequisites=False)['ready'])
(target/relative).write_text('changed dependency')
with self.assertRaisesRegex(ValueError,'identity differs'):p.prepare_runtime(target,check_only=True,check_prerequisites=False)
def test_source_git_revision_is_stage_only_fixed_command_and_validated(self):
from types import SimpleNamespace
with patch.object(p.subprocess,'run',return_value=SimpleNamespace(stdout='a'*40+'\n'))as run:
self.assertEqual(p.source_git_revision(self.root),'a'*40)
self.assertEqual(run.call_args.args[0],['git','rev-parse','HEAD']);self.assertEqual(run.call_args.kwargs['cwd'],self.root)
with patch.object(p.subprocess,'run',return_value=SimpleNamespace(stdout='unknown\n')):
with self.assertRaisesRegex(ValueError,'Exact source Git revision'):p.source_git_revision(self.root)
def test_runtime_prerequisites_require_readiness_dialog_and_allow_qdbus_fallback(self):
from types import SimpleNamespace
def which(name):return None if name=='qdbus6'else '/usr/bin/'+name
def run(command,**kwargs):return SimpleNamespace(stdout=json.dumps({name:True for name in p.PYTHON_MODULES})if '-c'in command else 'wine-fixture\n')
with patch.object(p.shutil,'which',side_effect=which),patch.object(p.subprocess,'run',side_effect=run):
self.assertEqual(p.prerequisites()['readiness_dbus_program'],'qdbus')
def missing(name):return None if name in('kdialog','qdbus6','qdbus')else '/usr/bin/'+name
with patch.object(p.shutil,'which',side_effect=missing),patch.object(p.subprocess,'run',side_effect=run):
with self.assertRaisesRegex(ValueError,'kdialog, qdbus6 or qdbus'):p.prerequisites()
def test_elf_abi_requirements_only_take_version_needs(self):
from types import SimpleNamespace
text="Version definition section '.gnu.version_d' contains1entry:\n Name: DO_NOT_USE\nVersion needs section '.gnu.version_r' contains2entries:\n 0x0: Version:1 File: libc.so.6 Cnt:2\n 0x0: Name: GLIBC_2.43 Flags:none Version:3\n 0x0: Name: GLIBC_2.38 Flags:none Version:4\n 0x1: Version:1 File: libstdc++.so.6 Cnt:1\n 0x0: Name: GLIBCXX_3.4.32 Flags:none Version:5\n"
with patch.object(p.subprocess,'run',return_value=SimpleNamespace(stdout=text)):
self.assertEqual(p.elf_requirements(self.root/'module.so'),{'libc.so.6':['GLIBC_2.38','GLIBC_2.43'],'libstdc++.so.6':['GLIBCXX_3.4.32']})
def test_elf_loader_failure_blocks_without_wine_or_diagnostics_dump(self):
from types import SimpleNamespace
with patch.object(p.subprocess,'run',return_value=SimpleNamespace(returncode=1,stderr='private-path'))as run:
with self.assertRaisesRegex(ValueError,'ELF ABI dependencies'):p.validate_elf_loader(self.root)
self.assertNotIn('wine',run.call_args.args[0]);self.assertIn('-c',run.call_args.args[0])
def test_doubleclick_failure_uses_launcher_os_dialog(self):
from types import SimpleNamespace
from unittest.mock import Mock
launcher=SimpleNamespace(notify_error=Mock())
with patch.object(sys,'argv',['package','--launch-root',str(self.root)]),patch.object(p,'frontend',return_value=launcher),patch.object(p,'prepare_runtime',side_effect=ValueError('missing prerequisite')):
self.assertEqual(p.main(),2)
launcher.notify_error.assert_called_once_with('Linux client startup stopped: missing prerequisite')
def profession_source(self,canonical_talents=False):
source=self.root/'icon-source';folder=source/'client_addons/WoWHybridUI';folder.mkdir(parents=True)
project=Path(__file__).resolve().parents[1]/'client_addons/WoWHybridUI'
for item in project.iterdir():
if item.is_file():(folder/item.name).write_bytes(item.read_bytes())
if not canonical_talents:
# Explicit older base without built-in talents exercises optional closure.
toc=folder/'WoWHybridUI.toc'
excluded={'TurtleData.lua','TurtleTalentProvider.lua','TurtleTalents.lua','## Dependencies: Blizzard_SharedTalentUI'}
toc.write_text('\n'.join(line for line in toc.read_text().splitlines() if line not in excluded)+'\n')
self.accepted_ui_fixture(project.parents[1],source)
return source
def test_canonical_talents_preserved_once_with_truthful_component_receipt(self):
source=self.profession_source(canonical_talents=True)
toc=(source/'client_addons/WoWHybridUI/WoWHybridUI.toc').read_bytes()
for selected in (False,True):
target=self.root/('canonical-'+str(selected))
result=p.package_profession_icon_addon(source,target,include_talents=selected)
folder=target/'_classic_beta_/Interface/AddOns/WoWHybridUI'
self.assertEqual((folder/'WoWHybridUI.toc').read_bytes(),toc)
self.assertTrue(result['talents_included'])
self.assertEqual(result['native_dependencies'],['Blizzard_SharedTalentUI'])
for name in ('TurtleData.lua','TurtleTalentProvider.lua','TurtleTalents.lua'):
self.assertEqual(result['load_order'].count(name),1)
self.assertEqual((folder/name).read_bytes(),(source/'client_addons/WoWHybridUI'/name).read_bytes())
def test_partial_or_unordered_canonical_talents_rejected_before_writes(self):
source=self.profession_source(canonical_talents=True)
toc=source/'client_addons/WoWHybridUI/WoWHybridUI.toc';normal=toc.read_text()
for changed in (normal.replace('TurtleData.lua\n',''),
normal.replace('## Dependencies: Blizzard_SharedTalentUI\n',''),
normal.replace('TurtleData.lua\nTurtleTalentProvider.lua','TurtleTalentProvider.lua\nTurtleData.lua')):
toc.write_text(changed)
with self.assertRaisesRegex(ValueError,'canonical talent'):
p.package_profession_icon_addon(source,self.root/'rejected',include_talents=True)
self.assertFalse((self.root/'rejected').exists())
def accepted_ui_fixture(self,project,source):
# The portable base owns the verified generated weapon table; the provider is source-controlled.
diagnostics=source/'client_addons/GatewayDiagnostics';diagnostics.mkdir(parents=True,exist_ok=True)
provider=project/'client_addons/GatewayDiagnostics/SourceWeaponDamage.lua'
shutil.copyfile(provider,diagnostics/provider.name)
self.ui_base=self.root/'builds/Forever-Base-20261118'
base=self.ui_base
addon=base/'native-client/_classic_beta_/Interface/AddOns/WoWHybridUI';addon.mkdir(parents=True)
shutil.copyfile(provider,addon/provider.name)
data=addon/'SourceWeaponDamageData.lua';data.write_text('GatewaySourceWeaponDamageData = {}\n')
(base/'base-manifest.json').write_text(json.dumps(dict(source_weapon_presentation=dict(
provider_sha256=p.sha(provider),data_sha256=p.sha(data)))))
def test_profession_overlay_exact_load_order_and_integrity(self):
source=self.profession_source();target=self.root/'new-client';result=p.package_profession_icon_addon(source,target)
folder=target/'_classic_beta_/Interface/AddOns/WoWHybridUI'
entries=[line for line in (folder/'WoWHybridUI.toc').read_text().splitlines() if line and not line.startswith('##')]
self.assertEqual(entries,result['load_order'])
self.assertLess(entries.index('NativeBagSlots.lua'),entries.index('NativeMountJournal.lua'))
self.assertLess(entries.index('NativeMountJournal.lua'),entries.index('NativeBarberShop.lua'))
self.assertLess(entries.index('SourceWeaponDamageData.lua'), entries.index('SourceWeaponDamage.lua'))
self.assertNotIn('WoWHybridUI.toc.bak-20261116', {f.name for f in folder.iterdir()})
self.assertFalse((folder.parent/'WoWHybridProfessionIcons').exists())
self.assertEqual(len(result['files']),len(entries)+1)
for name,digest in result['files'].items():self.assertEqual(p.sha(target/name),digest)
self.assertEqual(result['exact_border_override_scope'],'white');self.assertFalse(result['nonwhite_live_acceptance_verified'])
def test_current_ui_copy_is_refreshed_only_after_generated_data_verification(self):
source=self.profession_source();target=self.root/'release'
p.package_profession_icon_addon(source,target)
existing=target/'_classic_beta_/Interface/AddOns/WoWHybridUI/NativeBagSlots.lua'
existing.write_bytes(b'old packaged module')
dataset=self.ui_base/'native-client/_classic_beta_/Interface/AddOns/WoWHybridUI/SourceWeaponDamageData.lua'
accepted=dataset.read_bytes();dataset.write_bytes(b'wrong generated module')
with self.assertRaisesRegex(ValueError,'dependency bytes differ'):
p.package_profession_icon_addon(source,target,discard_copied=True)
self.assertEqual(existing.read_bytes(),b'old packaged module')
dataset.write_bytes(accepted)
p.package_profession_icon_addon(source,target,discard_copied=True)
self.assertEqual(existing.read_bytes(),(source/'client_addons/WoWHybridUI/NativeBagSlots.lua').read_bytes())
self.assertEqual((existing.parent/dataset.name).read_bytes(),accepted)
def test_historical_addon_needs_no_portable_weapon_base(self):
source=self.profession_source();folder=source/'client_addons/WoWHybridUI'
toc=folder/'WoWHybridUI.toc';toc.write_text('NativeNameplates.lua\n')
missing=self.root/'nonexistent-ui-base'
self.assertEqual(p.package_profession_icon_addon(source,self.root/'legacy',ui_base=missing)['load_order'],['NativeNameplates.lua'])
for name in ('SourceWeaponDamageData.lua','SourceWeaponDamage.lua'):
toc.write_text('NativeNameplates.lua\n'+name+'\n')
with self.assertRaisesRegex(ValueError,'Incomplete Source weapon'):
p.package_profession_icon_addon(source,self.root/'incomplete',ui_base=missing)
self.assertFalse((self.root/'incomplete').exists())
def test_talent_dataset_uses_selected_base_file_when_no_generated_copy_exists(self):
source=self.profession_source()
for name in ('TurtleTalentProvider.lua','TurtleTalents.lua'):
(source/'client_addons/GatewayDiagnostics'/name).write_bytes(b'-- talent provider')
relative='native-client/_classic_beta_/Interface/AddOns/WoWHybridUI/TurtleData.lua'
dataset=self.ui_base/relative;dataset.write_text('GatewayTurtleData = {}\n')
manifest=self.ui_base/'base-manifest.json'
contents=json.loads(manifest.read_text())
contents['selected_files']=[dict(path=relative,sha256=p.sha(dataset))]
manifest.write_text(json.dumps(contents))
target=self.root/'talents';report=p.package_profession_icon_addon(source,target,include_talents=True)
self.assertEqual(report['files'][relative.removeprefix('native-client/')],p.sha(dataset))
dataset.write_bytes(b'wrong')
with self.assertRaisesRegex(ValueError,'talent prerequisite differs'):
p.package_profession_icon_addon(source,self.root/'rejected',include_talents=True)
self.assertFalse((self.root/'rejected').exists())
def test_toc_additions_ship_and_nonlocal_or_duplicate_entries_fail_before_writes(self):
source=self.profession_source();folder=source/'client_addons/WoWHybridUI';toc=folder/'WoWHybridUI.toc'
target=self.root/'release';p.package_profession_icon_addon(source,target)
normal=toc.read_text()+'NewUiControl.lua\n';toc.write_text(normal);(folder/'NewUiControl.lua').write_bytes(b'-- NEW')
result=p.package_profession_icon_addon(source,target,discard_copied=True)
self.assertEqual(result['load_order'][-1],'NewUiControl.lua')
for bad in ('../outside.lua','NewUiControl.lua'):
with self.subTest(entry=bad):
toc.write_text(normal+bad+'\n')
with self.assertRaisesRegex(ValueError,'distinct local Lua filenames'):
p.package_profession_icon_addon(source,self.root/'rejected',discard_copied=True)
self.assertFalse((self.root/'rejected').exists())
def test_profession_overlay_existing_canonical_reused(self):
source=self.profession_source();target=self.root/'new-client';p.package_profession_icon_addon(source,target)
self.assertEqual(p.package_profession_icon_addon(source,target)['addon'],'WoWHybridUI')
legacy=target/'_classic_beta_/Interface/AddOns/WoWHybridProfessionIcons';legacy.mkdir()
with self.assertRaisesRegex(ValueError,'Duplicate profession icon addon'):p.package_profession_icon_addon(source,target)
def test_canonical_ui_talent_component_closure_and_rejection_namespace(self):
source=self.profession_source();project=Path(__file__).resolve().parents[1]
modules=source/'client_addons/GatewayDiagnostics';modules.mkdir(exist_ok=True)
for name in ('TurtleTalentProvider.lua','TurtleTalents.lua'):
(modules/name).write_bytes((project/'client_addons/GatewayDiagnostics'/name).read_bytes())
data=source/'build/turtle-data/TurtleData.lua';data.parent.mkdir(parents=True)
data.write_text('GatewayTurtleData={tabs={},talents={}}\n')
target=self.root/'talent-component';result=p.package_profession_icon_addon(source,target,include_talents=True)
folder=target/'_classic_beta_/Interface/AddOns/WoWHybridUI'
self.assertEqual(result['load_order'][-3:],['TurtleData.lua','TurtleTalentProvider.lua','TurtleTalents.lua'])
self.assertEqual(len(result['files']),len(result['load_order'])+1);self.assertTrue(result['talents_included'])
self.assertEqual(result['native_dependencies'],['Blizzard_SharedTalentUI'])
self.assertIn('## Dependencies: Blizzard_SharedTalentUI',(folder/'WoWHybridUI.toc').read_text())
self.assertEqual(set(result['load_order']),{x.name for x in folder.iterdir()if x.suffix=='.lua'})
for relative,digest in result['files'].items():self.assertEqual(p.sha(target/relative),digest)
for name in ('GatewayDiagnostics','WoWHybridProfessionIcons','WoWHybridIssueReporter'):
self.assertFalse((folder.parent/name).exists())
for addon,event in [('WoWHybridUI','ADDON_ACTION_BLOCKED'),(None,'ADDON_ACTION_FORBIDDEN')]:
script='GW_TALENT_ADDON_BOUNDARY_ONLY=true;GW_TALENT_COMPONENT_DIRECTORY='+json.dumps(str(folder))
if addon:script+=';GW_TALENT_ADDON_NAME='+json.dumps(addon)
script+=';GW_TALENT_BLOCKED_EVENT='+json.dumps(event)+";dofile('tests/turtle_talents_inspect_context_test.lua')"
checked=subprocess.run(['lua','-e',script],cwd=project,capture_output=True,text=True)
self.assertEqual(checked.returncode,0,checked.stdout+checked.stderr)
data.unlink()
with self.assertRaises((ValueError,FileNotFoundError)):
p.package_profession_icon_addon(source,self.root/'missing-talent-data',include_talents=True)
def test_profession_overlay_source_symlink_refused(self):
source=self.profession_source();f=source/'client_addons/WoWHybridUI/NativeProfessionIcons.lua';f.unlink();other=self.root/'other.lua';other.write_text('unexpected');f.symlink_to(other)
with self.assertRaises(ValueError):p.package_profession_icon_addon(source,self.root/'new-client')
def test_profession_overlay_target_symlink_refused(self):
source=self.profession_source();target=self.root/'new-client';target.mkdir();other=self.root/'elsewhere';other.mkdir();(target/'_classic_beta_').symlink_to(other,target_is_directory=True)
with self.assertRaises(ValueError):p.package_profession_icon_addon(source,target)
if __name__=='__main__':unittest.main()