Files
2026-11-23 03:28:32 +02:00

117 lines
6.9 KiB
Python

"""WMO outdoor stage: apply and undo on a reflink snapshot of the LOCAL client store (= Codex 95474c0a parent)."""
from pathlib import Path
from tempfile import TemporaryDirectory
import hashlib
import json
import os
import sys
import importlib.util
here = Path(__file__).resolve().parent
CODEX=Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/codex')
sys.path.insert(0, str(CODEX))
from casc_stage_inverse import restore_parent_indices
parent_dir = CODEX / 'post-431f-content-20261121'
sys.path.insert(0, str(parent_dir))
helper = importlib.util.spec_from_file_location('prior_rehearsal', parent_dir/'rehearse.py')
h = importlib.util.module_from_spec(helper)
helper.loader.exec_module(h)
grand = parent_dir/'candidate'
helm = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/helm-alias-cb30-20261122/candidate')
bake45 = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/db2-bake-cf2c-20261122/candidate')
blob = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/model-blob-ee45-20261122/candidate')
drake = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/drake-anim-dece-20261122/candidate')
rude = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/emote-rude-9e58-20261122/candidate')
port1 = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/octo-port1-1ebe-20261122/candidate')
parent = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/codex/nightelf-swatches-on-bd711-20261122/candidate')
out = here/'candidate'
core = h.load(out/'core.json')
plan = h.load(out/'stage-plan.json')
def activate(folder, view):
state = h.load(folder/'stage-plan.json')
h.guard(view, state)
assert state['preconditions']['selected_index_generation_exact'] == h.generations(view)
for name in state['preconditions']['new_paths_absent']:
assert not (view/name).exists()
for entry in state['forward']['copy_verified_files']:
target = view/entry['target']
h.link(folder/entry['artifact'], target)
assert h.file_sha(target) == entry['sha256']
activation = state['forward']['final_activation']
assert h.file_sha(view/'.build.info') == activation['parent_sha256']
h.link(folder/activation['file'], view/'private-activation')
os.replace(view/'private-activation', view/'.build.info')
assert h.file_sha(view/'.build.info') == activation['child_sha256']
assert h.generations(view) == state['forward']['selected_index_generation_exact']
with TemporaryDirectory(dir=here,prefix='rehearsal-') as tmp:
view=Path(tmp)
import subprocess
client=Path('/mnt/Games/OctoWoW-LOCAL-Client')
(view/'Data').mkdir()
subprocess.run(['cp','-a','--reflink=always',str(client/'.build.info'),str(view/'.build.info')],check=True)
for sub in ('data','config'):
subprocess.run(['cp','-a','--reflink=always',str(client/'Data'/sub),str(view/'Data'/sub)],check=True)
activate(out,view)
reader=h.Reader(view,plan['candidate_build_key'])
assert reader.config['root'] == plan['candidate_root']
assert reader.encoding['decoded_sha256'] == h.load(out/'metadata.json')['encoding']['decoded_sha256']
parts={}
for name,row in core['parts'].items():
body,position=reader.get(row['content_key'],row['encoding_key'])
assert h.sha(body)==row['decoded_sha256'] and position['encoded_sha256']==row['encoded_sha256']
parts[name]=body
root=parts['root']
branch=h.tree(parts['tvfs-child'])
vfs=h.tree(parts['tvfs-parent'])
for name,tag in h.TVFS.items():
h.check_ref(h.tvfs_record(vfs,name),core['parts'][tag])
by_id={r['file_data_id']:r for r in core['assets']}
expected={json.load(open(c['file']))['fdid']:json.load(open(c['file'])) for c in h.load(here/'components.json')}
assert set(by_id)==set(expected)
identifiers=set(by_id)
routes=h.casc.root_controls_batch(root,h.casc.root_groups(root),identifiers)
enc_keys={bytes.fromhex(r['encoding_key']) for r in by_id.values()}
dl=h.casc.download_controls(parts['download'],h.casc.download_layout(parts['download']),enc_keys)
readback={}
for ident in sorted(identifiers):
ck,={r['content_key'] for r in routes[ident] if r['group']['locale']&2 and not r['group']['flags1']}
r=by_id.get(ident)
body,where=reader.get(ck,r['encoding_key'] if r else None)
if r:
assert (ck,h.sha(body))==(r['content_key'],r['decoded_sha256'])
assert where['encoded_sha256']==r['encoded_sha256']
assert dl[bytes.fromhex(r['encoding_key'])]['encoded_size']==r['encoded_size']
assert r.get('branches')
for bname in r['branches']:
h.check_ref(h.tvfs_record(h.tree(parts[bname]),f'{ident:08X}{ck.upper()}'),r)
assert h.sha(body)==expected[ident]['after_decoded']['sha256']
readback[ident]=dict(content_key=ck,sha256=h.sha(body),archive=where['archive'])
reader.page.cache_clear()
del reader,routes,parts,branch,vfs,root
action=plan['inverse']['first_restore']
assert h.file_sha(view/action['target'])==action['precondition_sha256']
selected = plan['preconditions']['selected_index_generation_exact']
pruned = [name for bucket, name in selected.items() if name != plan['forward']['selected_index_generation_exact'][bucket]]
for name in pruned:
(view/'Data/data'/name).unlink()
assert set(restore_parent_indices(view, out, plan)) == set(pruned)
h.link(out/action['artifact'],view/'private-rollback')
os.replace(view/'private-rollback',view/action['target'])
assert h.file_sha(view/action['target'])==action['postcondition_sha256']
for entry in plan['inverse']['then_remove_created_only_if_sha256_matches']:
target=view/entry['target']
assert h.file_sha(target)==entry['sha256']
target.unlink()
h.guard(view,plan)
assert all(not (view/p).exists() for p in plan['preconditions']['new_paths_absent'])
assert h.generations(view)==plan['preconditions']['selected_index_generation_exact']
reader=h.Reader(view,plan['parent_build_key'])
restored,_=reader.get(reader.config['root'])
assert restored==(parent/'decoded/root.bin').read_bytes()
assert hashlib.md5(restored).hexdigest()==plan['parent_root']
report=dict(stage_plan_sha256=h.file_sha(out/'stage-plan.json'),parent=plan['parent_build_key'],child=plan['candidate_build_key'],root=plan['candidate_root'],physical_readbacks=readback,added_assets=0,replaced_assets=len(readback),new_physical_frames=plan['new_frames'],inherited_frames=plan['inherited_frames'],selected_indices_changed=plan['new_index_files'],inverted_root_bytes_exact=True,all_child_paths_removed=True,restored_index_buckets=16,test_scope='Private scratch forward, active store readback and rollback. No in-game render test.')
h.save(here/'rehearsal.json',report)
print(report['stage_plan_sha256'],h.file_sha(here/'rehearsal.json'))