惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
宝玉的分享
宝玉的分享
美团技术团队
量子位
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
爱范儿
爱范儿
J
Java Code Geeks
博客园 - Franky
Last Week in AI
Last Week in AI
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
GbyAI
GbyAI
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog

Hacker News - Newest: "AI"

AI can't read an investor deck AI as an attorney? Student uses ChatGPT, Gemini to sue UW over alleged racial discrimination Hacking MCP Servers in AI Systems – The Rug Pull: Tool Changes After Approval GitHub - MeepCastana/KubeezCut: Free Web based video editor Can AI judge journalism? A Thiel-backed startup says yes, even if it risks chilling whistleblowers Coming soon: 10 Things That Matter in AI Right Now DARPA built an AI to fact-check enemy weapons claims What explains heterogeneity in AI adoption? When AI Meets Muscle: Context-Aware Electrical Stimulation Promises a New Way to Guide Human Movements - Department of Computer Science AI Changed How We Build. It Did Not Change What Matters. Linux rules on using AI-generated code - Copilot is OK, but humans must take 'full responsibility for the… Meta spins up AI version of Mark Zuckerberg to engage with employees Code Mode: Let Your AI Write Programs, Not Just Call Tools | TanStack Blog GitHub - Delavalom/graft: Go framework for building AI agents. Type-safe tools, multi-provider (OpenAI, Anthropic, Gemini, Bedrock), zero vendor SDKs. India's TCS tops estimates, says new AI models did not dent services demand Gen Z's fading AI hype Strong feeling: we are in a folded AI reality GitHub - machinarii/total-recall-catalog: A reference catalog of latest knowledge retrieval, memory & RAG systems GitHub - mensfeld/code-on-incus: Give each AI agent its own isolated machine with root, Docker, and systemd. Active defense detects and stops threats automatically.. Quantization, LoRA, and the 8% Problem: Benchmarking Local LLMs for Production AI Iran war: We spoke to the man making Lego-style AI videos that experts say are powerful propaganda Powell, Bessent discussed Anthropic's Mythos AI cyber threat with major U.S. banks GitHub - immartian/bellamem: Persistent belief-graph memory for AI agents. Retrieves decisive context by importance — not recency, not RAG, not /compact. recursive-mode: The Repo-Native Operating System for AI Engineering After the attack on Sam Altman's home, will AI CEO's go on the offensive? The biggest advance in AI since the LLM Opus 4.6 vs GPT 5.4 One Prompt Unity World Generation Test “AI polls” are fake polls Client Challenge Can AI be a 'child of God'? Inside Anthropic's meeting with Christian leaders
Migrating 6000 React tests using AI Agents and ASTs
fagnerbrack · 2026-05-03 · via Hacker News - Newest: "AI"

The internet is flooded with very impressive vibe-style coding demos, but in my day-to-day job at Filestage we rarely start codebases from scratch and we have to deal with hundreds of thousands of lines of code and their dependencies.
I set out to explore if AI could help migrate our 970 test files with over 6000 test cases in our frontend from React Testing Library v13 to v14. How hard could it be...

Step 1: Preparing a migration guide

At first, I naively told Claude Code CLI to migrate our codebase to the new package version. It started working, updated the package to the latest version, and then ran the tests. On every test failure, it tried to debug and fix the test, but there were too many test failures, so it started to spiral out of control.

I quickly understood this was not going to work, so I decided to dig deeper. I used the web version of Claude and using the research tool I asked it to build a migration guide and best practices. I read through this guide to learn about all the changes and oh boy there were a lot of them!

The update to v14 fundamentally changed how you write tests by making all APIs asynchronous and introducing a new setup pattern. This means a lot of code changes, but the worst part is that the timing behaviors also changed, which meant that many tests will start failing, others will have less coverage, and will require manual debugging to fix.

Step 2: Splitting into small changes

This update would require thousands of changes and would require days even with AI, increasing the possibility for the team to create new tests and create conflicts.
To be able to split the change in multiple PRs I had to find a way to have both versions of the package running at the same time, luckily that is pretty easy with NPM:

{
  "devDependencies": {
    "@testing-library/user-event": "13.5.0",
    "@testing-library/user-event-new": "npm:@testing-library/user-event@14.5.2"
  }
}

So my first PR was ready, have both versions installed and the migration guide in md format in our repo.

Step 3: Automating the code changes

I decided to first focus on the easy part. I gave the migration guide to Claude Code and told it to built a codemod. I used jscodeshift which parses the code into a AST which is just nested object structure that you can manipulate, the tool takes care of then getting that new AST and generating the output code.

Sample of an AST structure in astexplorer.net
Sample of an AST structure in astexplorer.net

Great thing about jscodeshift is that you can easily write tests for your codemod and use them to verify what the AI has done. You have input and output fixtures and it will run the codemod on them and compare them with the expected output.

"use strict";

const path = require("path");
const { defineTest } = require("jscodeshift/dist/testUtils");

