DOI: https://doi.org/10.1145/3719345
تاريخ النشر: 2025-03-04
المؤلف: Jiaolong Kong وآخرون
الموضوع الرئيسي: تقنيات اختبار البرمجيات وتصحيح الأخطاء
نظرة عامة
يقدم هذا القسم نظرة عامة على ContrastRepair، وهو نهج جديد لإصلاح البرامج تلقائيًا (APR) يستفيد من نماذج اللغة الكبيرة (LLMs)، وبشكل خاص ChatGPT، لتوليد تصحيحات فعالة لعيوب البرمجيات. يعزز هذا الأسلوب APR المدفوع بالمحادثة من خلال تقديم أزواج اختبار تباينية، تتكون من اختبار فاشل واختبار ناجح. يسمح هذا التعليق التبايني لـ LLM بتقليل الفروق بين الاختبار الناجح الذي تم توليده والاختبار الفاشل، مما يحسن من تحديد أسباب العيوب الجذرية.
يتضمن تنفيذ ContrastRepair تفاعلات تكرارية مع ChatGPT حتى يتم إنتاج إصلاحات عيوب معقولة. تكشف التقييمات التي أجريت على مجموعات بيانات مرجعية مثل Defects4j وQuixBugs وHumanEval-Java أن ContrastRepair يتفوق بشكل كبير على طرق APR الحالية، محققًا أداءً جديدًا رائدًا. ومن الجدير بالذكر أنه في مجموعات بيانات Defects4j 1.2 و2.0، يقوم ContrastRepair بإصلاح 143 من أصل 337 حالة عيب، متجاوزًا أفضل خط أساسي، الذي يصلح فقط 124 عيبًا.
مقدمة
تسلط مقدمة هذه الورقة البحثية الضوء على التعقيد المتزايد لأنظمة البرمجيات، مما يؤدي حتمًا إلى عيوب وثغرات يمكن أن تؤدي إلى فشل النظام وانتهاكات أمنية. يعد تصحيح الأخطاء يدويًا مكلفًا من حيث الموارد، حيث يستهلك حوالي 50% من وقت المطورين ويكلف مليارات سنويًا. لمواجهة هذه التحديات، ظهر إصلاح البرامج التلقائي (APR)، حيث أظهرت الطرق التقليدية مثل القائم على القوالب، والقائم على الحدس، والقائم على القيود فعالية محدودة. أدت التطورات الأخيرة في التعلم العميق (DL) إلى تحسين أداء APR، ومع ذلك لا تزال هذه الطرق تعاني من صعوبات في التعميم وكفاءة التحقق.
تقترح الورقة نهجًا جديدًا، يسمى ContrastRepair، الذي يستفيد من نماذج اللغة الكبيرة (LLMs) في سياق مدفوع بالمحادثة لتعزيز تحديد وإصلاح العيوب. من خلال دمج كل من التعليقات الإيجابية والسلبية من حالات الاختبار، يولد ContrastRepair مطالبات أكثر معلوماتية لـ LLMs، مما يسهل تحديد العيوب بشكل أفضل وتوليد التصحيحات. يتضمن الأسلوب إنشاء أزواج تباينية من حالات الاختبار الفاشلة والناجحة لعزل أسباب الفشل بشكل فعال. تظهر التقييمات على مجموعات بيانات مثل Defects4J وQuixBugs وHumanEval-Java أن ContrastRepair يتفوق على الطرق الرائدة الحالية، بما في ذلك CHATREPAIR القائم على ChatGPT، من خلال إصلاح 360 من أصل 581 عيبًا وتحقيق كفاءة أكبر في استدعاءات واجهة برمجة التطبيقات. تؤكد الدراسة على أهمية صياغة المطالبات والمعلومات السياقية في تحسين نتائج APR.
الطرق
يستعرض قسم المنهجية عملية ContrastRepair، التي تستخدم نهجًا محادثيًا لإصلاح الشيفرة المعيبة باستخدام نموذج لغة كبير (LLM) مثل ChatGPT. تبدأ العملية ببرنامج قيد التحقق ومجموعة اختبارات تحتوي على عدة حالات اختبار. إذا نجح البرنامج المعيب الأولي في اجتياز جميع الاختبارات، يتم اقتراح تصحيح معقول للمراجعة البشرية. على العكس، إذا فشل أي اختبار (يشار إليه بـ \( f \))، يتم التقاط سجلات التتبع المقابلة (\( T_f \))، جنبًا إلى جنب مع جميع الاختبارات الناجحة (\( P \)) التي يتعامل معها البرنامج بشكل صحيح.
لتسهيل تحديد أسباب الفشل، يقوم ContrastRepair بإنشاء أزواج اختبار تباينية تتضمن الاختبار الفاشل \( f \) واختبارات ناجحة أخرى (مثل \( f’ \)، \( f” \)). يتم استخدام عملية اختيار موجهة بالتماثل لاختيار اختبار ناجح يشبه الاختبار الفاشل عن كثب، مما يسمح لـ ChatGPT بعزل أسباب الفشل من خلال فحص اختلافاتها الطفيفة. في الحالات التي لا توجد فيها اختبارات ناجحة مشابهة بشكل كافٍ، يتم استخدام تقنية تحوير اختبار واعية بالنوع لتوليد اختبار ناجح يغير الحد الأدنى من حالة الاختبار الفاشلة. يتم بناء المطالبات لـ ChatGPT باستخدام سجلات التتبع، وأزواج الاختبار، والدوال المعتمدة المحددة من السجلات، والدالة المعيبة المستهدفة، ووصف المتطلبات. تستمر العملية التكرارية حتى يتم تحديد تصحيح معقول أو يتم استنفاد ميزانية الإصلاح، المحددة من خلال الحد الأقصى لعدد التكرارات.
المناقشة
في هذا القسم، تناقش الورقة مساهمات ونتائج النهج المقترح، ContrastRepair، الذي يستخدم نماذج اللغة الكبيرة (LLMs) لإصلاح البرامج تلقائيًا (APR). يقدم المؤلفون منهجية مدفوعة بالمحادثة تتضمن كل من التعليقات الإيجابية والسلبية لتحسين جودة إصلاح العيوب. تعتبر الابتكار الرئيسي هو بناء وتحديد أولويات أزواج الاختبار التباينية، التي تتكون من اختبارات فاشلة وناجحة مرتبطة ارتباطًا وثيقًا. تساعد هذه الاستراتيجية LLMs في تحديد العيوب بدقة وتوليد تصحيحات فعالة، مما يؤدي إلى تحسين ملحوظ بنسبة 15.32% في إصلاح العيوب الصحيحة مقارنة بأدوات APR الرائدة الحالية.
تؤكد الورقة أيضًا على أهمية اختيار أزواج الاختبار التباينية المناسبة، حيث لا توفر جميع الأزواج رؤى قيمة لعملية الإصلاح. يوضح المؤلفون ذلك من خلال مثال يتضمن دالة معيبة تتعامل بشكل خاطئ مع المدخلات السداسية، مما يوضح كيف يمكن أن توجه أزواج الاختبار المصممة بشكل جيد المُصلح لتحديد التغييرات الحرجة. علاوة على ذلك، تتضمن المنهجية تقنية تحوير واعية بالنوع لتوليد اختبارات ناجحة إضافية عند الحاجة، مما يضمن مجموعة قوية من حالات الاختبار للتقييم. تم تصميم عملية الإصلاح التكرارية الشاملة لتحقيق التوازن بين الاستمرار من التصحيحات السابقة وإعادة البدء من الدالة المعيبة الأصلية، مما يزيد من فرص توليد إصلاحات دقيقة. تؤكد نتائج التقييم فعالية ContrastRepair، مما يثبت أنه حل رائد في مجال إصلاح البرامج التلقائي.
DOI: https://doi.org/10.1145/3719345
Publication Date: 2025-03-04
Author(s): Jiaolong Kong et al.
Primary Topic: Software Testing and Debugging Techniques
Overview
The section presents an overview of ContrastRepair, a novel approach to Automated Program Repair (APR) that leverages Large Language Models (LLMs), specifically ChatGPT, to generate effective patches for software bugs. The method enhances conversation-driven APR by introducing contrastive test pairs, which consist of a failing test and a passing test. This contrastive feedback allows the LLM to minimize the differences between the generated passing test and the failing test, thereby improving the identification of bug root causes.
The implementation of ContrastRepair involves iterative interactions with ChatGPT until plausible bug fixes are produced. Evaluations conducted on benchmark datasets such as Defects4j, QuixBugs, and HumanEval-Java reveal that ContrastRepair significantly outperforms existing APR methods, achieving a new state-of-the-art performance. Notably, in the Defects4j 1.2 and 2.0 datasets, ContrastRepair successfully repairs 143 out of 337 bug cases, surpassing the best-performing baseline, which fixes only 124 bugs.
Introduction
The introduction of this research paper highlights the escalating complexity of software systems, which inevitably leads to bugs and vulnerabilities that can result in system failures and security breaches. Manual debugging is resource-intensive, consuming approximately 50% of developers’ time and costing billions annually. To address these challenges, Automatic Program Repair (APR) has emerged, with traditional methods such as template-based, heuristic-based, and constraint-based approaches showing limited effectiveness. Recent advancements in deep learning (DL) have improved APR performance, yet these methods still struggle with generalization and validation efficiency.
The paper proposes a novel approach, named ContrastRepair, which leverages Large Language Models (LLMs) in a conversational-driven context to enhance bug localization and repair. By incorporating both positive and negative feedback from test cases, ContrastRepair generates more informative prompts for LLMs, facilitating better bug identification and patch generation. The method involves creating contrastive pairs of failing and passing test cases to isolate failure causes effectively. Evaluations on datasets such as Defects4J, QuixBugs, and HumanEval-Java demonstrate that ContrastRepair outperforms existing state-of-the-art methods, including the ChatGPT-based CHATREPAIR, by successfully fixing 360 out of 581 bugs and achieving greater efficiency in API calls. The study emphasizes the importance of prompt formulation and contextual information in improving APR outcomes.
Methods
The methodology section outlines the ContrastRepair process, which employs a conversational approach to repair buggy code using a large language model (LLM) like ChatGPT. The process begins with a program under validation and a test suite containing multiple test cases. If the initial buggy program passes all tests, a plausible patch is proposed for human review. Conversely, if any test fails (denoted as \( f \)), the corresponding traceback logs (\( T_f \)) are captured, along with all passing tests (\( P \)) that the program handles correctly.
To facilitate the identification of failure causes, ContrastRepair constructs contrastive test pairs involving the failing test \( f \) and other passing tests (e.g., \( f’ \), \( f” \)). A similarity-guided selection process is employed to choose a passing test that closely resembles the failing test, thereby allowing ChatGPT to isolate the failure causes by examining their minor differences. In instances where no sufficiently similar passing tests exist, a type-aware test mutation technique is utilized to generate a passing test that minimally alters the failing test case. Prompts for ChatGPT are constructed using the traceback logs, the test pairs, dependent functions identified from the logs, the target buggy function, and the requirements description. The iterative process continues until a plausible patch is identified or the repair budget, defined by the maximum number of iterations, is exhausted.
Discussion
In this section, the paper discusses the contributions and findings of the proposed approach, ContrastRepair, which utilizes Large Language Models (LLMs) for automated program repair (APR). The authors introduce a conversation-driven methodology that incorporates both positive and negative feedback to enhance the quality of bug fixes. A key innovation is the construction and prioritization of contrastive test pairs, which consist of failing and passing tests that are closely related. This strategy aids LLMs in accurately localizing bugs and generating effective patches, leading to a notable 15.32% improvement in correct bug fixes over existing state-of-the-art APR tools.
The paper also emphasizes the importance of selecting appropriate contrastive test pairs, as not all pairs provide valuable insights for the repair process. The authors illustrate this with an example involving a buggy function that mishandles hexadecimal inputs, demonstrating how well-crafted test pairs can guide the repairer to identify critical changes. Furthermore, the methodology includes a type-aware mutation technique for generating additional passing tests when necessary, ensuring a robust set of test cases for evaluation. The overall iterative repair process is designed to balance between continuing from previous patches and restarting from the original buggy function, thereby optimizing the chances of generating accurate fixes. The evaluation results confirm the effectiveness of ContrastRepair, establishing it as a leading solution in the field of automated program repair.
