【文章标题】:The Pulse: We need to talk about migrations with AI 《脉搏》:我们需要谈谈AI驱动的代码迁移

【文章正文】: Hi, this is Gergely with a bonus, free issue of the Pragmatic Engineer Newsletter. In every issue, I cover Big Tech and startups through the lens of senior engineers and engineering leaders. Today, we cover one out of four topics from 大家好,我是Gergely,这是《实用工程师简报》的免费特刊。每期我都会通过资深工程师和技术主管的视角,解读科技巨头与初创企业的动态。今天我们将探讨上周《脉搏》特刊四个话题中的一个

last week’s The Pulse 上周《脉搏》

issue. Full subscribers received the article below seven days ago. If you’ve been forwarded this email, you can 特刊。付费订阅者七天前就已收到下文。如果你是邮件转发接收者,可以点击

subscribe here 此处订阅

OpenAI put an impressive-sounding case study about how they helped Asana save $5.9M with a single migration. From OpenAI发布了一个令人瞩目的案例研究,讲述他们如何通过一次迁移帮助Asana节省590万美元。根据

OpenAI OpenAI

(emphasis mine.) (引文部分为我所加注)

“Asana cleared 5 years of engineering work in 2 weeks with Codex “Asana借助Codex在两周内完成了原本需要5年的工程工作

. Using OpenAI Codex, Asana replaced an outdated testing system in two weeks for about $12K. 通过使用OpenAI Codex,Asana以约1.2万美元的成本在两周内替换了陈旧的测试系统。

For this project, Codex helped Asana’s engineers remove Enzyme, an outdated testing system that had made the company’s code harder to upgrade. Model and infrastructure costs came to about 6 million estimate for the previous staffing plan. 在这个项目中,Codex协助工程师移除了阻碍代码升级的Enzyme测试框架。AI模型和基础设施成本约1.2万美元,而原计划的人力方案预算高达600万美元。

After 1.5 weeks of engineering effort spread across two calendar weeks, Enzyme was fully removed. Model and infrastructure costs totaled about 6M. The experience changed which long-running software projects the company believes are practical to take on.” 实际工程耗时1.5周(跨两个自然周),总成本约1.2万美元。作为对比:原计划预计耗时五年、耗资600万美元。这次经历彻底改变了该公司对长期软件项目的可行性评估。”

For context, Asana migrated from Enzyme to React Testing Library, which indeed would not be a simple migration. However, their estimate of four engineers (each on circa $300K/year, according to OpenAI’s arithmetic), spending five years on the project, had me like: 需要说明的是,Asana是从Enzyme迁移到React Testing Library,这确实不是简单转换。但按照OpenAI的算法(假设每位工程师年薪30万美元),四个工程师耗时五年的预估让我不禁:

[插入思考表情]

But thinking about this for longer raised the question: what does a migration from Enzyme to React Testing Library even look like? 但深入思考后产生疑问:从Enzyme到React Testing Library的迁移究竟是什么样的?

Enzyme to React Testing Library migration Enzyme到React Testing Library的迁移实例

Let’s take a simple test and see how it looks in various testing libraries. 我们通过一个简单测试案例来对比不同测试库的写法

For our test, we want to verify that a button increments a counter. Here’s our button in React: 测试目标是验证按钮能否正确增加计数器。以下是React按钮组件:

[代码片段:计数器按钮组件]

Our button that increments its counter 实现计数器递增功能的按钮

Now, the test to verify this, in Enzyme: Enzyme版本的测试代码如下:

[代码片段:Enzyme测试用例]

The unit test in Enzyme Enzyme单元测试

And let’s rewrite this test in React Testing Library: 用React Testing Library重写的测试:

[代码片段:RTL测试用例]

The unit test in React Testing Library React Testing Library单元测试

The two tests do the same, but they have 虽然测试功能相同,但两者具有

completely 完全

different syntax! Let’s see just how different they are, with a side-by-side comparison: 不同的语法!通过并排对比更直观:

[代码对比图]

