"""Copies only the actual21 enum/Composer source files; no installs or connections."""
import hashlib,json,os,pathlib,shutil,tarfile
HERE=pathlib.Path(__file__).resolve().parent
CONTROL=HERE.parent/'final-3i2u-plan-20261011/execution-20261011'
PIN=CONTROL/'ENUM_DEPENDENCY_ACTUAL_PHP73.json'
SOURCE=pathlib.Path('/Users/wiscourper/Documents/workspace/zhct/zhctproject/store')
OUT=pathlib.Path('/tmp/cdx-prepay-enum-closure-20261011')
assert not OUT.exists(),'Exclusive new pure dependency probe only'
pins=json.loads(PIN.read_text())
assert pins['count']==21 and sum(n.startswith('extend/vendor/') for n in pins['files'])==19
OUT.mkdir(mode=0o700)
for name,entry in pins['files'].items():
 src=SOURCE/name
 assert src.is_file() and not src.is_symlink() and src.stat().st_size==entry['bytes']
 assert hashlib.sha256(src.read_bytes()).hexdigest()==entry['sha256'],'Original exact source drift '+name
 dst=OUT/name;dst.parent.mkdir(parents=True,exist_ok=True,mode=0o700)
 shutil.copyfile(src,dst);os.chmod(dst,0o600)
 assert hashlib.sha256(dst.read_bytes()).hexdigest()==entry['sha256']
archive=OUT.with_suffix('.tar')
assert not archive.exists()
with tarfile.open(archive,'w',format=tarfile.USTAR_FORMAT)as tar:
 for file in sorted(OUT.rglob('*')):
  if file.is_file():
   info=tar.gettarinfo(str(file),str(file.relative_to(OUT)));info.mode=0o600;info.uid=info.gid=0;info.uname=info.gname=''
   with file.open('rb')as content:tar.addfile(info,content)
os.chmod(archive,0o600)
print(json.dumps({'status':'EXACT_ENUM_CLOSURE_BYTE_PACKAGE','files':21,'additional_sibling_dependencies':19,'archive_bytes':archive.stat().st_size,'archive_sha256':hashlib.sha256(archive.read_bytes()).hexdigest(),'DB':0,'HTTP':0}))
