# `MutagenEx.Test.CodeServerFacade`
[🔗](https://github.com/iautom8things/mutagen_ex/blob/v0.2.0/lib/mutagen_ex/test/code_server_facade.ex#L1)

Behaviour for the `:code` module seam used by `MutagenEx.BeamCache`.

Per [`mutagen.decision.code_server_facade`](https://github.com/iautom8things/mutagen_ex/blob/main/.spec/decisions/code_server_facade.md),
`MutagenEx.MutationRunner`'s restore path now performs a binary swap via
`:code.load_binary/3` from a snapshot taken via `:code.get_object_code/1`.
Both functions mutate global BEAM state (the loaded-module table and the
on-disk path resolution), so direct tests would either need to tolerate
state leakage between cases or restore by hand after every assertion.

The facade isolates those two calls behind a behaviour. Production code
uses `MutagenEx.Test.CodeServer`, which delegates straight to the `:code`
module. Tests inject a stub that records calls and returns canned
responses without touching the live module table.

## Pattern parity

This facade mirrors `MutagenEx.Test.CompilerFacade` exactly:

  * One module per real-OTP boundary.
  * `cfg.code_server` selects the implementation (defaults to
    `MutagenEx.Test.CodeServer`), the same shape as `cfg.compiler`.
  * Test stubs declare `@behaviour MutagenEx.Test.CodeServerFacade` to
    get compile-time wiring checks.

# `get_object_code_result`

```elixir
@type get_object_code_result() :: {module(), binary(), charlist()} | :error
```

Result of `:code.get_object_code/1`.

# `load_binary_result`

```elixir
@type load_binary_result() :: {:module, module()} | {:error, term()}
```

Result of `:code.load_binary/3`.

# `get_object_code`

```elixir
@callback get_object_code(module()) :: get_object_code_result()
```

Read the currently-loaded `.beam` for `module`. Mirrors
`:code.get_object_code/1`.

Returns `{module, binary, filename}` for a loaded module, or `:error`
when the code server cannot resolve the module (not loaded, no `.beam`
on disk, etc.).

# `load_binary`

```elixir
@callback load_binary(module(), filename :: charlist(), binary()) :: load_binary_result()
```

Load `binary` as the bytecode for `module`, recording `filename` as
its on-disk origin. Mirrors `:code.load_binary/3`.

Used by `MutagenEx.BeamCache.restore/3` to put the snapshot binary
back after a per-site mutation cycle. Returns `{:module, module}` on
success.

---

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