"""Check the tested source inventory against exact Git blobs, not HEAD alone.""" from pathlib import Path import datetime, hashlib, json, subprocess, sys root=Path('C:/ar-multiselect-9e8r6t') run,=sys.argv[1:] gate=root/'.local/group-movement-gates'/run inputs=json.loads((gate/'inputs.json').read_bytes()) result=json.loads((gate/'result.json').read_bytes()) assert result['exitCode']==0 and result['inputsUnchanged'] head=subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip() def relevant(p): return p in ('Cargo.toml','Cargo.lock','rust-toolchain.toml') or p.startswith(('crates/','build/','.cargo/','scripts/','docs/','examples/','harness/fixtures/','harness/prototypes/')) paths=subprocess.check_output(['git','ls-tree','-r','--name-only','-z',head],cwd=root).decode().split('\0') assert set(inputs)=={p for p in paths if p and relevant(p)}, 'Committed input inventory differs' assert all('\n' not in p for p in inputs) request=''.join(head+':'+p+'\n' for p in inputs).encode() raw=subprocess.run(['git','cat-file','--batch'],cwd=root,input=request,capture_output=True,check=True).stdout offset=0 actual={} for path in inputs: end=raw.index(b'\n',offset) oid,kind,size=raw[offset:end].split() assert kind==b'blob' size=int(size) data=raw[end+1:end+1+size] assert len(data)==size and raw[end+1+size:end+2+size]==b'\n' actual[path]={'bytes':size,'sha256':hashlib.sha256(data).hexdigest()} offset=end+2+size assert offset==len(raw) changed=[p for p in inputs if inputs[p]!=actual[p]] assert not changed, 'Tested bytes differ from committed blobs: '+repr(changed) data=(gate/'inputs.json').read_bytes() report={'checked':datetime.datetime.now(datetime.timezone.utc).isoformat(),'commit':head,'gate':run,'inputCount':len(inputs),'inputMap':{'bytes':len(data),'sha256':hashlib.sha256(data).hexdigest()},'comparison':'Exact committed Git blobs equal every captured input; same complete filtered inventory'} out=root/'.local/group-movement-gates'/('committed-'+run+'.json') with out.open('x',encoding='utf-8') as f: json.dump(report,f,indent=2) print(json.dumps(report,indent=2))