Two very different files: the only code in common is the imports 两份截然不同的文件:唯一相同的只有import语句

The main reason for this difference is that the two frameworks use a fundamentally different approach to testing. Whereas Enzyme is oriented towards component testing (notice how the test operates on a component instance), the React Testing Library operates on the rendered 根本差异在于两者的测试理念不同。Enzyme面向组件测试(操作组件实例),而React Testing Library基于渲染后的

Document Object Model 文档对象模型

(a data structure representing the HTML shipped to the client) so the test sees the whole rendered page, not just the component its written for. That’s why the testing approach will differ radically between the two frameworks, especially when testing complex user journeys. You can learn more (即客户端接收的HTML数据结构),因此测试针对的是整个渲染页面而非单个组件。这使得两者的测试方法存在根本差异,尤其在复杂用户流程测试中。更多对比可参阅

here 此处

on the tradeoffs between the two approaches from the React Testing Library author. React Testing Library作者对两种方案的权衡分析

It took Airbnb 6 weeks to migrate 3,500 tests with AI Airbnb用AI迁移3500个测试耗时六周

Last year, Airbnb 去年Airbnb

revealed 披露了

how they migrated their Enzyme test suite of 3,500 component test files within six weeks with LLMs. The estimate of doing this by hand was 1.5 engineering years. Airbnb did the LLM-aided migration in a multi-phase process: 如何利用大语言模型在六周内迁移3500个组件测试文件。人工迁移预计需要1.5个工程年。Airbnb的AI辅助迁移分为多个阶段:

[迁移流程图]

Five phases of the migration, for each file. Source: 每个文件的五阶段迁移流程。来源:

Airbnb Airbnb

Airbnb’s team had to build loops to keep retrying migrations; once they did, 75% of files were migrated in just four hours, and the migrations were straightforward. They then built a more sophisticated refactor pipeline for the remaining 25% of tests; after building the pipeline, the new loop migrated most of the remaining tests (97%) in total, after running over 4 days. The remaining 3% was done with LLM input, with engineers finishing it in a week. 团队建立了自动重试机制,75%的文件在四小时内完成迁移。剩余25%通过更复杂的重构管道处理,四天后完成其中97%。最后3%由工程师结合LLM在一周内收尾。

This was in March 2025, when the frontier coding model was Claude 3.7 Sonnet. Today, models are a lot more capable, such as the likes of GPT-5.6 Sol and Claude Fable 5. 当时(2025年3月)最先进的编码模型是Claude 3.7 Sonnet。如今GPT-5.6 Sol和Claude Fable 5等模型已更强大。

AI makes impractical migrations doable AI使不可能完成的迁移成为可能

On the basis that it took Airbnb six weeks, I find it credible that it took Asana two weeks to migrate what is probably a similarly complex test infrastructure from Enzyme to RTL, a year later. 鉴于Airbnb耗时六周,我认为Asana在一年后用两周完成类似复杂度的Enzyme到RTL迁移是可信的。

The time and $6M cost as quoted by OpenAI feels inflated. 但OpenAI提到的600万美元成本似乎虚高。

I assume the numbers were based on an estimate that a fulltime engineer could do a maximum of X tests migrated per day, where X was between 5 and 10. Then, calculate the number of engineering years this takes (perhaps 20 engineering years), and multiply by the cost of an engineer. You estimate a project like this when it’s an undesirable project you 推测这个数字是基于:假设每位工程师每天最多迁移5-10个测试,计算总工程年数(可能20工程年),再乘以人力成本。通常只有工程师极不愿接手项目时才会这样估算。

really 真的

don’t want to do as an engineer! 不想接手的项目!

So, looking at it from this point of view: does it matter if the estimate was 1.5 years (Airbnb) or half a decade (Asana, hypothetically)? Or if the estimated cost was 5M? It would still be 因此关键在于:预估1.5年(Airbnb)或五年(假设的Asana)有区别吗?100万还是500万美元有区别吗?最终结论都是…(下文截断)