describe("migrate-to-userevent-v14 codemod", () => {
  for (const test of [
    "sample",
    /* ... */
  ]) {
    defineTest(
      path.resolve(__dirname, "codemods"),
      "migrate-to-userevent-v14",
      null,
      `migrate-to-userevent-v14/${test}`,
    );
  }
});
@@ -1,26 +1,33 @@
-import { render, screen } from "@testing-library/react";
-import userEvent from "@testing-library/user-event";
+import { screen } from "@testing-library/react";
+import { renderWithUserEvent } from "@shared/test/utils";

 import { Button } from "./Button";

 describe("Button", () => {
   it("should render button text", () => {
-    render(<Button>Click me</Button>);
+    renderWithUserEvent(<Button>Click me</Button>);
     expect(screen.getByText("Click me")).toBeInTheDocument();
   });

   it("should call onClick when clicked", async () => {
     const handleClick = jest.fn();
-    render(<Button onClick={handleClick}>Click me</Button>);
+
+    const {
+      userEvent
+    } = renderWithUserEvent(<Button onClick={handleClick}>Click me</Button>);

     await userEvent.click(screen.getByText("Click me"));
     expect(handleClick).toHaveBeenCalled();
   });

   it("should type text into input", async () => {
-    render(<input placeholder="Enter text" />);
+    const {
+      userEvent
+    } = renderWithUserEvent(<input placeholder="Enter text" />);
+
+    await userEvent.click(screen.getByPlaceholderText("Enter text"));

-    await userEvent.type(screen.getByPlaceholderText("Enter text"), "Hello");
+    await userEvent.keyboard("Hello");
     expect(screen.getByPlaceholderText("Enter text")).toHaveValue("Hello");
   });
 });
Diff of the sample input and output test fixtures

The second PR was ready, the first codemod iteration and its tests.

Step 4: The actual migration

Now the fun part begins, I gave Claude Code this prompt to start migrating:

We are migrating the frontend tests to the latest version of userevent testing library v14, the migration guide frontend/doc/user-event-testing-library-migration-guide.md.
We have created a codemod to help with the migration at frontend/codemods/migrate-to-userevent-v14.js.
We have created new render utility functions that return the userEvent instance at frontend/src/shared/test/utils.js.
Until the migration is done we have both user event versions installed, v13 as "@testing-library/user-event" and v14 as "user-event-new".

I want you to continue migrating the next 10 tests (`grep -rl 'from "@testing-library/user-event"' src | head -n 10`), for each test:
*Make sure to set your working path to the frontend dir so the commands run correctly.*
- Apply the codemod to the test file
- After migrating a test we need to execute `npm run validate:fix` to verify we didn't introduce linting issues in the file, fix introduced issues if any
- Then we have to execute `npm run test -- <test-file>` to verify the test is working, fix any issues if any
- Finally verify the coverage is still 100% then we can move to the next test file, fix any coverage issues if any, eg: `npm test -- PasswordField.test.jsx --coverage --collectCoverageFrom=src/supporting/components/PasswordField/PasswordField.jsx --reporter=json` then read the coverage report at frontend/jest-coverage/coverage-final.json

Improve the migration codemod if you find any patterns repeated in the codebase that are not being covered.
Improve the migration guide if you find any patterns repeated in the codebase that are not being covered.

This wasn't the first version of the prompt I started with a very basic one and watched for the AI to fail and improved it iteratively. At the beginning there were many edge cases found, some of them could be fixed automatically by improving the codemod but others required manual intervention so the iterative learnings were consolidated in the migration guide. The migration guide started with 4532 words and ended up with 7517. Here is the resulting codemod which started with 271 lines of code and one test and ended up with 992 and 14 test cases.

Claude Code CLI agentic AI migrating tests
Claude Code CLI agentic AI migrating tests

This step was repeated 50 times until all tests were migrated, creating a PR for each.

Current AI shortcomings

I've been thoroughly impressed by the AI performance for this use case, the ability to debug and fix tests has really surprised me. I did find some shortcomings during this project.
As Steve Yegge has already talked about when the AI reaches its context limit normally during long running tasks it will really have a hard time remembering what to do next and following the original plan. For me I found that 10 tests at a time was the sweet spot.
Verifying the results is critical, this project was a perfect example because apart from manually reviewing the code changes, we could easily run the tests and verify they worked as expected with 100% coverage and make sure no original source code was modified. Having good automated tests is even more valuable than ever.
AI will tend to skip problems it can't solve easily. I noticed that it wasn't able to maintain the code coverage until I added to the prompt the instructions on how to collect the coverage in JSON format so it could understand the coverage problem and have enough context to make the necessary fixes.
AI providers are having trouble keeping up with the demand. During this migration I had multiple outages.

Claude Code status page with multiple outages
Claude Code status page with multiple outages

Although I was tempted to automate even further this migration by creating a script to loop over each migration stage and create the PR automatically, I decided against it because when faced with an edge case, the solution from the AI wasn't always the best. Sometimes it relied on hacks, for example using fireEvent instead of deeply understanding the real root causes under the hood with userEvent. So right now I prefer to be vigilant instead of making a fool of myself in front of the whole team.

Conclusion

It took me one week to do this migration. It consisted of 50 PRs and each one took around half an hour. There were many tricky situations which the agent figured out that would've taken me hours to debug myself, and the changes involved, although mostly mechanical and repetitive, would've taken months to complete. The worst part of this kind of work is how energy-draining it is because there is little creativity involved. I'm truly amazed, and this is not a Claude ad, I'm a big fan of OpenAI Codex CLI or Google Gemini CLI too. Paying for more usage and better models has been totally worth it, check the leaderboard to see if you are missing out on better performance.

Traditional strong software development fundamentals still apply: work on small changes iteratively, make sure you have good automated validation to give you confidence to push those changes, and make sure you have a good understanding of what is going on under the hood when the time comes to debug because I'm sure it will.

I'm truly excited because mundane maintenance tasks are very common in long-running projects and it seems we are getting close to forgetting about them and having them truly automated. Giving software developers more time to actually work on solving real customer problems with software, what an amazing revolution we are living.

Let's build something solid.

Stop firefighting. Start shipping with confidence. Let's talk about what predictable delivery looks like for your team.