from pathlib import Path from datetime import datetime,timezone import json,hashlib,shutil OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1];proof=json.loads((OUT/'business-country-fixture.json').read_text(encoding='utf-8'));QA=Path(proof['QA_source']);assert QA.resolve().is_relative_to((ROOT/'storage/app/private/investmoz-v2/portal-audit').resolve()) and proof['target']['port']==55441 relative='resources/js/pages/investment/business-interest.tsx';source=QA/relative;active=ROOT/relative;baseline=hashlib.sha256(active.read_bytes()).hexdigest();backup=QA/'storage/app/private/business-feedback-20261012-before.tsx';assert not backup.exists();shutil.copyfile(source,backup) s=source.read_text(encoding='utf-8') needle=" const [error, setError] = useState('');";assert s.count(needle)==1;s=s.replace(needle,needle+"\n const [fieldErrors, setFieldErrors] = useState>>({});") needle=" const update = (field: K, value: Form[K]) =>\n setForm((current) => ({ ...current, [field]: value }));";assert s.count(needle)==1 s=s.replace(needle,""" const update = (field: K, value: Form[K]) => { setForm((current) => ({ ...current, [field]: value })); setFieldErrors((current) => ({ ...current, [field]: undefined })); }; const fieldId = (field: keyof Form) => `business-interest-${field}`; const feedback = (field: keyof Form) => ({ id: fieldId(field), name: field, 'aria-invalid': !!fieldErrors[field], 'aria-describedby': fieldErrors[field] ? `${fieldId(field)}-error` : undefined, }); const fieldError = (field: keyof Form) => fieldErrors[field] ? ( ) : null;""") needle=""" if (!response.ok) throw new Error( data.message ?? 'Não foi possível enviar a manifestação.', );""";assert s.count(needle)==1 s=s.replace(needle,""" if (!response.ok) { const errors: Partial> = {}; for (const [field, messages] of Object.entries(data.errors ?? {})) { if (field in form && Array.isArray(messages)) { errors[field as keyof Form] = messages.filter((message): message is string => typeof message === 'string').join(' '); } } setFieldErrors(errors); setError(data.message ?? 'Não foi possível enviar a manifestação.'); const first = Object.keys(errors)[0] as keyof Form | undefined; window.setTimeout(() => document.getElementById(first ? fieldId(first) : 'business-interest-feedback')?.focus(), 0); return; } setFieldErrors({});""") for field in ['fullName','email','phone','investorType','sectorInterest','modality','investmentRange','message']: needle=f' value={{form.{field}}}';assert s.count(needle)==1;s=s.replace(needle,f" {{...feedback('{field}')}}\n"+needle) # Existing implicit labels remain; insert a linked field-level message adjacent to their control. end=s.index(' ',s.index(f'{{...feedback(\'{field}\')}}'));s=s[:end]+f" {{fieldError('{field}')}}\n"+s[end:] for field in ['country','declared_origin_country_code']: needle=f' value={{form.{field}}}';assert s.count(needle)==1;s=s.replace(needle,f" id={{fieldId('{field}')}}\n error={{fieldErrors.{field}}}\n"+needle) needle=' checked={form.privacyConsent}';assert s.count(needle)==1;s=s.replace(needle," {...feedback('privacyConsent')}\n"+needle) needle=' {error &&

{error}

}';assert s.count(needle)==1;s=s.replace(needle," {fieldError('privacyConsent')}\n {error &&

{error}

}") # CountrySelect has two controls with their own labels; avoid wrapping them both in one implicit label. for label in ['País de origem declarado desta solicitação','País']: needle=f'' if needle not in s:continue start=s.index(needle);end=s.index('',start);s=s[:start]+s[start:end+8].replace(needle,f'
{label}',1).replace('','
',1)+s[end+8:] source.write_text(s,encoding='utf-8');assert hashlib.sha256(active.read_bytes()).hexdigest()==baseline out={'at':datetime.now(timezone.utc).isoformat(),'case':'C134','QA_only':True,'target':proof['target'],'file':relative,'before_sha256':hashlib.sha256(backup.read_bytes()).hexdigest(),'after_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'active_sha256_preserved':baseline,'compilation_required':True,'API_field_errors_connected':True,'incomplete_input_preserved':True,'idempotency_key_preserved_after_error':True,'visual_acceptance_pending':True,'scope':'Field feedback and accessible focus in existing business-interest form; no fields/schema/business rules added'} (OUT/'business-feedback-QA-delta.json').write_text(json.dumps(out,indent=2),encoding='utf-8');print(json.dumps(out))