Files
ft/CodexOutput/upserver/KVGameplayLoopTests/audit_changes.py

28 lines
2.0 KiB
Python

from pathlib import Path
import json,hashlib,difflib
root=Path(__file__).resolve().parents[3]
folder=Path(__file__).resolve().parent
baseline=json.loads((folder/'checkpoint0-baseline.json').read_text(encoding='utf-8-sig'))
changes=[]
for item in baseline['files']:
p=root/item['path']
digest=hashlib.sha256(p.read_bytes()).hexdigest().upper()
if digest!=item['sha256']:
before=folder/'before'/(item['path'].replace('/','__').replace('\\','__')+'.txt')
if item['path'].startswith('Client/'):
assert before.exists(),before
old=before.read_text(encoding='utf-8-sig').splitlines(); new=p.read_text(encoding='utf-8-sig').splitlines()
diff=list(difflib.unified_diff(old,new,fromfile=item['path']+' (reviewed baseline)',tofile=item['path']))
(folder/('diff-'+p.name+'.txt')).write_text('\n'.join(diff)+'\n',encoding='utf-8')
changes.append(dict(path=item['path'],before=item['sha256'],after=digest,added=sum(s.startswith('+') and not s.startswith('+++') for s in diff),removed=sum(s.startswith('-') and not s.startswith('---') for s in diff)))
pf='Client/Assets/Scripts/Core/PlayFabMgr.cs'
before=(folder/'before'/(pf.replace('/','__')+'.txt')).read_bytes()
after=(root/pf).read_bytes()
key=b' internal static PlayerKVKeyReadResult ReadKV('
assert before[before.index(key):]==after[after.index(key):],'B3A four fixed entries changed'
newpaths=['Client/Assets/Scripts/Services/UserService.KVGameplayLoop.cs','Client/Assets/Scripts/Services/PlayerData/PlayerKVGameplayBindings.cs','Client/Assets/Editor/KVGameplayLoopSetup.cs']
newfiles=[dict(path=p,sha256=hashlib.sha256((root/p).read_bytes()).hexdigest().upper()) for f in newpaths for p in (f,f+'.meta')]
out=dict(changedExistingSources=changes,newFiles=newfiles,B3AFixedEntriesByteIdentical=True,gameplayEnabled=False)
(folder/'checkpoint2-source-audit.json').write_text(json.dumps(out,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(json.dumps(out,ensure_ascii=False,indent=2))