# `Juggernaut.Sandbox`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/sandbox.ex#L1)

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.

# `deps_dir`

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

The dependency mirror of `sandbox`: `<sandbox>_deps`.

# `dir`

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

The sandbox directory of the project at `root`.

# `dirs`

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

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

# `ensure_build_format`

```elixir
@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`

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

The root files always mirrored.

# `sync`

```elixir
@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`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
