I recently came across an issue in the test suite of our Node.js component. Like many long-standing projects, this suite was developed over many years by different people. This naturally led to a certain "rustiness" in the code.
The specific issues were classic signs of technical debt:
- Hard-coded values that were no longer relevant or correct.
- Missing metadata that broke our testing strategy for newer Node.js versions.
- Inconsistent structure across tests written by different generations of developers.
The fix was conceptually simple: rewrite a few lines, replace hard-coded paths with environment variables, and add a standard metadata file. It was a job that would take 15 minutes at most per test.
The catch? Our test suite had more than 100 such tests in our test suite.
100 tests times 15 minutes equals 1,500 minutes (25 hours). That's three full working days of mind-numbing, repetitive value rewriting. I needed a better way.
The solution: AI as a pattern matcher
Before I found this problem, I was playing around with Claude AI. I noticed that while Claude isn't the best at creating code from scratch, it is quite good at rewriting it, especially if given an example to mimic.
I think this is one of the best use cases for AI. It doesn't need to be creative or understand the problem as a whole; it just needs to apply changes made to one file dynamically across the test suite.
How to set up Claude for large-scale refactoring
While you can use the web interface, manually syncing more than 100 files is inefficient and a version control nightmare. To handle a task of this scale, it's better to use tools that can interact with your local file system directly.
The Claude command-line interface (CLI) is the official tool from Anthropic. Unlike the web interface, it can read your file structure, run terminal commands, and—crucially—edit files directly.
Installation
The installation is straightforward and requires no additional dependencies. As described in the official docs, the installation is very simple and requires no additional dependencies. Use the bash or Zsh shell to run the following command and install claude:
curl -fsSL https://claude.ai/install.sh | bashAuthentication
Once installed, run the following command to initialize the tool:
claudeOptional: Authenticate for Google Vertex AI
If you access Claude through Google Vertex AI, you must install the gcloud CLI to handle authentication. For detailed instructions, refer to the Google Cloud SDK documentation.
Now that Claude has access to local files, we can get back to solving our problem.
Step 1: Create the pattern
First, I manually fixed one test file to establish the pattern.
Remove hard-coded paths
I replaced the rigid binary paths with environment variables. This ensures the tests can run with different versions, such as Node.js 22 or Node.js 24.
Before (hard-coded):
# Before (Hardcoded)
NODE_BIN="/usr/bin/node"After (flexible):
NODE_BIN=${NODE_BIN:-/usr/bin/node}
NPM_BIN=${NPM_BIN:-/usr/bin/npm}
NPX_BIN=${NPX_BIN:-/usr/bin/npx}
NODEJS_MAIN_PACKAGE=${NODEJS_MAIN_PACKAGE:-nodejs}Add FMF metadata
Our testing strategy uses .fmf metadata files to call tests with environment variables. These values set the local variables defined in the previous step, allowing you to use the same test code for different binaries.
The following example shows the metadata structure and the added values:
summary: Verify usage of pqc in nodejs
tag:
- TestCaseCopy
- Tier1
tier: '1'
component:
- nodejs:24
environment:
MODSTREAMS: nodejs:24
extra-summary: /CoreOS/nodejs/Sanity/pqc [nodejs:24]Step 2: Craft the prompt
Instruct Claude to look at the existing change, highlight the important parts, and apply them across the entire test suite. Asking the tool to explain the changes as a verification is also a good idea to ensure accuracy before proceeding. See Figure 1.

Claude then resolves the issue by scanning the project files, as shown in Figure 2.

It will provide the requested explanation for verification (Figure 3).

Claude then automatically applies the same changes to other files across the project (Figure 4) and displays each code change.

Claude asks for confirmation for each file (Figure 5). You can skip this step if it is no longer necessary.

The result
Claude applied the pattern across the suite in approximately 15 minutes. I manually accepted each change to ensure accuracy.
Instead of spending three days on copy-paste drudgery, the new process took less than an hour:
- 15 minutes fixing the first test.
- 20 minutes crafting the prompt and reviewing Claude's output.
- 20 minutes verifying the test run.
Refactoring legacy test suites is rarely difficult, but it is almost always boring and tedious. By using Claude as a pattern matcher rather than a generator, you can complete these tasks more efficiently and safely.
Next steps
Ready to explore how intelligent tools can enhance your development workflow?
- Check out our collection of learning paths for Red Hat OpenShift AI to start building and deploying your own AI-powered applications.
- Browse the AI quickstarts catalog for production-ready use cases, including fraud detection, document processing, and customer service automation.
- Discover more ways to integrate AI into your workflow by exploring our curated resources for AI in development.