redline
HighTests and CItest-branch-in-prod

Test-only branch in shipped code

Test-only branch in shipped code. Shipped code behaves differently under test (NODE_ENV === 'test'). The tests no longer check what runs in production.

This is how the comment reads inline, under the flagged line.

Why it matters

Branches on 'am I in a test?' mean the tests exercise a path production never takes.

What to do

Inject the dependency that differs (clock, client, store) and keep one code path.

Examples

Flagged
if (process.env.NODE_ENV === 'test') return fakeUser;
Better
const user = await users.get(id); // tests pass an in-memory store

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: Shipped code only. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

if (process.env.NODE_ENV === 'test') return 1;
src/app.py
if 'pytest' in sys.modules:
    pass

Left alone

if (process.env.NODE_ENV === 'production') {}

Research

CI steps that ignore failure (`continue-on-error`, `\|\| true`, `--no-verify`) and test-only branches in shipped code. Any check passes once you edit the check or the code path it runs.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "test-branch-in-prod"
    ],
    "severity": {
      "test-branch-in-prod": "low"
    }
  }
}

Read the source or report a false positive.