arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.09907cs.SEcs.AI
收藏

智能体基于属性的测试:在Python生态系统中寻找Bug

Agentic Property-Based Testing: Finding Bugs Across the Python Ecosystem

MATS, Anthropic(MATS,Anthropic);Northeastern University(东北大学);Anthropic

Muhammad Maaz, Liam DeVoe, Zac Hatfield-Dodds, Nicholas Carlini

AI总结:

本文提出一种基于LLM的智能体,通过分析代码与文档推断属性,自动合成并执行基于属性的测试(PBT)以确认Bug。在100个Python包的评估中,其高分Bug报告有效率达86%,并成功向NumPy等提交合并了补丁,证明该方法严格且可扩展。

摘要:

基于属性的测试(PBT)是一种轻量级形式化方法,通常作为随机测试框架实现。用户使用PBT框架提供的组合子为其测试指定输入域,并将预期的属性或不变量指定为单元测试函数。然后,框架通过生成输入并调用测试函数等方式搜索反例。在这项工作中,我们展示了一个基于LLM的智能体,它能够分析Python模块,从代码和文档中推断特定于函数和跨函数的属性,合成并执行PBT,反思这些测试的输出以确认真正的Bug,最后为开发者输出可操作的Bug报告。我们在100个流行的Python包上对智能体进行了广泛评估。在智能体生成的Bug报告中,我们经过人工审查发现,56%是有效Bug,32%是我们愿意报告给维护者的有效Bug。随后,我们开发了一种排序准则,以便向开发者呈现高优先级的有效Bug,并发现在得分最高的21个Bug中,86%是有效的,81%是我们愿意报告的。这些Bug涵盖了多种失败模式,从序列化失败到数值精度错误,再到有缺陷的缓存实现。我们报告了5个Bug,其中4个带有补丁,包括报告给NumPy和云计算SDK的Bug,其中3个补丁已成功合并。我们的结果表明,结合PBT的LLM为自主测试软件提供了一种严格且可扩展的方法。

英文摘要:

Property-based testing (PBT) is a lightweight formal method, typically implemented as a randomized testing framework. Users specify the input domain for their test using combinators supplied by the PBT framework, and the expected properties or invariants as a unit-test function. The framework then searches for a counterexample, e.g. by generating inputs and calling the test function. In this work, we demonstrate an LLM-based agent which analyzes Python modules, infers function-specific and cross-function properties from code and documentation, synthesizes and executes PBTs, reflects on outputs of these tests to confirm true bugs, and finally outputs actionable bug reports for the developer. We perform an extensive evaluation of our agent across 100 popular Python packages. Of the bug reports generated by the agent, we found after manual review that 56\% were valid bugs and 32\% were valid bugs that we would report to maintainers. We then developed a ranking rubric to surface high-priority valid bugs to developers, and found that of the 21 top-scoring bugs, 86\% were valid and 81\% we would report. The bugs span diverse failure modes from serialization failures to numerical precision errors to flawed cache implementations. We reported 5 bugs, 4 with patches, including to NumPy and cloud computing SDKs, with 3 patches merged successfully. Our results suggest that LLMs with PBT provides a rigorous and scalable method for autonomously testing software. Our code and artifacts are available at: https://github.com/mmaaz-git/agentic-pbt.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