Juggernaut.Sandbox (Juggernaut v0.4.0)

Copy Markdown View Source

The persistent mirror of the project that mutants are compiled and run in (design notes §10.2): _build/juggernaut/sandbox/, a Mix project of its own with its own _build/test, at a stable path so Mix stays incremental.

It mirrors what the project holds (Juggernaut.Sandbox.Sync): every file git lists for it (tracked, and untracked but not ignored), so files the application reads at run time come along (a top-level data directory, say), plus everything under lib, test, config, priv and the configured paths, ignored files included, and mix.exs, mix.lock and .formatter.exs. Outside a repository only the latter are mirrored; in a repository root that git cannot read (a worktree whose gitdir is not mounted) the sync is an infrastructure error naming git, never a partial mirror. Dependencies are mirrored too, into deps_dir/1 next to the sandbox (sync_deps/2), and the compile reads them from there through MIX_DEPS_PATH: compiling a dependency can write into its own directory (phoenix copies templates into priv/), so the project's deps/ is only ever read and may be read-only or shared. Mutants never touch the working tree.

Summary

Functions

The dependency mirror of sandbox: <sandbox>_deps.

The sandbox directory of the project at root.

The directories mirrored whole for a project whose configured source paths are given.

Makes the sandbox's _build one of the current format: a build without _build/juggernaut.build naming it was made by an older Juggernaut, so _build is removed and the next compile builds the dependencies and the project again. Mix would not do it alone: a module that reads the config while it compiles is not recompiled when only the config it was compiled without changes.

The root files always mirrored.

Syncs the project at root into its sandbox. Options: :sandbox (default dir/1), :paths (configured source paths, mirrored too), :overrides (metamutant sources by relative path) and :git (a Juggernaut.Plan.Git runner, for tests). Unknown options raise.

Mirrors the project's dependencies (deps, a deps/ directory) into deps_dir(sandbox), incrementally, as Juggernaut.Sandbox.Sync does. Everything a dependency holds is mirrored (.git, .hex, priv) except _build directories, and files a dependency writes into its own directory while it compiles are left in place.

Functions

deps_dir(sandbox)

@spec deps_dir(Path.t()) :: Path.t()

The dependency mirror of sandbox: <sandbox>_deps.

dir(root)

@spec dir(Path.t()) :: Path.t()

The sandbox directory of the project at root.

dirs(paths \\ [])

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

The directories mirrored whole for a project whose configured source paths are given.

ensure_build_format(sandbox)

@spec ensure_build_format(Path.t()) :: :ok | :rebuilt

Makes the sandbox's _build one of the current format: a build without _build/juggernaut.build naming it was made by an older Juggernaut, so _build is removed and the next compile builds the dependencies and the project again. Mix would not do it alone: a module that reads the config while it compiles is not recompiled when only the config it was compiled without changes.

files()

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

The root files always mirrored.

sync(root, opts \\ [])

@spec sync(Path.t(), keyword()) ::
  {:ok, Juggernaut.Sandbox.Sync.report()} | {:error, Juggernaut.Error.t()}

Syncs the project at root into its sandbox. Options: :sandbox (default dir/1), :paths (configured source paths, mirrored too), :overrides (metamutant sources by relative path) and :git (a Juggernaut.Plan.Git runner, for tests). Unknown options raise.

sync_deps(deps, sandbox)

@spec sync_deps(Path.t(), Path.t()) ::
  {:ok, Juggernaut.Sandbox.Sync.report()} | {:error, Juggernaut.Error.t()}

Mirrors the project's dependencies (deps, a deps/ directory) into deps_dir(sandbox), incrementally, as Juggernaut.Sandbox.Sync does. Everything a dependency holds is mirrored (.git, .hex, priv) except _build directories, and files a dependency writes into its own directory while it compiles are left in place.