"""Construct and verify a fictional export package. No customer system is accessed.""" import csv,hashlib,io,json,zipfile from pathlib import Path p=Path(__file__).parent payload={'records.csv':b'record_id,title,attachment_path\nr1,Example note,files/note.txt\nr2,Second example,\n','files/note.txt':b'Fictional attachment for the export handoff example.\n'} manifest=dict(format='dreamtsoft-editorial-example-v1',fictional=True,export_id='example-export-1',tenant='example-workspace',cutoff='illustrative snapshot A',encoding='UTF-8',delimiter=',',records=2,attachments=1,excluded=['credentials','billing records','audit log'],files=[dict(path=k,bytes=len(v),sha256=hashlib.sha256(v).hexdigest()) for k,v in payload.items()]) def verify(m,files): expected={f['path'] for f in m['files']} if set(files)!=expected:return 'file inventory mismatch' for f in m['files']: raw=files[f['path']] if len(raw)!=f['bytes'] or hashlib.sha256(raw).hexdigest()!=f['sha256']:return 'payload mismatch' records=list(csv.DictReader(io.StringIO(files['records.csv'].decode('utf-8'),newline=''))) if len(records)!=m['records']:return 'record count mismatch' if len(files)-1!=m['attachments']:return 'attachment count mismatch' if len({r['record_id'] for r in records})!=len(records):return 'duplicate record identity' if any(r['attachment_path'] and r['attachment_path'] not in files for r in records):return 'missing attachment reference' return 'valid fixture' assert verify(manifest,payload)=='valid fixture' missing=dict(payload);del missing['files/note.txt'] changed=dict(payload);changed['files/note.txt']+=b'changed' checks=dict(scope='fictional package fixture only',complete=verify(manifest,payload),missing_attachment=verify(manifest,missing),changed_payload=verify(manifest,changed)) assert checks['missing_attachment']=='file inventory mismatch' and checks['changed_payload']=='payload mismatch' (p/'example-manifest.json').write_text(json.dumps(manifest,indent=2)+'\n') with zipfile.ZipFile(p/'example-export.zip','w',compression=zipfile.ZIP_DEFLATED) as z: for name,data in {**payload,'manifest.json':(p/'example-manifest.json').read_bytes()}.items(): info=zipfile.ZipInfo(name,date_time=(2026,9,5,0,0,0));info.compress_type=zipfile.ZIP_DEFLATED;z.writestr(info,data) (p/'package-checks.json').write_text(json.dumps(checks,indent=2)+'\n') print(json.dumps(checks,indent=2))