Skip to main content

Interactive Onboarding with drift init

drift init is an interactive terminal UI (TUI) that takes you from zero configuration to a running contract test in a single session. It guides you through authentication, OpenAPI file selection, endpoint and parameter configuration, plugin selection, and server setup — then runs the verification and writes the resulting test file to disk.

Use drift init when you are setting up Drift for the first time on a project and want a guided path to your first passing test.

note

drift init produces one executing test case, not a complete test suite. After completing init, use your IDE or an AI agent skill to expand coverage across the rest of your API.

What you will learn

By the end of this tutorial, you will have:

  • Authenticated with PactFlow
  • Selected an OpenAPI definition and an endpoint to test
  • Run a successful contract verification
  • A saved test case file you can re-run at any time with drift verify

Prerequisites

Before you begin, you will need:

  • Drift installed — see Installation
  • A PactFlow account with Drift enabled — sign up at pactflow.io
  • Your PactFlow API token and workspace URL
  • An OpenAPI definition file in your project directory

Launch drift init

Run the following command in your project root:

drift init

The Welcome screen appears.

The drift init welcome screen, showing an amber ASCII-art drift init logo on a black terminal background. Keyboard shortcuts shown: s to Start, q to Quit.

Press enter to start the onboarding flow, or q to quit.

Step 1: Auth

Drift checks your shell environment for PactFlow credentials:

  • PACT_BROKER_BASE_URL
  • PACT_BROKER_TOKEN

If both variables are set, Drift reads them automatically and pre-populates the fields.

The Auth screen with no credentials set. Two empty fields are shown: Base URL and Token. A link to app.pactflow.io/settings/api-tokens is shown above the fields.

If the variables are not set, enter your workspace URL and API token manually. Use Tab to switch between fields.

Once credentials are entered, Drift validates them against PactFlow and confirms your plan has Drift enabled.

The Auth screen with credentials populated from environment variables. The Base URL and Token fields are filled. Below, a "Validating credentials..." message is shown alongside a drift.config snippet.

When validation succeeds, Drift shows your account name and confirms Drift is enabled on your plan. It then exchanges your credentials for a locally-cached token — subsequent runs do not require a PactFlow round-trip every time.

The Auth screen after successful validation. A green tick shows "Credentials valid" with the user's name and email. "Drift: enabled" is shown below. A drift.config snippet is displayed for optional manual config.

tip

Set your credentials as environment variables before running drift init to skip manual entry:

export PACT_BROKER_BASE_URL="https://your-workspace.pactflow.io"
export PACT_BROKER_TOKEN="your-api-token"

Press Enter to continue.

Step 2: File — Select your OpenAPI definition

Drift scans your project directory and lists all OpenAPI definition (OAD) files it finds. A preview of the selected file — title, version, paths, and endpoint count — is shown in the right panel.

The File selection screen. The left panel lists detected OpenAPI files, with "Product API" highlighted. The right panel shows a preview: Title "Product API", Version 1.0.0, paths /products and /products/id, Endpoints: 4.

Use ↑↓ to navigate the list and Enter to select a file.

Step 3: Endpoint — Pick an endpoint to test

Drift reads the selected OAD and lists every endpoint it contains, colour-coded by HTTP method. A preview of the highlighted endpoint — summary, operation ID, parameters, request body, and responses — is shown in the right panel.

The Endpoint selection screen. The left panel lists four endpoints: GET /products, POST /products (highlighted), GET /products/id, DELETE /products/id. The right panel previews POST /products: "Create a product", request body application/json, responses 201/400/401.

Use ↑↓ to navigate and / to filter the list by path or method. Press Enter to select an endpoint.

Recommendation: Start with the simplest endpoint most likely to succeed — typically a GET with no required parameters, or a POST that creates a resource without complex dependencies. The goal is to get one test passing quickly.

Step 4: Params — Fill in parameters

This step appears only when the endpoint you selected has parameters (path, query, or request body).

If the OAD includes examples for the selected endpoint, Drift pre-populates the fields with those values. Accept the defaults or edit the values directly.

