Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/synapse/blob/main/evidence/REPAIR-RECOVERY-L662/review-fix/relative-backup-qualify.py # synapse A component of the AienOS ecosystem. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `synapse / evidence / REPAIR-RECOVERY-L662 / review-fix / relative-backup-qualify.py` 37 lines ยท 3138 bytes Raw Blame History 1 """Observe real file and directory fsync calls for a bare relative repair backup. 2 Requires Linux strace; uses only a synthetic in-memory device and owned scratch. 3 This is syscall-order coverage, not a physical crash/power-loss experiment. 4 """ 5 import argparse,hashlib,json,os,re,subprocess 6 from pathlib import Path 7 8 p=argparse.ArgumentParser();p.add_argument('--root',type=Path,required=True);p.add_argument('--out',type=Path,required=True);args=p.parse_args() 9 root=args.root.resolve();out=args.out.resolve();out.mkdir(parents=True,exist_ok=False) 10 cwd=out/'cwd';cwd.mkdir();tmp=out/'tmp';tmp.mkdir();env=os.environ.copy();env['TMPDIR']=str(tmp);env.setdefault('CARGO_TARGET_DIR',str(out/'cargo')) 11 source_files=['crates/synapse-store/src/blockdev/repair.rs','crates/synapse-store/src/blockdev_tests.rs'] 12 state={'source_head':subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip(),'inputs':{f:hashlib.sha256((root/f).read_bytes()).hexdigest() for f in source_files},'passed':False,'physical_crash_tested':False} 13 cmd=['cargo','test','--locked','-j','6','-p','synapse-store','--lib','--no-run','--message-format=json'] 14 with (out/'build-json.log').open('w') as stdout,(out/'build-stderr.log').open('w') as stderr: 15 result=subprocess.run(cmd,cwd=root,env=env,stdout=stdout,stderr=stderr,timeout=600) 16 if result.returncode:raise RuntimeError('Failed to build actual unit-test binary') 17 executables=[] 18 for line in (out/'build-json.log').read_text().splitlines(): 19 try:row=json.loads(line) 20 except ValueError:continue 21 if row.get('reason')=='compiler-artifact' and row.get('target',{}).get('name')=='synapse_store' and row.get('profile',{}).get('test') and row.get('executable'):executables.append(row['executable']) 22 if len(set(executables))!=1:raise RuntimeError('Cannot uniquely bind actual synapse-store test binary') 23 binary=Path(executables[-1]);state['binary']=str(binary);state['binary_sha256']=hashlib.sha256(binary.read_bytes()).hexdigest() 24 test='blockdev_tests::repair_tests::r1_repair_bare_relative_backup_is_created_and_verified' 25 command=['strace','-f','-yy','-o',str(out/'trace.log'),'-e','trace=openat,fsync',str(binary),'--exact',test,'--nocapture','--test-threads=1'] 26 with (out/'test.log').open('w') as log:rc=subprocess.run(command,cwd=cwd,env=env,stdout=log,stderr=subprocess.STDOUT,timeout=120).returncode 27 state['command']=command;state['test_exit']=rc 28 calls=[] 29 for index,line in enumerate((out/'trace.log').read_text().splitlines()): 30 match=re.search(r'fsync\(\d+<([^>]+)>\)\s*=\s*0',line) 31 if match:calls.append({'line':index,'path':match.group(1),'raw':line}) 32 files=[c for c in calls if Path(c['path']).parent==cwd and Path(c['path']).name.startswith('relative-repair-backup-')] 33 dirs=[c for c in calls if Path(c['path'])==cwd] 34 state['successful_fsync_calls']=calls;state['backup_file_synced']=bool(files);state['containing_directory_synced']=bool(dirs) 35 state['passed']=rc==0 and bool(files) and bool(dirs) and files[0]['line']