> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moltzap.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# protocol/testing/toxics

> Public barrel for Toxiproxy toxic profiles and control helpers.

# protocol/testing/toxics

*`packages/protocol/src/testing/toxics`*

## Purpose

Public barrel for Toxiproxy toxic profiles and control helpers.

## Public surface

### [`allToxicTags`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/profile.ts#L51)

*Variable*

```ts theme={null}
export const allToxicTags = [
  "latency",
  "bandwidth",
  "slicer",
  "reset_peer",
  "timeout",
  "slow_close",
] as const
```

All six toxic tags, enumerated for coverage assertions in Tier D.

### [`defaultToxicProfile`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/defaults.ts#L24)

*Variable*

```ts theme={null}
export const defaultToxicProfile:
```

### [`makeToxiproxyClient`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L255)

*Function*

```ts theme={null}
export function makeToxiproxyClient(
  config: ToxiproxyConfig,
): Effect.Effect<ToxiproxyClient, ToxicControlError>
```

### [`ToxicControlError`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/errors.ts#L8)

*Class*

```ts theme={null}
export class ToxicControlError extends Data.TaggedError(
  "TestingToxicControlError",
)<{
  readonly op: "create-proxy" | "delete-proxy" | "add-toxic" | "remove-toxic";
  readonly status: number;
  readonly body: string;
}> {}
```

Toxiproxy HTTP API returned a non-2xx, or the control endpoint is down.

### [`ToxicHandle`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L60)

*Interface*

```ts theme={null}
export interface ToxicHandle {
  readonly name: string;
  readonly profile: ToxicProfile;
}
```

A live toxic attachment. Scoped: acquiring adds the toxic to the proxy,
releasing the scope removes it. Tier D properties acquire a
`ToxicHandle` inside `Effect.scoped` so a crashed property still cleans
up.

### [`ToxicProfile`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/profile.ts#L14)

*TypeAlias*

```ts theme={null}
export type ToxicProfile =
  | {
      readonly _tag: "latency";
      /** Added latency in milliseconds, per-packet. */
      readonly latencyMs: number;
      /** Random jitter in ms, uniform [0, jitterMs). */
      readonly jitterMs: number;
    }
```

Toxic profile DSL.

Per D2 and Invariant I4, adversity is a parameter selected at suite
invocation, not hardcoded case-by-case. A `ToxicProfile` is a named
preset (one of the six toxics) plus its parameters; the Tier D runner
picks the matching Tier C invariant and re-runs it with the toxic
attached.

Exhaustiveness: the `_tag` union covers every toxic named in §5 Tier D
(D1–D6) so the implementer cannot forget a branch in the client dispatch.

### [`ToxicTag`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/profile.ts#L60)

*TypeAlias*

```ts theme={null}
export type ToxicTag = (typeof allToxicTags)[number];
```

### [`ToxiproxyClient`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L81)

*Interface*

```ts theme={null}
export interface ToxiproxyClient {
  /** Create a scoped proxy; teardown on release. */
  readonly proxy: (opts: {
    readonly name: string;
    readonly upstream: string;
  }) => Effect.Effect<ToxiproxyProxy, ToxicControlError, Scope.Scope>;
  /** Probe: control plane reachable. */
  readonly ping: Effect.Effect<void, ToxicControlError>;
}
```

### [`ToxiproxyConfig`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L25)

*Interface*

```ts theme={null}
export interface ToxiproxyConfig {
  /** Control-plane URL, e.g. `http://localhost:8474`. */
  readonly apiUrl: string;
  readonly network?: ToxiproxyNetworkConfig;
}
```

### [`ToxiproxyNetworkConfig`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L31)

*Interface*

```ts theme={null}
export interface ToxiproxyNetworkConfig {
  /** Hostname Toxiproxy should use when dialing the real server upstream. */
  readonly upstreamHost?: string;
  /** Address Toxiproxy should bind inside its own process/container. */
  readonly listenHost?: string;
  /** Hostname conformance clients should use when dialing a Toxiproxy listener. */
  readonly connectHost?: string;
  /** Fixed listener port range for Docker bridge mode. Omit for `:0`. */
  readonly listenPortRange?: ToxiproxyListenPortRange;
}
```

### [`ToxiproxyProxy`](https://github.com/chughtapan/moltzap/blob/main/packages/protocol/src/testing/toxics/client.ts#L70)

*Interface*

```ts theme={null}
export interface ToxiproxyProxy {
  /** Upstream (real server) address the proxy forwards to. */
  readonly upstream: string;
  /** Client-facing URL (`ws://127.0.0.1:&lt;ephemeralPort>`). */
  readonly listenUrl: string;
  /** Attach a toxic inside a Scope; removed on release. */
  readonly withToxic: (
    profile: ToxicProfile,
  ) => Effect.Effect<ToxicHandle, ToxicControlError, Scope.Scope>;
}
```

A live proxy that sits between TestClient and the real server (or
between real client and TestServer). Acquiring the scope allocates an
ephemeral port and registers the proxy; releasing deletes it.

## Files

* `client.ts`
* `defaults.ts`
* `errors.ts`
* `profile.ts`
