import json from pathlib import Path import pytest from scripts.data.export_hfd_overlay_assets import export, sha def approved(tmp_path): image, audio = tmp_path/'image.jpg', tmp_path/'question.wav' image.write_bytes(b'reviewed-image');audio.write_bytes(b'reviewed-wave') feature=tmp_path/'components_r0/visual'/f'{sha(str(image))}.pt' feature.parent.mkdir(parents=True);feature.write_bytes(b'existing-feature') row=dict(cohort='vqav2_static',id='vqav2_one',split='train',voice='female_01_en', question=dict(question='What color?',answer='red',image_path=str(image),image_sha256=sha(str(image))), visual_review=dict(accepted=True,blind_to_reference=True,image_sha256=sha(str(image))), asr_review=dict(accepted=True,wave_sha256=sha(str(audio))),timeline=dict(question_voice=str(audio))) plan=tmp_path/'source_plan.json';plan.write_text(json.dumps([row])) return plan,row def test_reuses_only_independent_question_and_visual_assets(tmp_path): plan,row=approved(tmp_path) result=export(plan,tmp_path) asset=result['assets'][0] assert result['format']=='hfd_overlay_assets_v1' assert asset['question_audio_path']==row['timeline']['question_voice'] assert 'path' not in asset and 'frontend_root' not in asset assert result['provenance']['motion_pairing_discarded'] is True def test_rejects_unapproved_visual_and_cross_split_image(tmp_path): plan,row=approved(tmp_path) row['visual_review']['blind_to_reference']=False plan.write_text(json.dumps([row])) with pytest.raises(ValueError,match='Unapproved'):export(plan,tmp_path) row['visual_review']['blind_to_reference']=True other={**row,'id':'vqav2_two','split':'val'} plan.write_text(json.dumps([row,other])) with pytest.raises(ValueError,match='overlaps'):export(plan,tmp_path)