# `WardrikTesting.Server`

A `Wardrik.Server` that answers from a script, for testing packages without Wardrik.

    setup do
      :ok = WardrikTesting.Server.start(:my_test, secrets: ["wrk_good"])
      %{scope: Wardrik.Scope.new(WardrikTesting.Server, :my_test, "acme/@maria")}
    end

## Messages

The calling test is sent:

  * `{:ran, id, input}` for each operation.
  * `{:streamed, id, input}` for each stream.
  * `{:asked, conversation, text, principal_id}` for each message.
  * `{:offered, worker, tools}` for each worker's tools.

## Answers

  * An operation returns the protocol's example output, or `nil` if it has none.
  * `acme/missing`, and any conversation under it, isn't found.
  * The agents given as `:offered` are listed and defined with their channels.
  * `agent.read` reports whether the conversation is waiting on a person, as its last turn left it.
  * A message is answered as `WardrikTesting.Script` describes. The events are written to the
    conversation's log if the test started `events/1`.
  * A stream with `"after" => "nope"` fails with `:invalid_request`.
  * Following `acme/broken` fails partway. Following `acme/waiting` waits on `call_1`. Following
    any other agent replies `"Re: "` followed by the input.

# `add_agent`

```elixir
@spec add_agent(atom(), String.t(), [String.t()], String.t() | nil) :: :ok
```

Adds the agent `id` to those offered, answering in `channels`.

# `events`

```elixir
@spec events(atom()) :: atom()
```

Returns the name to start `WardrikEvents` under, so turns are written to it.

# `offer_agents`

```elixir
@spec offer_agents(atom(), [{String.t(), [String.t()]}]) :: :ok
```

Replaces the agents offered with `offered`, each as `{id, channels}`.

# `revoke`

```elixir
@spec revoke(atom(), String.t()) :: :ok
```

Revokes `secret`, so it no longer authenticates.

# `start`

```elixir
@spec start(atom(), keyword()) :: :ok
```

Starts the server for the calling test under `name`.

Registers the test process as `name`, and stops the server when the test ends.

## Options

  * `:secrets` - API tokens it accepts. Each acts for `acme/@maria` as an owner. `[]` unless set.
  * `:offered` - agents it offers, each as `{id, channels}` or `{id, channels, description}`.
    `[]` unless set.

---

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