#!/usr/bin/env python3 """CH5 QA-only full inventory / deterministic chest fixture. Run with isolated cores/db stopped.""" import argparse,json,re,subprocess from pathlib import Path from cluster import inventory BASE=Path('/root/deploy-features/20261026-stack2000') def sql(q):return subprocess.check_output(['mysql','-N','-e',q],text=True).strip() p=argparse.ArgumentParser();p.add_argument('action',choices=['install','remove']);p.add_argument('--private-file',required=True);a=p.parse_args() s=inventory('test') if s['db']['pid'] or any(e['pid'] for e in s['cores']):raise RuntimeError('stop isolated cluster before fixture mutation') secret=json.loads(Path(a.private_file).read_text());assert secret['player_schema']=='player_sb' pid=int(secret['player_id']);manifest=BASE/'stress-fixture.json' if a.action=='remove': data=json.loads(manifest.read_text()) ids=','.join(map(str,data['fillers'])) if ids:sql('DELETE FROM player_sb.item WHERE owner_id=%d AND vnum=11000 AND id IN (%s)'%(pid,ids)) path=Path(data['group_path']);assert not path.is_symlink();path.unlink();path.symlink_to(data['group_target']) manifest.unlink();print('QA fillers and isolated chest override removed') else: if manifest.exists():raise RuntimeError('fixture already installed') rows=sql("SELECT i.pos,p.size FROM player_sb.item i JOIN player_sb.item_proto p ON i.vnum=p.vnum WHERE i.owner_id=%d AND i.window='INVENTORY' AND i.pos<225"%pid) occupied=set() for row in rows.splitlines(): cell,size=map(int,row.split());occupied.update(cell+5*j for j in range(size)) for cell,vnum,count,size in [(197,16,1,2),(198,50037,2,1)]: cells={cell+5*j for j in range(size)} if cells&occupied:raise RuntimeError('QA seed cells occupied') sql("INSERT INTO player_sb.item(owner_id,window,pos,count,vnum,port_extra) VALUES(%d,'INVENTORY',%d,%d,%d,UNHEX(REPEAT('00',69)))"%(pid,cell,count,vnum));occupied.update(cells) ids=[] for cell in range(225): if cell in occupied:continue ids.append(int(sql("INSERT INTO player_sb.item(owner_id,window,pos,count,vnum,port_extra) VALUES(%d,'INVENTORY',%d,1,11000,UNHEX(REPEAT('00',69)));SELECT LAST_INSERT_ID()"%(pid,cell)))) path=Path('/usr/metin2/server/sbtest/share/locale/newcibn/special_item_group.txt');assert path.is_symlink();target=str(path.readlink());blob=path.read_bytes() pattern=rb'(?m)^Group[^\r\n]*\r?\n\{.*?^\}' def keep(m):return b'' if re.search(rb'\bVnum\s+50037\b',m[0],re.I) else m[0] blob=re.sub(pattern,keep,blob,flags=re.S)+b'\nGroup STACK2000_QA\n{\n Vnum 50037\n 1 27002 2000 100\n}\n' data=dict(fillers=ids,group_path=str(path),group_target=target) manifest.write_text(json.dumps(data));manifest.chmod(0o600);path.unlink();path.write_bytes(blob) print('QA-only full inventory prepared; filler count',len(ids))