104 lines
5.7 KiB
Python
104 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Claude lane: content step 99a3b2b6 -> b7f4 (native retail Classic AH categories: Potion/Elixir/.../Cloth/Herb/...; Turtle items classified by gateway table).
|
|
Step logic copied verbatim from grouped-cb30-v1/install.py. Usage: install.py check|apply|rollback|status"""
|
|
import hashlib, json, os, shutil, sys
|
|
from pathlib import Path
|
|
CLIENT = Path(os.environ.get('GW_CLIENT', '/mnt/Games/OctoWoW-Windows-Client'))
|
|
CAND = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/atlasfix-4966-frozen-candidate')
|
|
PLAN = json.loads((CAND / 'stage-plan.json').read_text())
|
|
HERE = Path(__file__).resolve().parent; SD = HERE / 'state'; SD.mkdir(exist_ok=True)
|
|
STATE, LOG = SD / ('install-state-' + CLIENT.name + '.json'), SD / 'install-log.jsonl'
|
|
assert hashlib.sha256((CAND / 'stage-plan.json').read_bytes()).hexdigest() == '8f93302bd7d8f6ce2b0054fb2dc1a327b9c7c2f7480680ac6fc7b67b24bd1466'
|
|
assert PLAN['parent_build_key'] == 'b7f4a79122e629dcb77e8986f6238a8d'
|
|
def sha(p, chunk=1 << 24):
|
|
h = hashlib.sha256()
|
|
with open(p, 'rb') as f:
|
|
while b := f.read(chunk): h.update(b)
|
|
return h.hexdigest()
|
|
def log(**kw):
|
|
with open(LOG, 'a') as f: f.write(json.dumps(kw) + '\n')
|
|
print(json.dumps(kw))
|
|
def fail(msg):
|
|
log(event='FAIL', msg=msg); sys.exit(1)
|
|
def running():
|
|
for pid in filter(str.isdigit, os.listdir('/proc')):
|
|
try:
|
|
args = open(f'/proc/{pid}/cmdline', 'rb').read().replace(b'\0', b' ').decode('latin1')
|
|
cwd = os.readlink(f'/proc/{pid}/cwd')
|
|
except OSError:
|
|
continue
|
|
argv0 = args.split(' ', 1)[0].replace('\\', '/').rsplit('/', 1)[-1].lower()
|
|
if argv0 == 'wowb.exe' and (str(CLIENT) in args or cwd.startswith(str(CLIENT))): return True
|
|
return False
|
|
def build_key():
|
|
return next(l for l in (CLIENT / '.build.info').read_text().splitlines()[1:] if l.strip()).split('|')[2]
|
|
def gens(b):
|
|
return sorted(x.name for x in (CLIENT / 'Data/data').glob(f'{int(b):02x}*.idx'))
|
|
def signed_set(endpoint):
|
|
d = Path(os.environ.get('GW_SIGNED_ROOT', HERE)) / f'signed-{endpoint}'
|
|
want = dict(l.split()[::-1] for l in (d / 'SHA256SUMS').read_text().splitlines())
|
|
for n in NATIVES:
|
|
if sha(d / n) != want[n]: fail(f'signed {endpoint} {n} changed')
|
|
return d
|
|
|
|
def step_check(cand, plan):
|
|
p, bad = plan['preconditions'], []
|
|
for e in p['existing_exact_sha256']:
|
|
t = CLIENT / e['target']
|
|
if not t.exists() or sha(t) != e['sha256']: bad.append(e['target'])
|
|
for b, n in p['selected_index_generation_exact'].items():
|
|
if gens(b)[-1] != n: bad.append(f'idx {b}: {gens(b)[-1]} != {n}')
|
|
for s in p['inherited_native_alias_exact_spans']:
|
|
with open(CLIENT / s['target'], 'rb') as f:
|
|
f.seek(s['offset']); blob = f.read(s['bytes'])
|
|
if hashlib.sha256(blob).hexdigest() != s['sha256']: bad.append(f"span {s['target']}@{s['offset']}")
|
|
for t in p['new_paths_absent']:
|
|
if (CLIENT / t).exists(): bad.append('exists ' + t)
|
|
for e in plan['forward']['copy_verified_files']:
|
|
if sha(cand / e['artifact']) != e['sha256']: bad.append('artifact ' + e['artifact'])
|
|
if bad: fail(f"{plan['candidate_build_key'][:8]} preconditions: " + '; '.join(bad[:20]))
|
|
def step_apply(cand, plan):
|
|
step_check(cand, plan)
|
|
for e in plan['forward']['copy_verified_files']:
|
|
t = CLIENT / e['target']; t.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(cand / e['artifact'], t)
|
|
if sha(t) != e['sha256']: fail('copy ' + e['target'])
|
|
for b, n in plan['forward']['selected_index_generation_exact'].items():
|
|
if gens(b)[-1] != n: fail(f'idx not selected {b}')
|
|
fa = plan['forward']['final_activation']; bi = CLIENT / fa['target']
|
|
if sha(bi) != fa['parent_sha256']: fail('.build.info changed')
|
|
shutil.copyfile(cand / fa['file'], bi)
|
|
if sha(bi) != fa['child_sha256']: fail('.build.info verify')
|
|
log(event='content-step', build=plan['candidate_build_key'][:8])
|
|
sys.path.insert(0, '/mnt/Games/@project/gateway/runtime/continuation-20261113/codex')
|
|
from casc_stage_inverse import restore_parent_indices
|
|
|
|
def step_rollback(cand, plan):
|
|
inv = plan['inverse']; fr = inv['first_restore']; bi = CLIENT / fr['target']
|
|
current = sha(bi)
|
|
if current not in (fr['precondition_sha256'], fr['postcondition_sha256']): fail('unexpected .build.info before rollback')
|
|
restore_parent_indices(CLIENT, cand, plan)
|
|
if current == fr['precondition_sha256']: shutil.copyfile(cand / fr['artifact'], bi)
|
|
if sha(bi) != fr['postcondition_sha256']: fail('.build.info rollback ' + plan['candidate_build_key'][:8])
|
|
for e in inv['then_remove_created_only_if_sha256_matches']:
|
|
t = CLIENT / e['target']
|
|
if t.exists():
|
|
if sha(t) != e['sha256']: fail('changed, not removing ' + e['target'])
|
|
t.unlink()
|
|
log(event='content-step-rolled-back', to=plan['parent_build_key'][:8])
|
|
|
|
|
|
def check():
|
|
if running(): fail('client process running')
|
|
if build_key() != PLAN['parent_build_key']: fail('build key is not the b7f4a791 parent: ' + build_key())
|
|
step_check(CAND, PLAN); log(event='check-ok', candidate=PLAN['candidate_build_key'][:8])
|
|
def apply():
|
|
check(); step_apply(CAND, PLAN)
|
|
STATE.write_text(json.dumps({'applied': True}))
|
|
log(event='applied', build=build_key()[:8])
|
|
def rollback():
|
|
if running(): fail('client process running')
|
|
step_rollback(CAND, PLAN); STATE.write_text(json.dumps({'applied': False})); log(event='rolled-back', build=build_key()[:8])
|
|
def status(): print(json.dumps({'build_key': build_key()[:8], 'state': json.loads(STATE.read_text()) if STATE.exists() else None}))
|
|
{'check': check, 'apply': apply, 'rollback': rollback, 'status': status}[sys.argv[1]]()
|