883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
72 lines
4.2 KiB
Python
72 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
from pathlib import Path
|
|
import hashlib,json,shutil,struct,subprocess,sys,tempfile,unittest
|
|
from unittest.mock import patch
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import warrior_action_bar_ui as w
|
|
|
|
class WarriorUI(unittest.TestCase):
|
|
def test_exact_original_fdid_and_only_warrior_branch_changes(self):
|
|
old,new=w.verified_sources(ROOT)
|
|
self.assertEqual(w.FID,7430847)
|
|
self.assertEqual(hashlib.sha256(old).hexdigest(),w.SOURCE_SHA)
|
|
self.assertEqual(hashlib.sha256(new).hexdigest(),w.PATCH_SHA)
|
|
self.assertEqual(old.count(b'\r\n'),242);self.assertEqual(new.count(b'\r\n'),242)
|
|
self.assertEqual(new,old.replace(w.ORIGINAL_BRANCH.encode(),w.PATCHED_BRANCH.encode(),1))
|
|
|
|
def test_original_and_patched_policy_all_42_cases(self):
|
|
lua=shutil.which('lua');self.assertIsNotNone(lua,'Lua interpreter required for build-time original policy fixture')
|
|
fixture=ROOT/'tests/fixtures/warrior-action-bar/policy-test.lua'
|
|
for filename,mode in [('original-ActionBarController.lua','original'),('ActionBarController.lua','proposed')]:
|
|
result=subprocess.run([lua,str(fixture),str(ROOT/'client_ui/warrior_action_bar'/filename),mode],capture_output=True,text=True,timeout=10)
|
|
self.assertEqual(result.returncode,0,result.stderr)
|
|
|
|
def test_source_and_patch_tamper_rejected(self):
|
|
old,new=w.verified_sources(ROOT)
|
|
for a,b in [(old+b' ',new),(old,new+b' '),(old,new.replace(b'WARRIOR',b'DRUID'))]:
|
|
with self.assertRaises(ValueError):w.validate_patch(a,b)
|
|
|
|
def test_source_symlink_rejected_even_with_exact_bytes(self):
|
|
with tempfile.TemporaryDirectory()as folder:
|
|
root=Path(folder);dest=root/w.SOURCE;dest.parent.mkdir(parents=True);dest.symlink_to(ROOT/w.SOURCE)
|
|
patched=root/w.PATCH;patched.write_bytes((ROOT/w.PATCH).read_bytes())
|
|
with self.assertRaises(ValueError):w.verified_sources(root)
|
|
|
|
def root(self,duplicate=False):
|
|
header=struct.pack('<6I',1296454484,24,2,2,0,0)
|
|
group=struct.pack('<4IB',2,127990,0,301989888,6)
|
|
raw=header+group+struct.pack('<2I',w.FID,99)+bytes.fromhex(w.OLD_CKEY)+bytes.fromhex('ab'*16)
|
|
if duplicate:
|
|
raw=struct.pack('<6I',1296454484,24,2,3,0,0)+raw[24:]+struct.pack('<4IB',1,127990,1,301989888,6)+struct.pack('<I',w.FID)+bytes.fromhex(w.OLD_CKEY)
|
|
return raw
|
|
|
|
def test_root_preserves_ids_group_locale_names_and_all_other_bytes(self):
|
|
old=self.root();key='cd'*16
|
|
with patch.object(w,'OLD_ROOT',hashlib.md5(old).hexdigest()):new,report=w.patch_root(old,key)
|
|
self.assertTrue(report['all_other_root_bytes_identical']);self.assertEqual(report['changed_bytes'],16)
|
|
offset=report['offset'];self.assertEqual(old[:offset],new[:offset]);self.assertEqual(old[offset+16:],new[offset+16:])
|
|
self.assertEqual(w.c.root_controls(new,w.c.root_groups(new),{w.FID})[w.FID][0]['content_key'],key)
|
|
|
|
def test_root_wrong_original_variant_and_duplicate_id_rejected(self):
|
|
for old in [self.root().replace(bytes.fromhex(w.OLD_CKEY),b'x'*16),self.root(True)]:
|
|
with patch.object(w,'OLD_ROOT',hashlib.md5(old).hexdigest()):
|
|
with self.assertRaises(ValueError):w.patch_root(old,'cd'*16)
|
|
with self.assertRaises(ValueError):w.patch_root(self.root(),'cd'*16)
|
|
|
|
def test_fresh_client_rejects_live_source_identity_and_symlink_target(self):
|
|
with tempfile.TemporaryDirectory()as folder:
|
|
root=Path(folder);client=root/'runtime/native-client';client.mkdir(parents=True);(client/'.build.info').write_bytes(b'fixture')
|
|
stage=root/'stage';stage.mkdir();(stage/'manifest.json').write_text('{}')
|
|
with self.assertRaises(ValueError):w.apply_to_fresh_client(root,client,stage,running_check=lambda _:False)
|
|
target=root/'fresh';target.mkdir();(target/'.build.info').write_bytes(b'fixture')
|
|
with self.assertRaises(ValueError):w.apply_to_fresh_client(root,target,stage,running_check=lambda _:True)
|
|
link=root/'link';link.symlink_to(target,target_is_directory=True)
|
|
with self.assertRaises(ValueError):w.apply_to_fresh_client(root,link,stage,running_check=lambda _:False)
|
|
|
|
def test_stage_requires_fresh_destination_before_reading_asset_baseline(self):
|
|
with tempfile.TemporaryDirectory()as folder:
|
|
out=Path(folder)/'present';out.mkdir()
|
|
with self.assertRaises(ValueError):w.stage_ui_assets(ROOT,out)
|
|
|
|
if __name__=='__main__':unittest.main()
|