Juggernaut.MutantId (Juggernaut v0.4.0)

Copy Markdown View Source

Canonical mutant keys and short ids (design notes §6).

The key names a mutant by where it is inside its function clause and what it changes, never by line number, so an edit outside the clause keeps it:

<Module>|<fun>/<arity>|c<clause>|p<path>|<operator>:<variant>|r<rhash>
Elixir.MyApp.Approvals.Grant|check/2|c1|p2.0.1|relational:>=|r3fa9c1d2e4b5

The short id shown everywhere is <Alias>.<fun>/<arity>:<operator>:<h7>, where h7 is the first 7 hex digits of the key's SHA-256. When two mutants of a run share those digits, each of them gets one more digit until they differ.

Summary

Functions

Finds the one mutant query names among mutants (anything with :id and :key): a full short id, a canonical key, its hash part, or a unique prefix of the hash part of 4 or more characters (hash parts are hex, so anything else names nothing).

The hash part of a short id (after the last :).

The canonical key of a mutant.

The first 12 hex digits of the SHA-256 of a rendered replacement.

Short ids for entries ({key, module, function, operator}), as a map from key to id. Deterministic: the same set of keys always gets the same ids. digits (default 7) is the shortest hash part.

Types

parts()

@type parts() :: %{
  module: module(),
  function: {atom(), arity()},
  clause: non_neg_integer(),
  path: [non_neg_integer()],
  operator: atom(),
  variant: String.t() | nil,
  replacement: String.t()
}

Functions

find(mutants, query)

@spec find([%{id: String.t(), key: String.t()}], String.t()) ::
  {:ok, map()} | {:error, :unknown} | {:error, {:ambiguous, [String.t()]}}

Finds the one mutant query names among mutants (anything with :id and :key): a full short id, a canonical key, its hash part, or a unique prefix of the hash part of 4 or more characters (hash parts are hex, so anything else names nothing).

hash_part(id)

@spec hash_part(String.t()) :: String.t()

The hash part of a short id (after the last :).

key(parts)

@spec key(parts()) :: String.t()

The canonical key of a mutant.

rhash(replacement)

@spec rhash(String.t()) :: String.t()

The first 12 hex digits of the SHA-256 of a rendered replacement.

short_ids(entries, digits \\ 7)

@spec short_ids([{String.t(), module(), {atom(), arity()}, atom()}], pos_integer()) ::
  %{
    required(String.t()) => String.t()
  }

Short ids for entries ({key, module, function, operator}), as a map from key to id. Deterministic: the same set of keys always gets the same ids. digits (default 7) is the shortest hash part.