Skip to main content

Set Up TestPilot AI

Why This Matters

Every lesson from here on works in the TestPilot AI repository. A green npm run check now means that, later on, a failure is about your change and not about your setup.

Clone and install

You need Node.js 22.18 or newer (check with node -v).

git clone git@github.com:learn-automated-testing/testpilot-ai.git
cd testpilot-ai
npm install
npm run check

npm run check runs the TypeScript compiler and the tests. It should end with all tests passing, without an API key.

npm run check in the terminal: typecheck, then 13 tests in 3 files passing in about 100 ms

The whole check takes a fraction of a second. That is on purpose: the tests use a fake client that returns prepared answers. They are fast, free and give the same result every time. Testing your code without calling the model is a design choice you will defend more than once in the exam.

Create an API key

To talk to Claude for real you need a key from the Claude Console.

When you click Create key, the Console first asks where your code runs. For your own machine, cloud workloads and CI pipelines there are options that need no stored key at all, which is safer. For TestPilot’s .env you choose Somewhere else.

The Claude Console asks where your code runs: your own machine (sign in with the ant CLI), cloud or Kubernetes, a CI pipeline without stored secrets, or somewhere else with an API key

Give the key a name that says what it is for, and keep the expiry short. A key called testpilot-ai that expires in 30 days is easy to recognise and does little harm if it leaks.

The Create API key form with the name testpilot-ai, a 30-day expiry and the default workspace as scope

The key is shown once. Copy it straight into your .env file, never into a chat, a ticket, a commit or a screenshot.

The Save your API key dialog, with the key hidden in this screenshot

cp .env.example .env
# open .env and paste your key after ANTHROPIC_API_KEY=

.env is listed in .gitignore, so it never ends up in git. Check that with git status: .env must not appear.

The keys page shows all your keys, who created them and when they expire. Disable keys you no longer use.

The API keys overview in the Claude Console, with key values hidden

A five-minute tour

PathWhat it is
src/types.tsThe format of a test run export
src/runs.tsLoading runs and plain helpers such as failureRate()
src/prompt.tsThe system prompt and the message builder
src/schema.tsThe shape of a triage verdict
src/triage.tsThe one function that calls Claude
fixtures/runs/run-1042.jsonA test run with five failures, one of each kind
tests/Tests with a fake client
docs/exercises.mdThe exercises per lesson
AGENTS.md, CLAUDE.mdInstructions for coding agents (module 6)

Open fixtures/runs/run-1042.json now and read the five failures. You will meet them in every module.

Solution branches

When a lesson has a worked solution, it is on a branch. Compare your work with ours:

git fetch
git diff main...solution/lesson-09-structured-output   # three dots: only the lesson's changes

Check

  • npm run check is green
  • .env contains your key and does not show up in git status
  • you can name the five failures in run-1042.json