Tia.Map (tia v0.1.0)

Copy Markdown View Source

The recorded dependency map and the rules that keep it honest.

For each test file the map stores the source files it executed and one fingerprint: the content hash of the test file and of every one of those sources. A test file is stale when it has no entry or when its fingerprint no longer matches the files on disk, so the map validates itself and needs no help from git.

A separate globals fingerprint covers what a per-test map cannot see: dependencies, configuration, migrations, test_helper.exs and any file that defines macros. When it changes, every test file is stale.

Summary

Functions

Test files whose recorded sources include any of the changed paths.

Forgets a test file, which makes it stale until it is recorded again.

The fingerprint of everything the per-test map cannot see.

An empty map stamped with the current globals.

What a local run has to execute: {:all, reason} when the globals moved, otherwise {:run, stale_test_files}.

Drops the entries of test files that no longer exist on disk.

Stores the sources a test file executed, fingerprinted against the disk.

Reads a map, or :error when it is missing, unreadable or of another version.

What CI has to execute for a diff: the stale test files plus every test file whose recorded sources include a changed path.

Test files on disk that have no entry or whose fingerprint no longer matches.

Every test file on disk.

Writes the map with one test file per line, so concurrent edits merge cleanly.

Types

selection()

@type selection() :: {:run, [String.t()]} | {:all, String.t()}

t()

@type t() :: %{required(String.t()) => term()}

Functions

affected(map, changed)

@spec affected(t(), [String.t()]) :: [String.t()]

Test files whose recorded sources include any of the changed paths.

delete(map, test_file)

@spec delete(t(), String.t()) :: t()

Forgets a test file, which makes it stale until it is recorded again.

globals(config)

@spec globals(Tia.Config.t()) :: String.t()

The fingerprint of everything the per-test map cannot see.

new(config)

@spec new(Tia.Config.t()) :: t()

An empty map stamped with the current globals.

plan(map, config)

@spec plan(t(), Tia.Config.t()) :: selection()

What a local run has to execute: {:all, reason} when the globals moved, otherwise {:run, stale_test_files}.

prune(map, config)

@spec prune(t(), Tia.Config.t()) :: t()

Drops the entries of test files that no longer exist on disk.

put(map, config, test_file, sources)

@spec put(t(), Tia.Config.t(), String.t(), [String.t()]) :: t()

Stores the sources a test file executed, fingerprinted against the disk.

read(path)

@spec read(Path.t()) :: {:ok, t()} | :error

Reads a map, or :error when it is missing, unreadable or of another version.

select(map, changed, config)

@spec select(t(), [String.t()], Tia.Config.t()) :: selection()

What CI has to execute for a diff: the stale test files plus every test file whose recorded sources include a changed path.

stale(map, config)

@spec stale(t(), Tia.Config.t()) :: [String.t()]

Test files on disk that have no entry or whose fingerprint no longer matches.

test_files(config)

@spec test_files(Tia.Config.t()) :: [String.t()]

Every test file on disk.

write(map, path)

@spec write(t(), Path.t()) :: :ok

Writes the map with one test file per line, so concurrent edits merge cleanly.