利用LLMs加速大规模测试迁移
by: Charles Covey-Brandt
作者:Charles Covey-Brandt
Airbnb recently completed our first large-scale, LLM-driven code migration, updating nearly 3.5K React component test files from Enzyme to use React Testing Library (RTL) instead. We’d originally estimated this would take 1.5 years of engineering time to do by hand, but — using a combination of frontier models and robust automation — we finished the entire migration in just 6 weeks.
Airbnb 最近完成了我们第一次大规模的 LLM 驱动代码迁移,将近 3.5K 的 React 组件测试文件从 Enzyme 更新为使用 React Testing Library (RTL)。我们最初估计这需要 1.5 年的工程时间手动完成,但通过结合前沿模型和强大的自动化,我们在短短 6 周内完成了整个迁移。
In this blog post, we’ll highlight the unique challenges we faced migrating from Enzyme to RTL, how LLMs excel at solving this particular type of challenge, and how we structured our migration tooling to run an LLM-driven migration at scale.
在这篇博客文章中,我们将重点介绍从 Enzyme 迁移到 RTL 时面临的独特挑战,LLM 在解决这种特定类型挑战方面的优势,以及我们如何构建迁移工具以大规模运行 LLM 驱动的迁移。
Background
背景
In 2020, Airbnb adopted React Testing Library (RTL) for all new React component test development, marking our first steps away from Enzyme. Although Enzyme had served us well since 2015, it was designed for earlier versions of React, and the framework’s deep access to component internals no longer aligned with modern React testing practices.
在 2020 年,Airbnb 采用了 React Testing Library (RTL) 来开发所有新的 React 组件测试,标志着我们首次脱离 Enzyme。尽管 Enzyme 自 2015 年以来一直为我们服务良好,但它是为早期版本的 React 设计的,而该框架对组件内部的深度访问已不再与现代 React 测试实践相符。
However, because of the fundamental differences between these frameworks, we couldn’t easily swap out one for the other (read more about the differences here). We also couldn’t just delete the Enzyme files, as analysis showed this would create significant gaps in our code coverage. To complete this migration, we needed an automated way to refactor test files from Enzyme to RTL while preserving the intent of the original tests and their code coverage.
然而,由于这些框架之间的根本差异,我们无法轻易地将一个替换为另一个(阅读更多关于差异的信息这里)。我们也不能简单地删除Enzyme文件,因为分析显示这会在我们的代码覆盖率中造成显著的空白。为了完成这次迁移,我们需要一种自动化的方法将测试文件从Enzyme重构为RTL,同时保留原...