from pathlib import Path
import json,hashlib
p=Path(__file__).resolve().parent
inquiry=(p/'original-inquiry.txt').read_text().strip();facts=json.load(open(p/'approved-facts.json'));handoff=json.load(open(p/'handoff.json'));confirmation=json.load(open(p/'illustrative-manual-confirmation.json'));sources=json.load(open(p/'source-map.json'));draft=(p/'agent-review-draft.md').read_text()
a=handoff['before_confirmation'];b=handoff['after_illustrative_confirmation']
assert 'DEMO-PROPERTY-01' not in inquiry
assert a['property_id'] is None and a['property_match_source'] is None and a['property_match_status']=='pending_confirmation'
assert b['property_match_source']==confirmation['source_id'] and b['property_id']==confirmation['confirmed_record_id']==facts['record_id']
assert 'Authored illustrative' in confirmation['source_type']
for key in ['floor_area','asking_price','viewing_availability','exact_viewing_date']:assert facts[key] is None and b[key] is None
assert not b['appointment_booked'] and handoff['actions_performed']==[]
for field in ['intent','relative_date']:assert sources['properties'][field]['quote'] in inquiry
assert 'Ground-floor apartment with access to a private patio.' in draft
assert 'No appointment has been booked.' in draft
staging_record = p/'staging-record.json'
staging = 'MISSING_ORIGINAL_AND_EDITED_IMAGES'
staging_hashes = {}
if staging_record.is_file():
    record = json.loads(staging_record.read_text())
    assert sources['staging_status'].startswith('AVAILABLE_SYNTHETIC_CONCEPTS')
    assert record['review']['strict_furniture_only_preservation'] is False
    for asset in record['assets']:
        file = p/asset['file']
        digest = hashlib.sha256(file.read_bytes()).hexdigest()
        assert digest == asset['sha256']
        staging_hashes[asset['id']] = digest
    assert set(staging_hashes) == {'RE-I1', 'RE-I2'}
    staging = 'SYNTHETIC_CONCEPT_FILES_MATCH_RECORDED_HASHES; strict furniture-only preservation not established'
else:
    assert sources['staging_status'].startswith('MISSING')
receipt={'status':'PASS_SOURCE_ASSOCIATION_AND_UNKNOWN_HANDLING','initial_identity':'pending_confirmation; no automatic property identification from wording','association':'Only the separate authored illustrative confirmation supplies ID; not an actual CRM action','unknowns_preserved':['floor_area','asking_price','viewing_availability','exact_viewing_date'],'appointment_booked':False,'staging':staging,'staging_image_sha256':staging_hashes,'sources':{f.name:hashlib.sha256(f.read_bytes()).hexdigest() for f in p.iterdir() if f.is_file() and f.suffix in ['.txt','.md','.json','.svg','.png'] and f.name!='validation-receipt.json'}}
(p/'validation-receipt.json').write_text(json.dumps(receipt,indent=2)+'\n');print(receipt['status'])
