# `Chronicle.Testing.InMemoryKernel`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/testing/in_memory_kernel.ex#L4)

An in-memory fake Chronicle kernel: a `GenServer` holding an event log plus a
`%GRPC.Channel{}` interceptor answering the subset of the Chronicle wire protocol
the client needs to append, read, and register artifacts.

This is the seam `Chronicle.Testing.start_supervised_client/1` uses to run a real
`Chronicle.Client` against no real kernel: the client's own append, constraint,
and unit-of-work code runs completely unchanged, talking to this process instead
of a socket.

Supported RPCs: the compatibility check, `Append`/`AppendManyForEventSources`,
reads (`ForEventSourceIdAndEventTypes`/`FromSequenceNumber`), `TailSequenceNumber`,
`HasEventsForEventSourceId`, and the registration calls for event types, event
sources, constraints, read models and projections (acknowledged, not modeled —
constraint definitions are supplied directly at `start_link/1`, not parsed off the
wire; see the moduledoc on `Chronicle.Testing`). Every other RPC returns
`{:error, {:not_supported_in_memory, rpc}}` — most prominently
`closes_stream` constraints and the actual `ReadModels`/`Projections` query
surface, which is why `Chronicle.Testing.read_model/3` reads reducer state kept by
`Chronicle.Testing.Dispatcher` instead of querying a kernel sink that does not exist.

Concurrency scopes are honored along every dimension (`:event_source_id`,
`:event_stream_type`, `:event_stream_id`, `:event_source_type`, `:event_types`,
including `ExpectsNoMatchingEvent`). Constraints support `:unique` (ignoring
casing, scoped, respecting removal) and `:unique_event_type`.

# `all_wire_events`

```elixir
@spec all_wire_events(GenServer.server()) :: [map()]
```

Returns every committed wire event, across every event source and sequence, in
append order. Used by `Chronicle.Testing.Assertions`.

# `channel`

```elixir
@spec channel(GenServer.server()) :: GRPC.Channel.t()
```

Returns a `%GRPC.Channel{}` whose interceptor answers RPCs against this kernel.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts an in-memory kernel.

## Options

  * `:event_store` — default `"test"`
  * `:namespace` — default `"Default"`
  * `:event_types` — event type modules this kernel can decode (used for
    `Chronicle.Testing.appended_events/2` and assertions)
  * `:constraints` — resolved constraint definition maps, in the shape
    `Chronicle.Events.Constraints.from_event_types/1` /
    `from_constraint_modules/1` produce
  * `:name` — registered process name (optional)

# `subscribe`

```elixir
@spec subscribe(GenServer.server(), pid()) :: :ok
```

Subscribes `pid` to every committed append batch:
`{:chronicle_testing_appended, event_store, namespace, event_sequence_id, [wire_event, ...]}`.

# `wire_events_for`

```elixir
@spec wire_events_for(GenServer.server(), String.t()) :: [map()]
```

Returns every committed wire event for `event_source_id`, across every event
sequence, in append order.

---

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