table('fr_calculations')->count();$p=$rulePreview(13,$documentInput('gross_included',[$line('RECOVERY','100')]));$host->beginTransaction();try{$host->beginTransaction();try{$host->statement("CREATE FUNCTION dm_fail_test() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'Injected document math failure'; END; $$");$host->statement('CREATE TRIGGER dm_fail_test BEFORE INSERT ON fr_commands FOR EACH ROW EXECUTE FUNCTION dm_fail_test()');$selectRule(13);$failed=false;try{$rules->confirm(13,$p['preview']);}catch(Illuminate\Database\QueryException){$failed=true;}$ok($failed&&$host->table('fr_calculations')->count()===$before,'failed command receipt leaves no line result');}finally{$host->rollBack();}$selectRule(13);$out=$rules->confirm(13,$p['preview']);$ok($out['state']==='determined_qa'&&$host->table('fr_calculations')->count()===$before+1,'same command recovers line calculation after failure');}finally{$host->rollBack();}$ok($host->table('fr_calculations')->count()===$before,'failure recovery test fully rolled back');file_put_contents($work.'/document-math-recovery.json',json_encode(['passed'=>true,'checks'=>$checks,'rolled_back'=>true,'new_financial_effects'=>0],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/document-math-recovery.json']).PHP_EOL;