Skip to content

Skip tests that already passed on this commit

Re-running a test suite that already passed on the same commit wastes minutes. Stamp each pass by commit and skip only when nothing changed.

On this page

The suite passed ten minutes ago. Nothing has been committed since. Now a reviewer agent runs it again, then the agent that wrote the change runs it once more before it reports, and a script runs it a third time before release. Same code, same result, three times the wait, and three times the load on the machine.

Skipping a repeat run is easy. Skipping it safely is the hard part: a skip must never hide a change.

Where duplicate runs come from

  • Several agents on one change. One agent builds, another reviews, a third checks. Each one runs the suite to be sure, because none of them sees the others' results.
  • Habit and retries. An agent re-runs the suite at the end of every step, even when the step changed nothing.
  • Pipelines. A push and a pull request on the same commit can each start the same workflow.

What CI tools already offer

On a CI service, look at what it has before building your own:

  • GitHub Actions has third-party actions such as skip-duplicate-actions that skip jobs when a run on the same file content (the same tree hash) already succeeded.
  • Build systems with task caching, such as Nx, Turborepo and Bazel, hash a task's inputs and reuse the result when the inputs match.
  • Many teams key a cache on git rev-parse HEAD or on the tree hash, and skip a step when a marker for that key exists.

These are good fits for CI. On one developer machine shared by several agents, there is often no such cache, and the runs come from different shells that do not know about each other.

The rules that make a skip safe

Whatever tool you use, a skip should hold only when all of these are true:

  1. The tree is clean. No uncommitted or untracked changes. git status --porcelain prints nothing. A pass on a dirty tree says nothing about the commit.
  2. Same commit. git rev-parse HEAD matches the commit of the pass.
  3. Same check. Same folder, same command. A pass of a quick partial run must not stand in for the full suite.
  4. No failure since. If the same check failed on this commit after the pass, the pass no longer counts.
  5. Only checks, never builds or deploys. A build's output may be needed, and a deploy has effects. Those always run.

The rules also have a blind spot you should know: anything outside git. Installed packages, tool versions, the environment and live services are not in the commit. An end-to-end test against a deployed site can give another result on the same commit after a redeploy.

How dotime-queue does it

dotime-queue keeps a journal of every heavy command it runs on the computer. A test or lint run started through it is skipped when it already passed by the rules above:

Shell
dotime-queue run --label "web-app: tests" -- npm test

When it skips, it prints one line, takes no slot, starts nothing and exits 0:

Shell
dotime-queue: skipped: "web-app: tests" already passed on commit 0a1b2c3d (12 min ago); --no-skip runs it anyway

The exact conditions, from the manual:

  • the job's kind is test or lint (guessed from the label and command, or given with --kind), or a passed review;
  • the folder is a git checkout at a commit with no uncommitted or untracked changes;
  • a run in the same folder, with the same label and the same command, passed on this commit from a clean tree;
  • the code fingerprint matches, which also covers files the command names directly, such as a script outside git;
  • no run of the same check on this commit failed after that pass.

A job whose label or command names a build, bundle, compile, deploy, release or publish always runs, even when it also names tests. A build, deploy, debug or other job always runs.

To run a check again on purpose, for example a flaky test or an end-to-end test against a live site, add --no-skip in front of the --:

Shell
dotime-queue run --no-skip --label "web-app: e2e" -- npm run test:e2e

To ask without running anything, dotime-queue passed --match "tests" prints a stamp: line and exits 0 when a matching check passed on exactly this clean commit, and exits 1 otherwise. It looks more broadly than run does, at every run in the repository, so it can show a stamp for a check that run would still run.

dotime-queue history counts the skipped jobs per project and the run time they saved.

What it does not do

  • It is not a remote cache. Stamps live in the journal of one state folder on one computer. Another machine, or CI, does not see them.
  • It does not know about changes outside git, such as new package versions or a redeployed site. Use --no-skip after such a change.
  • It never skips builds, deploys or isolated runs, and it never skips on a dirty tree.
  • It does not decide whether your tests are good enough. A pass means the command exited 0, nothing more.