mix juggernaut (Juggernaut v0.4.0)

Copy Markdown View Source

Runs mutation testing and gates on the result.

mix juggernaut [--changed | --since REF | --full | --files PATH...] [options]

With no scope flag, mutates every function in the files changed against base (.juggernaut.exs, default main; JUGGERNAUT_BASE overrides). Files may also be given as positional arguments.

Examples

mix juggernaut                                  # gate lane, files changed vs base
mix juggernaut --lane inner --format agent      # advisory, changed functions, agent JSON
mix juggernaut --files lib/my_app/policy.ex   # these files, whole
mix juggernaut --lane release --full --output cover/mutation.txt
mix juggernaut --dry-run --full                 # mutant inventory only

Output: human (live progress on stderr, survivors as they are found, then the summary), agent (one compact JSON document), json (the mutation-testing-elements report), markdown (for pull requests) and github (Actions annotations). --stream writes NDJSON events instead, ending with the agent document when --format agent. Machine formats write only their document to stdout.

When mix juggernaut.server is running for this checkout the run is sent to it and uses its warm pool (unless --no-server); the output and exit code are the same. --watch starts the server if none is running and runs the inner lane on every saved change under paths, test_paths and config/ until interrupted.

Options

  • --changed - Every function in files changed vs the merge base of base and HEAD (the default).
  • --since REF - Only function clauses changed since REF.
  • --full - Every file under paths.
  • --files PATH - These files (globs allowed), whole. Repeatable.
  • --lane inner|gate|release - Preset of scope, operators, cache and control. Default: gate.
  • --format human|agent|json|markdown|github - Output format. Default: human. Or set JUGGERNAUT_FORMAT.
  • --stream - NDJSON events on stdout as they happen; with --format agent the last line is the report.
  • --fail-fast - Stop at the first mutant that fails a threshold (inner: on).
  • --max-mutants N - Run at most N mutants; the rest are pending.
  • --budget DURATION - Stop dispatching after this long (90s, 5m, 1h).
  • --workers N - Pool size for this run.
  • --no-cache - Do not read or write the result cache.
  • --dry-run - List the planned mutants only; run nothing.
  • --seed N - ExUnit seed for every job (random and recorded if absent).
  • --page N - Page of survivors to show. Default: 1.
  • --per-page N - Survivors per page. Default: 20.
  • --output PATH - Also write the document to PATH.
  • --strict-ignores - Ignore-comment warnings become exit 2.
  • --watch - Start or attach to the server and run the inner lane on every saved change.
  • --no-server - Never attach to a running server (--no-server).
  • --force-unlock - Remove the checkout lock first, whoever holds it: for a run whose container was removed before its lock went stale.

Exit codes

  • 0 - the gate passed
  • 1 - the gate failed or is incomplete (survivors over a threshold, mutants left unrun)
  • 2 - usage or configuration error; nothing was scored
  • 3 - infrastructure or harness error; never a verdict

Summary

Functions

Whether this run goes to a running server: not with --no-server, --dry-run (it runs nothing) or inside the server itself (its jobs carry the pool).

:ok, or the usage error for --stream with a format other than human or agent: the stream is the document then, and only the agent document can end it.

The scope asked for: %{kind: :changed | :since | :full | :files, ref: ref | nil, files: [path]}. Positional files join --files and cannot be combined with another scope flag. The :changed ref is filled from the config's base later.

The run each change sends: argv without --watch, in the inner lane unless one is named.

The config a watch runs on: .juggernaut.exs loaded and its refuse_env checked, so a bad config is a usage error (exit 2) before any server is started.

Watches the checkout and sends an inner-lane run of what changed to the server after every settled change (Juggernaut.Watch), until interrupted. argv is the watching command line: its other flags are kept, --watch is dropped and --lane inner added unless a lane is given. config gives the watched directories (watch_config/1). ctx.watch_opts passes Juggernaut.Watch.loop/3 options (tests).

Writes one piece of a run's output: stdout through the Mix shell; stderr line by line to ctx.progress when given, else to stderr as it is (the live progress line redraws).

Writes the --output document (rendered by render only when there is a path), or returns the infrastructure error (exit 3) naming the path it could not write.

Functions

attach?(opts, ctx)

@spec attach?(keyword(), map()) :: boolean()

Whether this run goes to a running server: not with --no-server, --dry-run (it runs nothing) or inside the server itself (its jobs carry the pool).

check_stream(format, arg2)

@spec check_stream(atom(), boolean() | nil) :: :ok | {:error, Juggernaut.Error.t()}

:ok, or the usage error for --stream with a format other than human or agent: the stream is the document then, and only the agent document can end it.

scope(opts, args)

@spec scope(keyword(), [String.t()]) ::
  {:ok, Juggernaut.Run.scope()} | {:error, Juggernaut.Error.t()}

The scope asked for: %{kind: :changed | :since | :full | :files, ref: ref | nil, files: [path]}. Positional files join --files and cannot be combined with another scope flag. The :changed ref is filled from the config's base later.

watch_argv(argv)

@spec watch_argv([String.t()]) :: [String.t()]

The run each change sends: argv without --watch, in the inner lane unless one is named.

watch_config(ctx)

@spec watch_config(map()) ::
  {:ok, Juggernaut.Config.t()} | {:error, Juggernaut.Error.t()}

The config a watch runs on: .juggernaut.exs loaded and its refuse_env checked, so a bad config is a usage error (exit 2) before any server is started.

watch_loop(argv, ctx, config)

@spec watch_loop([String.t()], map(), Juggernaut.Config.t()) :: :ok

Watches the checkout and sends an inner-lane run of what changed to the server after every settled change (Juggernaut.Watch), until interrupted. argv is the watching command line: its other flags are kept, --watch is dropped and --lane inner added unless a lane is given. config gives the watched directories (watch_config/1). ctx.watch_opts passes Juggernaut.Watch.loop/3 options (tests).

write(ctx, arg)

@spec write(map(), {:stdout | :stderr, iodata()}) :: :ok

Writes one piece of a run's output: stdout through the Mix shell; stderr line by line to ctx.progress when given, else to stderr as it is (the live progress line redraws).

write_output(path, render)

@spec write_output(Path.t() | nil, (-> iodata())) ::
  :ok | {:error, Juggernaut.Error.t()}

Writes the --output document (rendered by render only when there is a path), or returns the infrastructure error (exit 3) naming the path it could not write.