Skip to content

Deployment failed but tests pass locally

Most deploy failures with green local tests come from env differences. One class is an overloaded machine. How to tell them apart quickly.

On this page

The tests are green on your laptop. The pipeline is red, or the deploy fails at the build step. You read the code and see nothing wrong. Usually that is because nothing is wrong with the code: the two runs were not the same run.

Most of the time the difference is in the environment. Sometimes it is the other way round: the local run that failed, or the local run you trusted, happened on a machine that was busy with other work. This page covers both.

The usual causes: the environment differs

Check these first. They explain most cases of "works here, fails there":

  • Environment variables and secrets. A key or URL is set in your shell or a local .env file and missing on the build host.
  • Runtime versions. A different Node, Python or system library. Pin the version (.nvmrc, the engines field, a .tool-versions file) and print it at the start of the pipeline.
  • Dependencies. npm install on your machine may resolve other versions than npm ci with the lockfile on the build host. Commit the lockfile and use the same install command in both places.
  • Files that exist only on your machine. Ignored or untracked files, such as generated code, a local config or a build cache, make a local run pass that a fresh checkout fails. git clean -ndx lists them without deleting anything.
  • Case-sensitive paths. macOS is case-insensitive by default, most Linux build hosts are not. An import of ./Button for a file named button.js works locally and fails on Linux.
  • State left from earlier runs. A local database already seeded, a cache already warm, a server already running. The pipeline starts from nothing.
  • Resources on the build host. A smaller machine or container may run out of memory (exit 137) or time where your laptop did not.

How to diagnose it without any extra tool

  1. Reproduce from a fresh checkout. Clone the repository into a new folder, install with the same command the pipeline uses, and run the same test command:
    Shell
    git clone <your repo> fresh-checkcd fresh-checknpm cinpm test
    If it fails here, the difference was on your machine all along.
  2. Compare versions. Print node --version, npm --version and any tool the build uses, in both places.
  3. Diff the environment. List the variable names (not values) your app reads and check each exists on the host.
  4. Run inside the same image. If the pipeline uses a container image, run the tests in that image locally.
  5. Read the first error, not the last. Pipelines often fail many steps after the real cause.

The other class: a busy machine

There is one more case, and it runs the other way. When several coding agents share one computer, a local run can fail because three test suites and a build ran at the same moment. The agent then reports red, and someone goes looking for a code problem that is not there. Or a "green" local result came from a quiet moment, and a later local check under load fails with timeouts.

You can spot this class by the error: timeouts, Killed, JavaScript heap out of memory, ENOSPC (disk full) or EMFILE (too many open files). Those are signs about the machine, not your logic.

How dotime-queue helps

dotime-queue runs heavy commands on one computer through a waiting line. Use it to make your local check equal to your deploy check, and to keep the machine from muddying the result.

  1. Run the same command the pipeline runs, through the queue.
    Shell
    dotime-queue run --label "web-app: tests" -- npm test > test.log 2>&1
    It waits for a free slot and for the machine to have memory, disk and CPU to spare, so the result is about the code.
  2. Read the reason before you touch code. With the output in a file, each failed run gets a class: memory, disk, files, port, network, test, build, run-limit and others. dotime-queue reasons counts them for the last 7 days. A terminal or pipe is never read; those failures are unknown.
  3. Check which commit passed. dotime-queue passed --match "tests" prints a stamp: line when a matching check passed on exactly this clean commit, and exits 1 when none did.
  4. Ship from the same checks. dotime-queue release runs the checks listed in dotime.release.json on one commit, then a security check and the build, and only then your deploy command. See deploy only after the tests pass.

What it does not do

  • It does not find or fix environment differences. Missing variables, other versions and case-sensitive paths are yours to fix.
  • It does not run your CI pipeline or its workflow files, and it does not change your build host.
  • It does not host apps or deploy to a cloud. A release runs the deploy command you write.
  • It does not fix failing tests. It records why runs failed, so the real failures stand out.