The Parameter Input screen showing a pre-populated JSON request body: id, type, price, name, and version fields filled from OAD examples. Keyboard shortcuts include Load from clipboard and Copy to clipboard.

Use l to load parameter values from the clipboard, or c to copy the current values. Press Enter to continue.

note

Authentication and security schemes are not currently supported in the Params step unless they are documented as an explicit parameter in the OAD. If your endpoint requires an auth header that is not in the spec, add it manually to the generated test file after init completes.

Step 5: Plugins — Choose your plugins

Select which Drift plugins to enable for this test. Use Space to toggle a plugin on or off. A description of the highlighted plugin is shown in the right panel.

The Plugins screen. A checklist shows: http-dump v0.1.1 (selected, highlighted), oas v0.0.7 (required), junit-output v0.0.4 (selected), json v0.0.7 (selected), pact v0.0.4 (unselected), data v0.0.4 (selected). The right panel shows the http-dump description.

The oas plugin is required and cannot be deselected.

Recommendation: Keep http-dump enabled. It logs the full request and response for every test run, which makes debugging much easier if verification fails.

See Plugins for a description of each available plugin.

Step 6: Server — Set the target server URL

Drift presents a list of common server URLs and checks which ports are currently responding. Servers with an active port are marked [live] in green.

The Server screen. A URL field shows http://localhost:8080. Below it, a green "Server is responding" message. A Suggestions list shows common localhost ports; :5000 and :8080 are marked as live.

Select a server from the suggestions list, or type a custom URL directly. Use ↑↓/% to cycle through suggestions. Press Enter to confirm.

Step 7: Review — Confirm your selections and run verification

The Review screen shows all of the choices you have made. Select any item in the left panel to edit it before proceeding.

When you are ready, select Run Verification to execute the test.

After verification runs, the right panel updates with the results. If the test passes, select Continue — View next steps to proceed. If it fails, the right panel shows the failing operation, the failure detail, and an AI Assist panel with options to copy a fix prompt or a generate prompt for use with an AI coding agent.

The Review Configuration screen after a failed test run. The left panel lists: Run Verification, Edit Endpoint (POST /products), Edit Params, Edit Plugins, Edit Server URL, Continue. The right panel shows: Last Results (Some Tests Failed, 0 passed 1 failed), Operations table (createProduct FAILED), Failure Detail (status_code: expected 201 but got 401), and an AI Assist panel with options to copy fix or generate prompts.

tip

If the test fails, copy a prompt from the AI Assist panel and paste it into your AI coding agent. The fix prompt includes the failure detail and the test case file, giving the agent the context it needs to diagnose the problem.

Step 8: Next Steps — Setup complete

The drift init Next Steps screen. The breadcrumb at the top shows all steps completed: Auth, File, Endpoint, Params, Plugins, Server, Review, Verify, Next Steps. The screen shows the saved test file path, the drift verify command to re-run it, links to the docs and the Drift AI skill, and a note that AI prompt files are written on exit.

The Next Steps screen confirms what was set up. It shows:

  • The path to the saved test case file (for example, ./tests/createProduct.testcase.yaml)
  • The drift verify command to re-run the test at any time
  • Links to documentation and the Drift AI agent skill

AI prompt files

When you press q to quit, drift init writes one or two AI prompt files to your project:

FileWhen it is writtenPurpose
drift-generate-tests.prompt.mdAlwaysProvides context and instructions to help an AI agent generate further tests for the rest of your API
drift-fix-tests.prompt.mdOn test failure onlyProvides context to help an AI agent diagnose and fix the failing test

These files are designed to be opened in your IDE with an AI assistant (such as Claude Code, GitHub Copilot, or Cursor) and used as a starting prompt.

Re-run the test

The test case file saved by drift init is a standard Drift YAML file. Run it again at any time with:

drift verify --test-files ./tests/createProduct.testcase.yaml --server-url https://your-api-server.example.com

Next steps

With one passing test in place, you are ready to expand coverage: